Skip to content

fix(awq): preserve scale-search routing and reject incomplete replay groups - #4144

Merged
Qubitium merged 5 commits into
mainfrom
fix/awq-search-stabilization
Nov 15, 2026
Merged

Qubitium merged 5 commits into
mainfrom
fix/awq-search-stabilization

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Make AWQ scale search and final folding agree, reject incomplete/ambiguous replay groups, and repair confirmed architecture-boundary mistakes with the existing module-tree syntax. No DSL or automatic graph tracing.

The source audit covered 206 model types / 182 definitions. Its 14 unsafe-acceptance entries led to conservative corrections in 13 definition families; this is not certification of every supported model.

What Changed

  • Candidate replay uses Q(W * s) / s on the original input and leaves non-quantized routers/shared gates unchanged. Final folding still compensates declared consumers.
  • Restore candidate weights and remove replay-observation hooks in finally. Validate live bindings, widths, replay containment, declared-target execution and equal reference/candidate chunk counts.
  • Check duplicate/shared/tied fold conflicts before low-sample or missing-feature filtering. Unsafe generated groups use configured fallback or raise with fallback=None; conflicts always raise.
  • Correct parallel/shared-input stages and nested router ownership in CohereCompass, GraniteMoE-SWA, Hunyuan, InternLM2 and MiniCPM. Add conservative :nosrc boundaries/explicit owners for AXK2, GLM-MoE-DSA, LongCatFlash, Falcon Mamba, Moss, Gemma3n, Inkling and original Qwen.
  • Add 38 real-tiny CPU/ownership/declaration checks and update only the 10 affected registry snapshots. Correct the stale MiniMax test expectation: its output gate reads the same input as QKV; no production MiniMax change.
  • Dedicated CPU CI runs unit, dense and MoE jobs on Python 3.12 with 20-minute timeouts and uploaded JUnit results. Unit CI now includes registry, architecture-relationship and subset-ordering tests. Checkpoint downloads/validation fail rather than silently skip.
  • No new tags/schema, kernels, checkpoint format, persistent expanded weights, mask/position reconstruction or automatic cross-root replay.

Tests

  • CPU unit/regression tests executed and passed.
  • New fast targeted tests added.

Python 3.12.16, Torch 2.15.0, Transformers 5.22.2, Defuser 0.0.31; CPU only. -s avoids an older user-site Defuser shadowing the installed supported version.

python -s -m pytest \
  tests/test_awq_{scale_search_safety,moe_router_scaling,scaling_groups,scale_folding,weight_mean,per_module_bits,empty_groups,mla_scaling,dynamic_group_size,position_kwargs,rank_and_empty,rotary_device,vl_rotary_resolution,scale_search_memory,clip_consistency,affine_range}.py \
  tests/module_tree/test_{registered_module_plans,awq_relationships,granite_swa_model_tree,definition_subset_ordering}.py \
  -q -o addopts='' -o log_cli=false --timeout=300 \
  -o junit_family=legacy --junitxml=awq-final-cpu.xml
# 929 passed, 100 skipped, 1 warning in 37.36s
# Skips: 89 CUDA unavailable, 9 absent local model fixtures, 2 non-buildable HF families.

python -s -m ruff check gptqmodel docs/eora tests setup.py
PATH=/home/ubuntu/.pyenv/versions/3.12.16/bin:$PATH bash format/check.sh
python -s -m compileall -q gptqmodel tests
git diff --check
# All passed

Type-checking all 13 touched definitions reports two pre-existing Inkling nullable-attribute diagnostics, identical to the pre-follow-up source. No new definition diagnostics. The original processor comparison also reported no new diagnostics.

Independent Torch FP32 oracles cover candidate loss/selection and transformed outputs; FP32/FP16/BF16 identity-quantizer tests check router neutrality, and injected failures check exact rollback. Restoring old search code produced 12 expected failures. Old architecture declarations also fail the new native regression checks.

Trained Hugging Face CPU checkpoints

