Skip to content

Nunchaku Lite quantization in place - #14608

Draft
rootonchair wants to merge 7 commits into
huggingface:mainfrom
rootonchair:feature/data-free-quantization
Draft

Nunchaku Lite quantization in place#14608
rootonchair wants to merge 7 commits into
huggingface:mainfrom
rootonchair:feature/data-free-quantization

Conversation

@rootonchair

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes # (issue)

Before submitting

  • Did you use an AI agent (Claude Code, Codex, Cursor, etc.) to help with this PR? If so:
    • Did you read the Coding with AI agents guide?
    • Did you run the self-review skill on the diff?
    • Did you share the final self-review notes in the PR description or a comment?
  • Did you read the contributor guideline?
  • Did you read our philosophy doc? (important for complex PRs)
  • Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?
  • Are you the author (or part of the team) of the model/pipeline (only applicable for model/pipeline related PRs)?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

rootonchair and others added 7 commits August 25, 2026 18:40
Support `pre_quantized=False` in NunchakuLiteQuantizationConfig: targeted
linears of an unquantized checkpoint are quantized at load time with
data-free SVDQuant (weight-span smoothing, rank-r SVD low-rank branch,
int4/nvfp4 group quantization) and packed directly into the kernel layout
SVDQW4A4Linear consumes — no calibration data needed.

The math lives in quantizers/nunchaku/data_free.py, which is pure torch and
stays importable without the `kernels` package; quantization happens per
weight in create_quantized_param so peak memory stays near the quantized
model size. Packed outputs are tensor-for-tensor identical to
DeepCompressor's Nunchaku W4A4 converter (verified against it on random
weights; qweight byte-identical). `awq_w4a16` targets are not supported in
this mode and raise. CPU tests validate shapes, round-trip reconstruction
error, bias packing, and the quantizer flow; a gated GPU mixin test runs
quantize-on-load end to end where kernels are available.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013NAtDkGmAw2fzbcvjfC79w
When `pre_quantized=False` and `svdq_w4a4.targets` is omitted, the quantizer
now infers targets from the model at load time: every nn.Linear whose
dimensions satisfy the Nunchaku packing constraints is selected, minus
modules matched by the new `modules_to_not_convert` config option or listed
in the model's `_keep_in_fp32_modules`. Explicit target lists keep working.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013NAtDkGmAw2fzbcvjfC79w
Auto-inference no longer needs a hand-written modules_to_not_convert list:
targets are restricted to the model's repeated transformer-block stacks
(identical-class nn.ModuleLists), which structurally excludes embedders,
final projections, and modulation heads, and adaLN-style linears inside
blocks are skipped via default ("norm", "modulation") name patterns. An
explicit modules_to_not_convert replaces the default patterns. For
FLUX.2-klein-9B the zero-config inferred target set matches the curated
list exactly (144 targets).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013NAtDkGmAw2fzbcvjfC79w
Clearer pairing with the svdq_w4a4 `targets` field, and avoids implying the
bnb/torchao semantics of keeping modules in high precision at load: the
option only filters data-free target inference.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013NAtDkGmAw2fzbcvjfC79w
Match the bitsandbytes loader contract: filter the load-time-produced packed
parameter names out of missing_keys via update_missing_keys, and remove the
consumed `weight`/`bias` checkpoint keys from unexpected_keys inside
create_quantized_param.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013NAtDkGmAw2fzbcvjfC79w
The module implements the SVDQuant math (smoothing, low-rank split,
quantization, kernel packing) as opposed to utils.py's kernel runtime;
name it after the algorithm. Data-free stays in the function names,
where it describes the mode.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013NAtDkGmAw2fzbcvjfC79w
Name the integration test after the loader mechanism (pre_quantized=False)
rather than the algorithm mode, and rename the companion class attribute to
quantize_on_load_config_dict to match.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013NAtDkGmAw2fzbcvjfC79w
@github-actions github-actions Bot added documentation Improvements or additions to documentation quantization tests size/L PR with diff > 200 LOC labels Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation quantization size/L PR with diff > 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant