Skip to content

fix(awq): validate candidate group sizes against kernel out_features constraints (#4095) - #4100

Closed
Prajwal7-2002 wants to merge 1 commit into
ModelCloud:mainfrom
Prajwal7-2002:fix/awq-dynamic-group-size-out-features
Closed

Prajwal7-2002 wants to merge 1 commit into
ModelCloud:mainfrom
Prajwal7-2002:fix/awq-dynamic-group-size-out-features

Conversation

@Prajwal7-2002

Copy link
Copy Markdown
Contributor

Summary

Fixes item 3 of #4095.

In MoE architectures like \Phi-tiny-MoE, expert \gate_proj\ and \up_proj\ layers have \in_features = 1024\ (or 2048) and \out_features = 448. Under default \AWQConfig(bits=4, group_size=128), \in_features\ is divisible by 128, so _ensure_group_size_divisibility\ previously skipped these layers. However, \AwqGEMMLinear._validate\ requires \out_features % group_size == 0. Because \448 % 128 == 64 != 0, module creation crashed at packing time with:
\
NotImplementedError: AWQ GEMM requires a group size divisible by 32 and out_features divisible by that group size: got out_features=448, group_size=128
\\

Changes

  1. Candidate Group Size Validation: Added _kernel_supports_candidate_group_size\ in \AWQProcessor\ to validate candidate group sizes against the resolved kernel's contract (\in_features, \out_features, \group_size, \�its, \sym, \desc_act, \pack_dtype) with \check_platform=False.
  2. **_largest_supported_group_divisor**: Accepts \out_features\ and tests candidate divisors against both \in_features % size == 0\ and kernel validation.
  3. **_ensure_group_size_divisibility**: Checks whether configured group size satisfies both \in_features\ divisibility and kernel shape/dimension constraints. When invalid, it retunes to the largest valid supported divisor (e.g. \64).
  4. Tests:
    • Added \ est_awq_retunes_group_size_for_non_divisible_out_features\ in \ ests/test_awq_dynamic_group_size.py.
    • Fixed missing _module_format\ attribute on test \Stub.
    • All 4 tests in \ ests/test_awq_dynamic_group_size.py\ pass.

…constraints (ModelCloud#4095)

Phi-tiny-MoE expert gate_proj/up_proj have out_features=448 and in_features divisible by 128. AwqGEMMLinear requires out_features to be divisible by group_size, causing a crash during create_quant_module. Check candidate group sizes against kernel validation in _ensure_group_size_divisibility and _largest_supported_group_divisor, retuning to 64. Add out_features=448 regression test.

Signed-off-by: Prajwal7-2002 <[email protected]>
@Prajwal7-2002

Copy link
Copy Markdown
Contributor Author

Thanks @Qubitium for expanding the validation and adding the docs + multi-GPU test runs in #4104! Closing this in favor of #4104.

@Qubitium

Copy link
Copy Markdown
Collaborator

Thank you for this — the diagnosis is right and the out_features=448 case is genuinely the crash in #4095 item 3.

I'm closing this as superseded rather than merging, for two concrete reasons found during review, both worth recording:

  1. -1 is recorded as a group-size override without being validated. For the unpackable shapes (4096 -> 16 router, 448 -> 8) _largest_supported_group_divisor returns -1 and it is written into dynamic={"group_size": -1}, which still fails AwqGEMMLinear._validate (out_features must be divisible by 64). The fix needs to leave the configured size alone when even per-channel cannot pack, instead of emitting an override that cannot be honoured.
  2. The existing input-axis test was changed from 448 -> 8 to 448 -> 512. That shape is exactly the one that exposes (1), so the edit hides the gap rather than covering it.

Also: the deepest except in the _validate try/except chain returns True, so an unexpected exception reads as "supported" — the unsafe direction for a capability check.

The fix that lands (#4104) keeps your approach but validates the candidate before recording it, calls the public validate() (returning False on exceptions), adds a 4096 -> 16 no-override regression, and adds docs/awq-dynamic-group-size.md. Credit for the original shape analysis is yours, and I'd welcome a review on #4104.

Closing as superseded — not as invalid.

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