python -s -m pytest tests/test_awq_hf_cpu.py \
  -q -s -o addopts='' -o log_cli=false --timeout=1200 \
  -o junit_family=legacy --junitxml=awq-hf-cpu.xml
# Dense and MoE both passed locally; independently exercised by CPU CI.
Model / pinned revision Packed AWQ linears Baseline → quantized NLL Relative logit RMSE Coverage fallbacks
SmolLM2-135M 210 2.659599 → 2.905344 0.192753 0
TinyMoE-100M 280 3.460494 → 3.454560 0.057763 2

Downloads allow only JSON/tokenizer/safetensors, with trust_remote_code=False. Tests perform real CPU AWQ quantization, verify packed counts and floating-point routers, enforce finite outputs and held-out drift limits, save safetensors with no new pickle payloads, explicitly reload FP16, and compare reloaded logits and greedy generation.

Model Support / Module Plan

  • No new models/aliases; existing explicit registry cases updated where block paths/order/owners changed.
  • Real native tiny modules cover shared/no-shared Granite, nested Hunyuan routers, Falcon Mamba width collisions, AXK2/GLM indexers, LongCat residuals, dense/sparse Inkling text layers, MHA/GQA CohereCompass and Gemma3n's native AltUp/Laurel decoder.
  • Architecture-fixture state_dict() entries resolve to deepest owners; quantized owners are declared and non-quantized owners explicitly excluded. Inkling's global_scale is a native trainable parameter, not a runtime cache.
  • Registry and model-specific tests passed; skips are not qualification.
  • Fusion declarations, fusion dispatch and kernel support are unchanged; new fusion/backend qualification requirements are not applicable.

Key nodes: test_every_inferred_fold_preserves_full_text_outputs, test_real_model_weight_owners_are_declared, test_native_branched_decoders, and test_cross_branch_groups_reject_incomplete_replay in test_awq_relationships.py.

Legacy Moss, InternLM2, MiniCPM and Qwen have separate pinned-source CPU audit probes, rerun against these fixes. Their CI declaration checks do not claim remote full-model/checkpoint qualification. Inkling's fixture exercises the real text backbone under its multimodal checkpoint prefix; Gemma3n exercises its real decoder, not a downloaded multimodal checkpoint.

Logic Flow Documentation

  • Shipped symbols and explicit failure/ambiguity paths.
  • Before/after evidence.
  • Same diagrams/table in AWQ scaling groups, linked from README.
flowchart TD
    A["AWQProcessor._quantize_layer"] --> B["_validate_scale_group_conflicts"]
    B --> C{"source or target overlap?"}
    C -- "yes" --> X["raise _AWQScaleGroupError<br/>no folds applied"]
    C -- "no" --> P["filter low-sample / missing-feature groups"]
    P --> D["_search_best_scale<br/>_validate_scale_group"]
    D --> E{"exact live bindings, widths,<br/>and targets inside replay boundary?"}
    E -- "no" --> F{"configured fallback enabled?"}
    E -- "yes" --> G["reference forward<br/>temporary target observation hooks"]
    G --> H["finally remove observation hooks"]
    H --> R{"reference replay succeeded?"}
    R -- "no" --> Y["propagate evaluation exception"]
    R -- "yes" --> I{"every declared target executed?"}
    I -- "no" --> F
    I -- "yes" --> J["_compute_best_scale<br/>20 candidates: Q(W * s) / s<br/>routers and shared gates unchanged"]
    J --> K["finally restore original weights"]
    K --> L{"candidate evaluation succeeded?"}
    L -- "yes" --> M["collect scale results<br/>apply_scale once per source<br/>apply_quant"]
    L -- "no" --> Y
    F -- "yes" --> N["warn with group and reason<br/>exclude group from folding and clipping<br/>apply_quant with empty scales"]
    F -- "no" --> X
    style X fill:#f8d7da,stroke:#842029,stroke-width:2px
    style Y fill:#f8d7da,stroke:#842029,stroke-width:2px
    style N fill:#fff3cd,stroke:#997404,stroke-width:2px
