Repository navigation
test(contracts): align fused-bias oracles and GLM-5.3 MTP ownership - #3756
Conversation
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.
Qubitium
left a comment
There was a problem hiding this comment.
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.
|
Review notes (merged as |
Summary
Three shipped behaviours changed on
mainwithout their test contracts beingupdated. This PR re-synchronises the contracts. None of the 23 failures was a
kernel regression.
Verified on a clean checkout of
mainat1c5039543: all 23 reproduce there,so nothing is already fixed upstream. No open PR covers the same files.
round(matmul) + bias(raw + bias.float()).to(dtype)out_features=64AwqGEMVFastLinearrequires a multiple of 128Bonus: 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
TorchLinearadds the bias to the FP32 partial sum and rounds once, so thevisible output is
round(matmul + bias). The oracle previously rounded first andadded 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_can_fuse_hip_biasis the single decision point for the split path. The oraclesnow 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 oraclealso 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):round(fp64 + bias)addmm(M=2)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 targetlayers;
_attach_glm5_next_mtpappendsGlm5NextMTPDecoderLayerso the loadersees the checkpoint namespace. That block owns four envelope tensors beyond the
target-layer schema, all dense:
enorm.weightenormhnorm.weighthnormeh_proj.weighteh_projshared_head.norm.weightshared_head.normflowchart 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:#b22module_treeGLM leavesenorm:!,hnorm:!,eh_proj:!,shared_head.norm:!plan.find("enorm")and the other threeNone45,3746,41Obligations are decided from checkpoint ownership, not by moving a counter: the
four owners are
state_dict()tensors present exactly once in layer 45, declareddense because none is a quantized projection. Layer 45's routed
gate_proj/up_proj/down_projremain quantized through the existingexperts:routedblock.The tree is
layer_modules_strict = False, so target layers 0-44 not owningthese 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 assertsevery declared dense owner resolves through
plan.find()with an explicit:!/:?tag.AWQ GEMV gating
AwqGEMVFastLineardeclaresSUPPORTS_OUT_FEATURES_DIVISIBLE_BY = (128,). Thedevice-family test used
out_features=64, so it was rejected by the shape guardbefore 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 andasserts the shape guard is the rejection reason.
Reference pages
docs/rocm-rdna4.mdgains the fused-epilogue flow, path table and measurement.docs/glm-integrated-mtp.mdgains the MTP ownership flow, owner table andbefore/after comparison. Both diagrams are drawn from the shipped code.
Validation
Both accelerator suites pass on real hardware, plus the CPU module-tree suites:
ruff checkon all changed Python files: cleanThe remaining
tests/module_treefailures onmain(fusable cohere_compass,fusion-kernel backend inventory, one
prepare_layer_replay_keep_maskstub) arepre-existing and reproduce unchanged on a pristine
maincheckout, so they areout of scope here.
Note on the lint-only commit
mainat1c5039543already failsruff-checkontests/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's27 tests pass.