Skip to content

refactor: add per-model runtime-adapter contract + DeepSeek/GPT-OSS adapters - #257

Open
Andrewxu313 wants to merge 2 commits into
mainfrom
refactor/per-model-runtime-adapter
Open

refactor: add per-model runtime-adapter contract + DeepSeek/GPT-OSS adapters#257
Andrewxu313 wants to merge 2 commits into
mainfrom
refactor/per-model-runtime-adapter

Conversation

@Andrewxu313

Copy link
Copy Markdown
Contributor

Description

Add batchgen/contracts/runtime_adapter.py: a frozen RuntimeState (the sole worker↔model coupling point) + ModelRuntimeAdapter ABC for per-model runtime behaviors that otherwise leak into the core as if "<model>" in model_type branches (attention-backend config, position-id computation, per-token KV byte size). Adds DeepSeek-V3 and GPT-OSS adapters reproducing the exact legacy formulas, exposed via each initializer's get_runtime_behavior_adapter(). Additive only — the generic runtime does not call them yet (the call-site swap is a follow-up). Mirrors the existing cuda_graph/adapter.py pattern.

Motivation

Foundation for de-leaking per-model behavioral branches out of batchgen_worker.py. Landing the contract + adapters first (with equivalence tests) lets the worker swap follow safely. Part of the modularization effort.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor / new infra (additive, no behavior change)

Checklist

  • I have read the CONTRIBUTION guide.
  • I have updated the tests (contract + per-model equivalence: 11 GPU-free cases).
  • I have updated the documentation (design repo: core_model_purity_audit.md, model_architecture_spec.md).

Andrewxu313 and others added 2 commits June 10, 2026 08:28
Add batchgen/contracts/runtime_adapter.py: frozen RuntimeState (sole worker<->model coupling point) + ModelRuntimeAdapter ABC for the behavioral leaks audited in core_model_purity_audit.md (attention-backend config, position-id computation, per-token KV byte size). Defaults cover the common GQA/non-MLA case; past_kv_byte_size is abstract. Additive only -- generic files do not call it yet (phase A). Mirrors the cuda_graph adapter pattern. Adds GPU-free contract test (6 cases).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Andrewxu313 <Andrewxu313@users.noreply.github.com>
Per-model ModelRuntimeAdapter implementations for the two models on the generic decode path, reproducing the exact legacy inline formulas they will replace: DeepSeek-V3 (full decode position_ids, compressed_kv_dim KV byte size, flash-attn toggle) and GPT-OSS (GQA KV byte size; base defaults otherwise). Exposed via each initializer's get_runtime_behavior_adapter(). Additive only -- decode.py/prefill.py do not call them yet. Equivalence unit tests prove adapter outputs match the original decode.py formulas.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Andrewxu313 <Andrewxu313@users.noreply.github.com>
@github-actions github-actions Bot added the ci:run Trigger build + GPU regression on H20 label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run Trigger build + GPU regression on H20

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant