Skip to content

[Example]: Dspark W4A16 PTQ script - #2027

Draft
h-guo18 wants to merge 1 commit into
mainfrom
haoguo/dspark-ptq-script
Draft

[Example]: Dspark W4A16 PTQ script#2027
h-guo18 wants to merge 1 commit into
mainfrom
haoguo/dspark-ptq-script

Conversation

@h-guo18

@h-guo18 h-guo18 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: new example

Adds examples/speculative_decoding/scripts/quantize_drafter.py, a CLI that quantizes an exported speculative-decoding drafter to W4A16 NVFP4.

Needs no calibration data (the preset's per-block scales are dynamic, so mtq.quantize is called without a forward_loop) and no modeling code — exported drafters such as nvidia/MiniMax-M3-DSpark have no importable model class, so each 2-D weight is wrapped in a throwaway nn.Linear under its checkpoint key and ModelOpt's usual quantizer_name patterns select over those names. Works for any drafter layout. Config comes from QUANT_CFG_CHOICES; packing and scales go through the existing export helpers. No library code touched.

Usage

python scripts/quantize_drafter.py \
    --drafter_path nvidia/MiniMax-M3-DSpark \
    --export_path ./MiniMax-M3-DSpark-W4A16
w4a16_nvfp4: 9.98 GiB -> 3.51 GiB

Writes a unified-HF checkpoint (w.weight / w.weight_scale / w.weight_scale_2) plus hf_quant_config.json. lm_head is excluded by default — unlike on a base model it is 37% of this drafter's parameters, so --quantize_lm_head is a real lever (~1.9 GiB), but measure AL first.

Testing

No automated test yet (see checklist). Validated on nvidia/MiniMax-M3-DSpark: runs in 67 s on CPU, 9.98 GiB (fp32) -> 3.51 GiB; all 43 quantized tensors round-trip within 0.0952 relative error; the 29 untouched tensors are bit-identical to bf16(source); the 86 added keys are exclusively scale buffers. pre-commit passes.

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ❌ — validated manually as above. Can add a tests/examples/speculative_decoding/ test over a small synthetic drafter if wanted before merge.
  • Did you update Changelog?: N/A (example-only)
  • Did you get Claude approval on this PR?: ❌ (not yet run)

Additional Information

Whether vLLM's DSpark drafter loader honours quantization_config on the draft model is not verified here.

Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2ad43cef-3d80-4196-9c48-5156f96f2b66

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.83%. Comparing base (87c9f8c) to head (2ec20d0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2027   +/-   ##
=======================================
  Coverage   66.83%   66.83%           
=======================================
  Files         519      519           
  Lines       58916    58916           
=======================================
  Hits        39376    39376           
  Misses      19540    19540           
Flag Coverage Δ
unit 54.89% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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