Skip to content

fix(awq): drop folds whose source has no weight elements - #6663

Merged
Qubitium merged 2 commits into
mainfrom
fix/awq-zero-size-fold-targets
Dec 1, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/awq-zero-size-fold-targets

Conversation

@Qubitium

@Qubitium Qubitium commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

#6657 keeps a declared AWQ fold whose first reader captured nothing. A port materializes a config-disabled projection as a zero-sized Linear; Klear's mlp.shared_experts with n_shared_experts=0 is gate_proj/up_proj = [0, hidden] and down_proj = [hidden, 0]. planned_group() accepted that empty projection as a fold source, so mlp.shared_experts.up_proj -> down_proj became a scaling group on the no-shared variant.

tests/module_tree/test_klear_local_port.py::test_awq_folds_are_neutral_on_dense_and_moe_layers[...-no-shared] fails on main for this reason.

What Changed

  • planned_group() now returns DROP when the source's weight tensor has no elements. A zero-sized source has no output to divide and no weight to absorb a scale, so it cannot be a scaling group; the target falls back to plain quantization like any other dropped group.
  • Added test_planned_group_rejects_a_zero_size_source to the declared-fold planner family.

No API or config changes. This is general to every definition, not a Klear special case.

Tests

# RED on main (0127a0313), branch's test file copied onto the main checkout
python -P -m pytest tests/module_tree/test_awq_fold_declarations.py::test_planned_group_rejects_a_zero_size_source -q
# 1 failed

# RED on main (0127a0313)
python -P -m pytest tests/module_tree/test_klear_local_port.py -q
# 3 failed, 44 passed
#   test_awq_folds_are_neutral_on_dense_and_moe_layers[1-False-no-shared]
#   test_awq_folds_are_neutral_on_dense_and_moe_layers[2-True-no-shared]
#   test_awq_folds_are_neutral_on_dense_and_moe_layers[4-False-no-shared]

# GREEN on the branch
python -P -m pytest tests/module_tree/test_klear_local_port.py -q
# 47 passed
python -P -m pytest tests/module_tree/test_awq_fold_declarations.py -q
# 14 passed

# AWQ safety baseline from the skill
python -P -m pytest -q tests/test_awq_scale_search_safety.py tests/test_awq_moe_router_scaling.py \
  tests/test_awq_empty_groups.py tests/test_awq_position_kwargs.py tests/test_awq_scale_search_memory.py \
  tests/test_bloom_awq_replay.py tests/module_tree/test_awq_relationships.py \
  tests/module_tree/test_bloom_awq_relationships.py tests/module_tree/test_registered_module_plans.py \
  tests/module_tree/test_definition_subset_ordering.py
# 591 passed, 3 skipped

# Full module-tree family
python -P -m pytest tests/module_tree tests/test_awq_declaration_empty_capture.py \
  tests/test_awq_moe_root_capture_4697.py -q
# 4470 passed, 807 skipped, 3 xfailed

python -P -m tests.module_tree.awq_fold_inventory --check
# changed: none

bash format/check.sh
# ruff 0.14.2, All checks passed

CPU only, CUDA_VISIBLE_DEVICES=.

Measured Impact

Seeded A/B on NVIDIA GB10 (sm_121), torch 2.15.0+cu132, Qwen2.5-0.5B-Instruct, 64 wikitext rows, batch_size=1, save + reload BACKEND.AUTO + greedy 32 tokens. Main 0127a0313 vs this branch:

Workload Tensors compared Result AUTO kernel Greedy text
GPTQ 4-bit g128 794 bit-identical MarlinLinear both identical
AWQ 4-bit g128 626 bit-identical AwqMarlinLinear both identical

Model Support / Module Plan

Not applicable: no model, alias or definition change.

AWQ onboarding safety

  • Native forward evidence: Klear's no-shared variant materializes zero-sized shared-expert projections; they have no output and cannot read the norm. The fold is rejected at the planner before any scale is applied.
  • Real-model neutral folds: test_klear_local_port.py covers dense/MoE/mixed/periodic/no-shared layouts and all pass with the fix.
  • Fallback: the dropped group's targets quantize plainly, the existing configured fallback path.
  • Policy: Klear no-shared is plain-quantization-only for the shared-expert fold; all other layouts keep their folds (full module-tree run above).

Logic Flow Documentation

Not applicable: this adds one DROP verdict inside the existing planned_group() filter. No control-flow mechanism, resolution order or tensor lifecycle changes.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions (A/B above).

Kernel Accuracy Requirements

Not applicable: planner filter only; no kernel, dispatch or fusion change.

Notes

Refs #6657. The regression is reproducible on 0127a0313 and disappears with the one-condition drop. Pre-existing failures seen on this host (missing /monster/data fixtures, optional deps) are unrelated.

GB10 Sweep added 2 commits December 1, 2026 15:42
A port materializes a config-disabled projection as a zero-sized Linear.
Klear's mlp.shared_experts with n_shared_experts=0 is the concrete case:
gate_proj/up_proj are [0, hidden] and down_proj is [hidden, 0].

After #6657 kept declared folds whose first reader captured nothing, the
planner also kept a fold whose source is one of those empty projections.
planned_group() only checked the module plan and widths, so the node became
a scaling group; tests/module_tree/test_klear_local_port.py then sees the
shared_experts.up_proj -> down_proj fold in the no-shared plan.

Reject a source whose weight tensor has no elements in the shared planner
filter. A zero-sized source has no output to divide and no weight to absorb
a scale, so the group cannot be folded; the target falls back to plain
quantization like any other dropped group. This is general to every
definition, not a Klear special case.

Refs #6657
The planner unit test fails on main because planned_group() accepts a
zero-sized Linear as a fold source, and passes with the fix.
@Qubitium
Qubitium marked this pull request as ready for review December 1, 2026 17:42
@Qubitium
Qubitium merged commit c224ee9 into main Dec 1, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/awq-zero-size-fold-targets branch December 1, 2026 17:42
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.

1 participant