Skip to content

test(contracts): align fused-bias oracles and GLM-5.3 MTP ownership - #3756

Merged
Qubitium merged 2 commits into
mainfrom
fix/test-contract-sync
Nov 10, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/test-contract-sync

Conversation

@ZX-ModelCloud

@ZX-ModelCloud ZX-ModelCloud commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Three shipped behaviours changed on main without their test contracts being
updated. This PR re-synchronises the contracts. None of the 23 failures was a
kernel regression.

Verified on a clean checkout of main at 1c5039543: all 23 reproduce there,
so nothing is already fixed upstream. No open PR covers the same files.

Failures Stale contract Shipped behaviour
20 ROCm GEMM/GEMV oracle asserts round(matmul) + bias Bias is fused into the FP32 epilogue: (raw + bias.float()).to(dtype)
2 GLM-5.3 hard-codes 45 layers / 37 owners Checkpoint-only MTP block makes it 46 layers / 41 owners
1 AWQ gating test uses out_features=64 AwqGEMVFastLinear requires a multiple of 128

Bonus: the Ada GEMM/GEMV suites carried the same stale epilogue contract and
failed 10 more cases on main. They are fixed here too.

Bias epilogue on the fused and split paths

TorchLinear adds the bias to the FP32 partial sum and rounds once, so the
visible output is round(matmul + bias). The oracle previously rounded first and
added bias afterwards in the activation dtype, which is one extra rounding.

flowchart TD
    A["TorchLinear._forward_eager"] --> B{"fused GEMV / GEMM?"}
    B -- "yes" --> C["gptq_gemv / gptq_gemm with out_dtype=float32"]
    C --> D["_apply_fused_bias: (out + bias.float()).to(x.dtype)"]
    B -- "no" --> E{"_can_fuse_hip_bias?"}
    E -- "yes" --> F["torch.addmm(bias, x_flat, weight)"]
    E -- "no" --> G["torch.matmul then add bias"]
    D --> H["visible output"]
    F --> H
    G --> H
Loading

_can_fuse_hip_bias is the single decision point for the split path. The oracles
now apply the same rule to the independent FP64 accumulation.

FP32 arithmetic error stays a separate assertion from output rounding. A visible
difference from the rounded FP64 oracle is accepted only when the FP32 and FP64
fused values straddle the rounding boundary
(|fp64_midpoint - fp64_fused| <= |fp32_fused - fp64_fused|). The GEMV oracle
also asserts _can_use_rocm_gemv(x) so a silent fallback cannot pass.

Measured on one seeded sample per row (4-bit, group size 128, K=2048, N=1024):

Activation Path Fused-rule mismatches Differs from round(fp64 + bias) Unexplained
float16 GEMV (M=1) 0 0 0
float16 fused GEMM (M=2) 0 17 elements 0
bfloat16 GEMV (M=1) 0 0 0
bfloat16 split addmm (M=2) 0 0 0

The 17 differing elements are all explained by FP32-vs-FP64 reduction order
crossing the rounding boundary; they are not kernel error.

GLM-5.3 MTP checkpoint ownership

The public checkpoint stores a non-mHC MTP block at
model.language_model.layers.45. Transformers instantiates only the 45 target
layers; _attach_glm5_next_mtp appends Glm5NextMTPDecoderLayer so the loader
sees the checkpoint namespace. That block owns four envelope tensors beyond the
target-layer schema, all dense:

Checkpoint key (layer 45) Owner Representation
enorm.weight enorm RMSNorm, dense
hnorm.weight hnorm RMSNorm, dense
eh_proj.weight eh_proj linear projection, dense
shared_head.norm.weight shared_head.norm RMSNorm, dense
flowchart TD
    C["Checkpoint: layers.45.*"] --> A["_attach_glm5_next_mtp"]
    A --> L["language_model.layers[45]: Glm5NextMTPDecoderLayer"]
    L --> T["Glm5NextQModel.module_tree"]
    T --> P["ModulePlan.from_tree"]
    P --> F{"plan.find(owner)"}
    F -- "enorm / hnorm / eh_proj / shared_head.norm" --> D["ModuleSpec with :! exclusion"]
    F -- "layers.45.mlp.experts.N.gate_proj etc." --> Q["quantizable routed spec"]
    F -- "undeclared owner" --> E["Test failure: weight owner undeclared"]
    D --> S["state_dict keeps source dtype; no quantization"]
    Q --> R["Routed quantization"]
    style E fill:#fee,stroke:#b22
Loading
Mechanism Before After
module_tree GLM leaves Target-layer leaves only Adds enorm:!, hnorm:!, eh_proj:!, shared_head.norm:!
plan.find("enorm") and the other three None Dense spec with explicit exclusion tag
Registry fixture blocks 14 ordered blocks 18, in MTP forward order
Flash-case counts 45, 37 46, 41

Obligations are decided from checkpoint ownership, not by moving a counter: the
four owners are state_dict() tensors present exactly once in layer 45, declared
dense because none is a quantized projection. Layer 45's routed
gate_proj/up_proj/down_proj remain quantized through the existing
experts:routed block.