Loading
Before (baseline c9efdbacf) Now
Candidate search multiplies non-quantized consumer weights (awq_processor.py:3099-3119). Search leaves them unchanged; final folding still compensates them.
Shared-source merge retains the first inspection module for cross-root groups (models/base.py:5540-5546). Group construction remains unchanged, but search rejects boundaries missing any member rather than scoring only one branch.
A contained target need not execute during replay (awq_processor.py:2551-2572). Reference-forward observation rejects unexecuted targets before candidate mutation; observation hooks are always removed.
Weight restoration occurs only after successful grid evaluation (awq_processor.py:3267-3278). Restoration is in finally, covering quantizer, replay, and loss exceptions.
Search results are collected without a group-validation fallback (awq_processor.py:2352-2359). Unsafe replay groups use the existing configured fallback with a warning, or raise with fallback disabled. Conflicting folds always raise.

Existing declarations now control the conservative path:

flowchart TD
    A["architecture module_tree<br/>parallel stages, :in, nested :!, :nosrc"] --> B["awq_get_modules_for_scaling"]
    B --> C["_merge_shared_source_nodes"]
    C --> D["_filter_awq_scaling_sources"]
    D --> E{"selected source is :nosrc?"}
    E -- "yes" --> P["drop smoothing group<br/>existing plain quantization path"]
    E -- "no" --> F["AWQProcessor._quantize_layer<br/>conflict, boundary and execution checks"]
    F --> G{"complete supported replay?"}
    G -- "yes" --> H["search and fold once"]
    G -- "no: _AWQScaleGroupError" --> I{"configured fallback enabled?"}
    I -- "yes" --> P
    I -- "no" --> X["raise; no unsafe fold"]
    F -- "raw forward exception" --> Y["propagate; not a safe fallback"]
    style P fill:#fff3cd,stroke:#997404
    style X fill:#f8d7da,stroke:#842029
    style Y fill:#f8d7da,stroke:#842029
Loading

The architecture qualification table records the per-family before/after changes.

Review Requirements

  • Reviewed implementation, tests and architecture findings.
  • Followed existing APIs/extension points; no new declaration language.
  • Kept production changes to the shared processor safety fixes and narrow definition metadata.
  • Checked rollback, routing, ownership, grouping and regression behavior.

Kernel Accuracy Requirements

No inference kernel, packer, fusion dispatch or persistent-weight-storage change. Search arithmetic is covered by independent Torch CPU oracles; GPU/native backend qualification is not claimed.

Notes

  • :nosrc deliberately uses the existing plain-quantization path. This is distinct from a generated group rejected under fallback=None. Conservative boundaries trade smoothing coverage for correctness.
  • The audit matrix retains audited revision 388f82f01: 70 static-appears-safe, 65 CPU-confirmed, 14 unsafe-accepted, 13 safe rejection/fallback, 30 unverified source, 9 unverified execution, 2 unverified layout and 3 raw replay errors.
  • 41 source/execution/layout gaps and 3 raw replay-error entries remain unqualified. Native Bloom's missing residual replay argument remains a raw exception, not safe fallback. Executing all declared targets still cannot discover omitted consumers or prove producer identity.
  • Automatic whole-layer/cross-root replay, a wiring DSL, and arbitrary dynamic-graph safety remain out of scope.

Link to Devin session: https://app.devin.ai/sessions/c7078b36d9ee47ee8105dc9185147b39
Open in Devin Desktop: https://app.devin.ai/desktop/session/c7078b36d9ee47ee8105dc9185147b39?variant=devin
Requested by: @Qubitium

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@Qubitium
Qubitium marked this pull request as ready for review November 15, 2026 12:33
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Devin Review

🟢 Devin Review found nothing to fix · View findings

Comment thread tests/test_awq_hf_cpu.py Resolved
Comment thread tests/test_awq_hf_cpu.py Resolved
Comment thread tests/test_awq_hf_cpu.py Resolved
Comment thread tests/test_awq_hf_cpu.py Resolved

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

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