h-guo18andClaude Opus 5.5 9047bbd418 fix(speculative): one label alignment per projector_type; DSpark and Domino export the head they built (#2762)
### What does this PR do?

Type of change: Bug fix

A DFlash-family drafter's label alignment belongs to its algorithm.
DSpark and Domino train block position `k` on the token at `anchor + k +
1`: next-token, so the anchor is itself a prediction. DFlash, DFlash2
and LiLiCorr train it on `anchor + k`: each masked position predicts
itself. Since #2757 the class constant `_label_shift` drives the
training targets, but on `main` the same fact is still written in four
more places, and the exports read it from the user's config:

- `DSparkModule.shift_label`, hard-coded `True`.
- `DominoModule.shift_label`, read from the config.
- A `NotImplementedError` in `HFDominoModel.modify`.
- The exporters' `getattr(draft_config, "shift_label", True)`, plus a
literal `sample_from_anchor: True` in the vanilla DSpark export.

Three bugs follow:

1. **`shift_label` in the config is ignored or contradicted.**
- DSpark with `shift_label: false` trains next-token alignment anyway
and exports `shift_label: false`, so a loader that honors the field
reads every drafted position one token off.
   - Domino refuses it, but only after building the draft.
   - DFlash, DFlash2 and LiLiCorr accept the field and ignore it.
2. **The exporters re-read head fields from the raw config.**
- `DSparkModule` casts `markov_rank` to int, so a rank written as `64.0`
trains a rank-64 head and exports `64.0`.
- The vanilla export copies that value to the top level, where vLLM's
`Qwen3DSparkModel` sizes its Markov table.
- `use_confidence_head` and Domino's `pure_draft_prefix_len` are re-read
with defaults of their own.
3. **Domino's HF AR validation drafts one position off, without its
head.** `HFDominoModel` inherits DFlash's `pseudo_speculative_generate`,
which decodes block positions `1..bs-1` with the backbone alone, so
every draft is scored against the wrong target. Shipped training is
unaffected: `domino.yaml` keeps AR validation off.

The fixes:

- **The alignment comes from `projector_type` alone.**
- `shift_label` is deprecated and will be removed in 0.50. Before
converting the model, `convert_to_dflash_model` compares it with the
wrapper class's `_label_shift`:
- A matching value is dropped with a `FutureWarning`. Configs copied
from the old Domino recipe (`shift_label: true`) keep working through
the migration window in the README's deprecation policy.
    - A contradicting value raises, because it never took effect.
- Why the check does not warn and override, as `HFDFlashModel.modify`
does for RoPE: on `main` a contradicting value was already ignored or
refused. DFlash, DFlash2 and LiLiCorr ignored it, DSpark trained
next-token anyway, and Domino refused `false`. Overriding it with a
warning would let a run go on that does not train what its config says.
- Why it is not a `DFlashConfig` validator: the alignment lives on the
plugin's wrapper class, which the config layer does not import. A
validator would also run on restore, where old checkpoints carry
contradicting values.
- `restore_dflash_model` drops the key unchecked before replaying
convert, so checkpoints that carry it still load. DSpark ones saved with
`shift_label: false` now re-export `true`.
- Both halves read one table, `_DEPRECATED_ARCHITECTURE_KEYS` in
`dflash/conversion.py`. It pairs each key with the model attribute that
now fixes its value, and the reason, so the check and the restore filter
cannot drift apart.
- The exports write `shift_label`, and DSpark's `sample_from_anchor`
(vLLM's name for the same alignment), from `_label_shift`.
- The modules' `shift_label` attributes and Domino's own check are gone.
The Domino recipe, the skill sheets and the test configs no longer set
the key.
- **The exporters read the built head** for `markov_rank`,
`markov_head_type`, `use_confidence_head`, `pure_draft_prefix_len`,
`gru_hidden_dim` and `emb_dim`, as `LiLiCorrExporter` already does.
- **Domino's `pseudo_speculative_generate` raises
`NotImplementedError`.**
- HF AR validation is being deprecated (#3107), so Domino gets no decode
of its own.
  - Domino acceptance cannot be measured anywhere yet:
- The inherited decode drafts with the backbone alone, one block
position off.
- The export declares `DFlashDraftModel`, so vLLM would serve it the
same way.
    - `examples/specdec_bench` has no Domino route.

The error, the changelog and the skill sheet now say so, matching the
launcher example's note.
- The eval-time warning that called acceptance rates "backbone-only" is
removed. The `forward` docstring and the skill sheet now note that eval
loss and accuracy exclude the correction head; the recipe sets `do_eval:
false`.
- During training, the AR callback already catches the error and logs
`AR validation not available.`
- **Changelog (0.49.0):** a Deprecations entry for `shift_label`, and a
Bug Fixes entry for the exports and Domino's AR validation.

### Usage

Remove `shift_label` from DFlash-family configs, since `projector_type`
fixes the alignment. Until 0.50 a value that matches the variant only
warns:

```yaml
dflash:
  dflash_architecture_config:
    projector_type: domino
    # shift_label: true  # deprecated: warns until 0.50; false raises
```

### Testing

- New and changed tests:
- `test_deprecated_shift_label[dflash|dspark|domino x true|false]`
restores a modelopt_state that carries `shift_label`, then converts with
it. A matching value warns, converts, and is not saved in the new
modelopt_state. A contradicting one raises and leaves the model
unconverted.
    - All 6 cases fail on `main` (09a14b9ae8).
- With the previous revision's refusal (39ffc25218), the 3 matching
cases fail.
- Without the restore filter, the 3 contradicting cases fail at restore.
- `test_export_config_has_dspark_fields` converts with `markov_rank`
given as a float and expects an int at both config levels. All 8 cases
fail without the exporter change.
- `TestDominoForward::test_ar_validation_is_refused` fails without the
override, because the inherited decode then runs.
- Rebased onto `main` (ef893e7708) as bd19e2d81b. `git range-diff` shows
the same changes commit for commit; only the skill sheets' new location
under `skills/modelopt-speculative-decoding/` and CHANGELOG context
differ.
- At bd19e2d81b, Python 3.12, transformers 5.18.0, torch 2.13:
`test_hf_{dflash,dflash2,dspark,domino,lilicorr}.py`,
`tests/unit/recipe`,
`tests/unit/torch/export/test_hf_spec_rope_export.py`,
`tests/unit/examples/test_deepseek_v4_recipe.py` and
`tools/launcher/tests/test_examples_resolve.py`: 987 passed.
- Before the rebase, at a944d85bb7, Python 3.12, transformers 5.18.0,
torch 2.10: `test_hf_{dflash,dflash2,dspark,domino,lilicorr}.py`, 318
passed.
- At 39ffc25218, which differs from the head only in the `shift_label`
check, Domino's error text and docs:
- Those five files plus `tests/unit/recipe/test_loader.py`,
`tests/unit/torch/export/test_hf_spec_rope_export.py` and
`tests/unit/examples/test_deepseek_v4_recipe.py`: 834 passed.
  - `tools/launcher/tests/test_examples_resolve.py`: 75 passed.
- `tests/gpu/torch/speculative/plugins/test_hf_dflash.py` on 2 GPUs
(torch 2.13): 16 passed.
- Not run:
- transformers 5.5 and 5.12, which CI's multi-version job covers. An
earlier revision passed 792 of these tests on 5.5.4, 5.12.1 and 5.18.0.
  - A bitwise A/B, because no training code changes.

### Before your PR is "*Ready for review*"

Make sure you read and follow [Contributor
guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md)
and your commits are signed (`git commit -s -S`).

Make sure you read and follow the [Security Best
Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors)
(e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(...,
weights_only=False)`, `pickle`, etc.).

- Is this change backward compatible?:
- ✅ for a `shift_label` that matches the variant, including the shipped
Domino recipe's `true`. Such configs convert as before, with a
deprecation warning.
- ❌ for a contradicting `shift_label`, which now raises at convert: it
never took effect. That is DFlash, DFlash2 or LiLiCorr with `true`, and
DSpark or Domino with `false`.
  - Existing checkpoints still load.
- Domino with `shift_label: false` raises `ValueError` instead of
`NotImplementedError`.
- Domino's HF AR validation raises instead of returning misaligned
drafts.
- 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?: ✅
- Did you update
[Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?:
✅ 0.49.0: a Deprecations entry for `shift_label`, and a Bug Fixes entry,
since DSpark and Domino have shipped since 0.46.0.
- Did you get Claude approval on this PR?: ✅ Approved at 39ffc25218. Its
one suggestion is addressed at the head.

### Additional Information

Follow-up to #2757, now merged. The shared-forward PRs, #2989 [1/2] and
then #2990 [2/2], build on this branch and will be restacked onto it.

Found while testing and not fixed here; it fails the same way on `main`:
with `DFlashModule` as its own FSDP2 unit, DSpark and Domino training
fails with `got mixed torch.Tensor and DTensor`, because their heads run
outside `DFlashModule.forward`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Corrected DSpark and Domino export settings to reflect the built model
configuration.
* Fixed a validation error in Domino’s Hugging Face autoregressive
validation; this validation is not supported for Domino.
* **Deprecations**
* `shift_label` is deprecated and planned for removal in version 0.50.
Matching values are ignored with a warning; conflicting values cause an
error. Existing checkpoints containing the setting can still be loaded.
* **Documentation**
* Updated speculative decoding guidance to reflect the deprecation and
Domino’s evaluation limitations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:20:29 +00:00

Banner image

NVIDIA Model Optimizer

Documentation version license

Documentation | Roadmap | Announcement Blogs


NVIDIA Model Optimizer (referred to as Model Optimizer, or ModelOpt) is a library comprising state-of-the-art model optimization techniques including quantization, pruning, Neural Architecture Search (NAS), distillation, speculative decoding and sparsity to accelerate models.

[Input] Model Optimizer currently supports inputs of a Hugging Face, PyTorch or ONNX model.

[Optimize] Model Optimizer provides Python APIs for users to easily compose the above model optimization techniques and export an optimized quantized checkpoint. Model Optimizer is also integrated with NVIDIA Megatron-Bridge, Megatron-LM and Hugging Face Accelerate for training required inference optimization techniques.

[Export for deployment] Seamlessly integrated within the NVIDIA AI software ecosystem, the quantized checkpoint generated from Model Optimizer is ready for deployment in downstream inference frameworks like SGLang, TensorRT-LLM, TensorRT, or vLLM. The unified Hugging Face export API now supports both transformers and diffusers models.

Latest News

Previous News

Install

To install stable release packages for Model Optimizer with pip from PyPI:

pip install -U nvidia-modelopt[all]

Model Optimizer will download and install additional third-party open source software projects. Review the license terms of these open source projects before use.

To install from source in editable mode with all development dependencies or to use the latest features, run:

# Clone the Model Optimizer repository
git clone git@github.com:NVIDIA/Model-Optimizer.git
cd Model-Optimizer

pip install -e .[dev]

You can also directly use NVIDIA container images, which have Model Optimizer pre-installed:

  • nvcr.io/nvidia/pytorch:<version>-py3
  • nvcr.io/nvidia/nemo:<version>
  • nvcr.io/nvidia/tensorrt-llm/release:<version>

Before pulling and using the container images, please review their respective license terms. Make sure to upgrade Model Optimizer to the latest version as described above. Visit our installation guide for more fine-grained control on installed dependencies or for alternative docker images and environment variables to setup.

Techniques

Technique Description Getting started Examples
Post Training Quantization Compress model size by 2x-4x, speeding up inference while preserving model quality! [Start here] [HF LLMs / VLMs] [Megatron-Bridge LLMs / VLMs] [Diffusers] [ONNX] [Windows]
Quantization Aware Training / Distillation Refine accuracy of quantized models even further with a few training steps! [Start here] [Hugging Face] [Megatron-Bridge]
Pruning Reduce your model parameters or memory footprint and accelerate inference by removing unnecessary weights! [Start here] [General] [Megatron-Bridge]
Distillation Reduce deployment model size by teaching small models to behave like larger models! [Start here] [Hugging Face] [Megatron-Bridge] [Megatron-LM]
Speculative Decoding Train draft modules to predict extra tokens during inference! [Start here] [Hugging Face] [Megatron-LM]
Sparsity Efficiently compress your model by storing only its non-zero parameter values and their locations [Start here] [Hugging Face]

Pre-Quantized Checkpoints

Resources

Model Support Matrix

Model Type Support Matrix
LLM / VLM Quantization View Support Matrix
Diffusers Quantization View Support Matrix
ONNX Quantization View Support Matrix
Windows Quantization View Support Matrix
Quantization Aware Training View Support Matrix
Pruning View Support Matrix
Distillation View Support Matrix
Speculative Decoding View Support Matrix

Deprecation Policy

Model Optimizer follows a structured approach to managing deprecated features:

  • Communication: Deprecation notices are documented in the Changelog. Deprecated items include source code statements indicating deprecation timing, with runtime warnings issued upon use.
  • Migration Period: Since Model Optimizer is still pre-1.0, we provide a 1-release (~1-month) migration period after deprecation. During this window, deprecated features continue functioning while issuing warnings.
  • Scope: The policy addresses both complete deprecations (entire APIs removed) and partial ones (specific parameters removed while methods remain).
  • Removal: Following the migration period, deprecated elements are removed in alignment with semantic versioning standards, potentially including breaking changes in minor version updates while Model Optimizer remains in 0.x.

Citation

If you use NVIDIA Model Optimizer in your research, please cite it as follows:

@misc{nvidia-modelopt,
  author       = {{NVIDIA Corporation}},
  title        = {{NVIDIA Model Optimizer}},
  howpublished = {\url{https://github.com/NVIDIA/Model-Optimizer}},
  year         = {2024--2026},
  note         = {GitHub repository}
}

Contributing

Model Optimizer is now open source! We welcome any feedback, feature requests and PRs. Please read our Contributing guidelines for details on how to contribute to this project.

AI Agents

ModelOpt's agent skills can be installed from this repository and used in any workspace.

Claude Code

claude plugin marketplace add https://github.com/NVIDIA/Model-Optimizer.git
claude plugin install modelopt@modelopt

Codex

codex plugin marketplace add https://github.com/NVIDIA/Model-Optimizer.git

Then open /plugins, select the modelopt marketplace, and install modelopt. Contributors can also use the skills directly from a checkout. See the agent tooling notes.

Top Contributors

Contributors

Happy optimizing!

S
Description
GitHub Trending: NVIDIA/Model-Optimizer
Readme Multiple Licenses
2.8 GiB
Languages
Python 97.7%
Shell 1%
Cuda 0.8%
Jinja 0.2%
C++ 0.2%