The tree is layer_modules_strict = False, so target layers 0-44 not owning
these leaves is fine. The test now derives the MTP layer count instead of
hard-coding target layers, checks the appended layer's layer_idx, and asserts
every declared dense owner resolves through plan.find() with an explicit
:!/:? tag.

AWQ GEMV gating

AwqGEMVFastLinear declares SUPPORTS_OUT_FEATURES_DIVISIBLE_BY = (128,). The
device-family test used out_features=64, so it was rejected by the shape guard
before the device check it meant to exercise.

The device tests now build a shape legal for every kernel (LCM of the declared
alignments) and additionally assert the error text does not mention
out_features. A new test covers the unaligned width on a supported device and
asserts the shape guard is the rejection reason.

Reference pages

docs/rocm-rdna4.md gains the fused-epilogue flow, path table and measurement.
docs/glm-integrated-mtp.md gains the MTP ownership flow, owner table and
before/after comparison. Both diagrams are drawn from the shipped code.

Validation

Both accelerator suites pass on real hardware, plus the CPU module-tree suites:

  • ROCm GEMM + GEMV + AWQ gating: 110 passed, 92 skipped (was 20 failed)
  • Ada GEMM + GEMV: 106 passed (was 10 failed)
  • Module-tree + GLM support + registry + MoE coverage: 252 passed, 135 skipped
  • ruff check on all changed Python files: clean

The remaining tests/module_tree failures on main (fusable cohere_compass,
fusion-kernel backend inventory, one prepare_layer_replay_keep_mask stub) are
pre-existing and reproduce unchanged on a pristine main checkout, so they are
out of scope here.

Note on the lint-only commit

main at 1c5039543 already fails ruff-check on
tests/test_ricursive_modeling_contracts.py:119 (C408 Unnecessary dict() call,
introduced by #3752); the check is red on main itself, not caused by this branch.
Because the gate must pass for this PR, a second commit rewrites that kwargs
dict(...) as a literal. It is mechanical, touches no assertion, and the file's
27 tests pass.

Update stale test contracts that no longer match shipped behavior after
bias was fused into the FP32 epilogue and after the checkpoint-only MTP
block became visible in the module tree. Neither change is a kernel
regression.

ROCm/NVIDIA bias epilogue:
- The visible output is round(matmul + bias), not round(matmul) + bias,
  on the fused GEMV/GEMM paths and on the split addmm path. Update the
  ROCm GEMM/GEMV and Ada GEMM/GEMV oracles to add bias to the FP32
  partial sum and round once.
- Apply the same fused epilogue to the independent FP64 adjudication
  oracle, and keep FP32 arithmetic error separate from output rounding:
  a visible difference is accepted only when the FP32 and FP64 fused
  values straddle the rounding boundary.
- Assert the fused GEMV dispatch so a fallback cannot silently pass.

GLM-5.3 MTP ownership:
- The checkpoint-only layer 45 MTP block owns enorm, hnorm, eh_proj and
  shared_head.norm beyond the target-layer schema. Declare them as dense
  `:!` owners in Glm5NextQModel.module_tree and in the registry fixture.
- The resolved layer list is 46 (45 target + 1 MTP) with 41 owners.
  The test now derives the MTP count instead of hard-coding only target
  layers, and checks every declared dense owner resolves through
  ModulePlan.find() with an explicit exclusion tag.

AWQ GEMV gating:
- Device-family rejection used out_features=64, which AwqGEMVFastLinear
  rejects for shape reasons. Use a legal shape per kernel and assert the
  error is the device family, then add a separate test for the illegal
  width rejection on a supported device.

Reference pages with diagrams and measured numbers:
docs/rocm-rdna4.md and docs/glm-integrated-mtp.md.
main's ruff-check fails on this file at 1c50395 (introduced by #3752):
`C408 Unnecessary dict() call`. Rewrite the call kwargs as a plain literal
so the lint gate can pass. No behavioural change; the file's 27 tests pass.
@Qubitium
Qubitium marked this pull request as ready for review November 10, 2026 09:36

@Qubitium Qubitium left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the fused-bias oracle changes, GLM-5.3 MTP ownership declarations, and AWQ shape gating. Local CUDA/CPU validation: 380 passed, 1 skipped; changed Python files pass Ruff and the PR checks are green. ROCm-specific execution was reported by the author and is unavailable on this CUDA host.

@Qubitium
Qubitium merged commit 85d01df into main Nov 10, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/test-contract-sync branch November 10, 2026 09:36

Copy link
Copy Markdown
Collaborator

Review notes (merged as 85d01dfba4dd): I checked the fused-bias oracle changes, the GLM-5.3 MTP envelope declarations, and the AWQ alignment fixture against the implementation. The changed CUDA/CPU suites passed locally (380 passed, 1 skipped), Ruff and git diff --check passed, and the PR checks were green. This host has no ROCm runtime; I reviewed that path against the submitted ROCm validation results and its dispatch/epilogue code. No further changes were needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants