fix(speculative): deprecate shift_label rather than refuse it; say Domino acceptance cannot be measured

README's deprecation policy gives a removed parameter one release of
continued operation with warnings, and the Domino recipe shipped
`shift_label: true` from 0.46 to 0.48. Convert now drops a shift_label that
matches the variant's _label_shift with a FutureWarning (removal in 0.50)
and still refuses a contradicting one, which never took effect; it checks
before converting the model. Restore keeps dropping it unchecked.

Domino's AR refusal, the changelog and the skill sheet no longer point to a
serving engine: the export declares DFlashDraftModel, so vLLM would run the
backbone alone, one block position off. The forward docstring and the skill
sheet now also say eval loss and accuracy exclude the correction head.

test_deprecated_shift_label fails 6/6 on main, 3/6 with the previous
refusal, and 3/6 without the restore filter. DFlash-family unit tests:
318 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: h-guo18 <67671475+h-guo18@users.noreply.github.com>
This commit is contained in:
h-guo18
2026-11-08 11:18:53 +00:00
co-authored by Claude Opus 5.5
parent 39ffc25218
commit a944d85bb7
6 changed files with 67 additions and 32 deletions
+2 -2
View File
@@ -81,12 +81,12 @@ Changelog
- Layerwise-calibration resume (``checkpoint_dir``) now loads checkpoint files with ``weights_only=True``. A checkpoint directory written by an earlier release whose layer inputs hold objects other than tensors, plain containers or Hugging Face dynamic caches can no longer be resumed; recalibrate in a fresh directory, or disable checkpointing.
- ``export_hf_checkpoint`` now reads how a model is distributed from the plan recorded on it, and raises for an FSDP2-sharded model, or one in a multi-rank run, that carries none. ``load_pretrained`` and ``examples/hf_ptq/hf_ptq.py --use_fsdp2`` record it; for a model you distribute yourself (``fsdp2_wrap`` and ``parallel_load_and_prepare_fsdp2`` record none), or export from several ranks as a DDP script does, record one with ``modelopt.torch.utils.distributed.set_distribution_plan`` before calibrating or exporting it, e.g. ``DistributionPlan(world_size)`` when every rank holds the whole model.
- Streaming speculative-decoding training's vLLM connector (``modelopt.torch.speculative.plugins.rdma_hidden_states_connector``) now requires vLLM 0.22 or later. It is tested with vLLM 0.29 and later.
- ``dflash_architecture_config.shift_label`` is no longer accepted: the label alignment follows ``projector_type`` (DSpark and Domino predict the next token). Remove it from DFlash-family configs; checkpoints saved with it still load.
**Deprecations**
- ``modelopt.torch.export.copy_non_safetensor_files_from_ckpt`` is deprecated; use ``copy_non_model_files``.
- PyTorch 2.10 support is deprecated and will be dropped in a future release.
- ``dflash_architecture_config.shift_label`` is deprecated and will be removed in 0.50, since ``projector_type`` fixes the label alignment (DSpark and Domino predict the next token): remove it from DFlash-family configs. Until then a value matching ``projector_type`` is ignored with a warning and any other raises, as it never took effect; checkpoints saved with it still load.
**Bug Fixes**
@@ -111,7 +111,7 @@ Changelog
- Fix GPT-OSS draft training with pre-normalization teacher hidden states by enabling the target model's final normalization.
- Fix vanilla DSpark exports to use the Qwen3 DSpark architecture, head names and configuration expected by vLLM. Re-export existing training checkpoints to use this format.
- ``mtq.fold_weight`` now folds sequential weight quantizers (e.g. W4A8 INT4 + FP8 weights) into the weights; it used to leave them unfolded and enabled.
- DSpark and Domino exports now write the ``shift_label``, ``markov_rank`` and other head fields they were trained with. Domino's HF AR validation (``pseudo_speculative_generate``) now raises instead of scoring the backbone one block position off; evaluate Domino drafters in a serving engine.
- DSpark and Domino exports now write the ``shift_label``, ``markov_rank`` and other head fields they were trained with. Domino's HF AR validation (``pseudo_speculative_generate``) now raises instead of scoring the backbone one block position off; Domino acceptance cannot be measured until a runtime applies its correction head.
- Fix ONNX quantization placing a per-tensor Q/DQ pair on a rank-0 (scalar) constant input, which TensorRT's ONNX parser rejects (``convertAxis`` asserts the quantization axis lies in ``[0, nbDims]`` but ``nbDims == 0``). Rank-0 constant operands are now kept unquantized in the int8, fp8, and autotune export paths; the existing single-element Mul/Div/Pad stripping stays gated under ``target_dla``.
- Fix the diffusers skip-softmax HF export to emit the schema TensorRT-LLM VisualGen loads (``threshold_scale_factor.coefficients`` and a scalar ``target_sparsity``). Re-export checkpoints that failed to load.
- Fix PTQ of native Transformers FP8 experts to apply source weight scales during calibration and export. Re-quantize affected checkpoints from the original FP8 source.
+37 -15
View File
@@ -15,6 +15,8 @@
"""DFlash conversion/restore utilities."""
import warnings
from torch import nn
from modelopt.torch.opt.conversion import ModelLikeModule
@@ -58,27 +60,43 @@ _REGISTRY_BY_PROJECTOR_TYPE = {
"lilicorr": LiLiCorrDMRegistry,
}
# Keys dflash_architecture_config once accepted, and why each is gone. Convert refuses them;
# restore drops them, since checkpoints saved before carry them.
_RETIRED_ARCHITECTURE_KEYS = {
# Deprecated dflash_architecture_config keys (removed in 0.50), each with the model attribute
# that now fixes its value, and why.
_DEPRECATED_ARCHITECTURE_KEYS = {
"shift_label": (
"projector_type fixes the label alignment (dspark and domino predict the token at "
"anchor + k + 1, the others the token at anchor + k)"
"_label_shift",
(
"projector_type fixes the label alignment (dspark and domino predict the token at "
"anchor + k + 1, the others the token at anchor + k)"
),
),
}
def _drop_deprecated_keys(arch_config: dict, dm_cls: type) -> dict:
"""Return ``arch_config`` without the deprecated keys, warning on each value ``dm_cls`` matches.
A value ``dm_cls`` contradicts raises instead: it never took effect, so the run would not
train what its config says.
"""
for key in sorted(_DEPRECATED_ARCHITECTURE_KEYS.keys() & arch_config.keys()):
attr, reason = _DEPRECATED_ARCHITECTURE_KEYS[key]
if arch_config[key] != getattr(dm_cls, attr):
raise ValueError(
f"dflash_architecture_config.{key}={arch_config[key]!r} contradicts the model: "
f"{reason}. Remove it."
)
warnings.warn(
f"dflash_architecture_config.{key} is deprecated and will be removed in 0.50: "
f"{reason}. Remove it.",
FutureWarning,
stacklevel=2,
)
return {k: v for k, v in arch_config.items() if k not in _DEPRECATED_ARCHITECTURE_KEYS}
def convert_to_dflash_model(model: nn.Module, config: DFlashConfig) -> ConvertReturnType:
"""Convert the model to a DFlash (or Domino) model as per `config`."""
retired = sorted(_RETIRED_ARCHITECTURE_KEYS.keys() & config.dflash_architecture_config.keys())
if retired:
raise ValueError(
"\n".join(
f"dflash_architecture_config.{key} is no longer a setting: "
f"{_RETIRED_ARCHITECTURE_KEYS[key]}. Remove it."
for key in retired
)
)
model = model.init_modellike() if isinstance(model, ModelLikeModule) else model
# merge custom config with default config (lazy import to avoid circular)
@@ -97,6 +115,9 @@ def convert_to_dflash_model(model: nn.Module, config: DFlashConfig) -> ConvertRe
)
registry.register_subclass(type(model), "base_model_class")
config.dflash_architecture_config = _drop_deprecated_keys(
config.dflash_architecture_config, registry[type(model)]
)
dflash_model = registry.convert(model)
dflash_model.modify(config)
@@ -113,9 +134,10 @@ def restore_dflash_model(
# Warm start is a one-time training-time init; the restored weights would overwrite it
# anyway, and replaying it on the meta device would raise.
config = config.model_copy(update={"dflash_init_checkpoint": None})
# Unchecked: checkpoints saved before the deprecation carry values that never took effect.
config.dflash_architecture_config = {
k: v
for k, v in config.dflash_architecture_config.items()
if k not in _RETIRED_ARCHITECTURE_KEYS
if k not in _DEPRECATED_ARCHITECTURE_KEYS
}
return convert_to_dflash_model(model, config)[0]
@@ -260,7 +260,8 @@ class HFDominoModel(HFDFlashModel):
Mirrors ``HFDFlashModel.forward`` for data preparation (reusing the inherited
anchor/noise/mask/position helpers), then applies the Domino head and the
two-term loss. Eval/offline-eval is delegated to the DFlash parent.
two-term loss. Eval/offline-eval is delegated to the DFlash parent, so eval loss and
accuracy exclude the correction head.
"""
if not self.training:
return super().forward(
@@ -357,8 +358,9 @@ class HFDominoModel(HFDFlashModel):
def pseudo_speculative_generate(self, input_ids, steps=1):
"""Refused: DFlash's decode would draft with the backbone alone, one block position off."""
raise NotImplementedError(
"Domino has no HF AR validation (pseudo_speculative_generate). Set ar_validate_steps "
"to 0 and measure acceptance on the exported drafter in a serving engine."
"Domino acceptance cannot be measured until a runtime applies its correction head: "
"the inherited DFlash decode would draft with the backbone alone, one block position "
"off. Set ar_validate_steps to 0."
)
@@ -86,9 +86,9 @@ export is the whole in-pipeline signal.
## Quality gate
**Domino has no HF AR validation.** `pseudo_speculative_generate` raises for Domino, so
keep the recipe's `ar_validate_steps: 0` and measure acceptance on the exported drafter
in a serving engine.
**Domino has no acceptance evaluation yet.** `pseudo_speculative_generate` raises and no
runtime applies the correction head, so keep the recipe's `ar_validate_steps: 0`. Eval
loss and accuracy (`do_eval`, off in the recipe) exclude the head too.
The training-regression gate from `dflash.md` applies and the Qwen3-8B example sets
it: `MAX_FINAL_LOSS=5.0`, `MIN_FINAL_ACC=0.15`, checked by `check_regression.py`
@@ -105,9 +105,9 @@ failures (`seq_len` divisibility, offline eval, mask token, chat template) are i
| Error pattern | Root cause | Fix |
| --- | --- | --- |
| `Domino (projector_type='domino') requires ['emb_dim', 'gru_hidden_dim'] in dflash_architecture_config` | GRU head dims missing | Set both in `dflash_architecture_config` |
| `dflash_architecture_config.shift_label is no longer a setting` | `shift_label` in the config (the old recipe set it) | Remove it; Domino always trains next-token alignment |
| `dflash_architecture_config.shift_label` deprecation warning, or `... contradicts the model` | `shift_label` in the config (the old recipe set it) | Remove it; Domino always trains next-token alignment |
| `pure_draft_prefix_len must be in [0, N] (block_size=B), got X` | Prefix length >= block size | Lower it below `block_size` |
| `DominoLambdaCallback: state.max_steps unset (<=0); lambda_base curriculum disabled` (warning) | `training.max_steps` not set | Set `training.max_steps`, else the curriculum never runs |
| `Domino has no HF AR validation (pseudo_speculative_generate)` | `ar_validate.py`, or `ar_validate_steps > 0` (training logs `AR validation not available.`) | Evaluate the exported drafter in a serving engine |
| `Domino acceptance cannot be measured until a runtime applies its correction head` | `ar_validate.py`, or `ar_validate_steps > 0` (training logs `AR validation not available.`) | Keep `ar_validate_steps: 0`; there is no Domino acceptance evaluation yet |
| DDP error about unused parameters | `ddp_find_unused_parameters` turned off | Keep it `true` |
| Draft trains but quality is poor | Draft dims left at `Qwen3Config` defaults instead of matching the base | Set the GQA/FFN dims explicitly |
@@ -151,7 +151,7 @@ failures (`seq_len` divisibility, offline eval, mask token, chat template) are i
| `DSpark (projector_type='dspark') requires 'markov_rank' (> 0) in dflash_architecture_config` | Markov head dimension missing | Set `dflash_architecture_config.markov_rank` |
| `DSpark requires markov_rank > 0, got N` | Non-positive value | Set a positive rank |
| `Unsupported markov_head_type: '...'. Expected 'vanilla', 'gated' or 'rnn'` | Typo or unsupported head | Use one of the three |
| `dflash_architecture_config.shift_label is no longer a setting` | `shift_label` in the config | Remove it; DSpark always trains next-token alignment |
| `dflash_architecture_config.shift_label` deprecation warning, or `... contradicts the model` | `shift_label` in the config | Remove it; DSpark always trains next-token alignment |
| `dflash_confidence_head_alpha > 0 but the confidence head was not built` | Loss term enabled without the head | Set `dflash_architecture_config.use_confidence_head=true`, or set the alpha to 0 |
| `DSpark offline model cannot run AR validation / pseudo_speculative_generate` | Offline/streaming conversion deleted base layers | Keep `estimate_ar=false` and `ar_validate_steps=0`; evaluate after export |
| Draft trains but acceptance length is poor | Draft dims left at defaults instead of matching the base | Set the GQA/FFN dims explicitly (see *Per-model adjustments*) |
@@ -1607,11 +1607,12 @@ def test_a_step_with_nothing_to_train_reaches_every_draft_parameter(head, draft_
],
ids=["dflash", "dspark", "domino"],
)
def test_shift_label_is_refused_at_convert_but_restores(head_fields, shift_label):
"""projector_type fixes the label alignment, so a config naming it is refused at convert.
def test_deprecated_shift_label(head_fields, shift_label):
"""projector_type fixes the label alignment, so convert drops a shift_label matching it with
a warning and refuses any other, which never took effect.
Restore drops it instead: DSpark used to accept the field and ignore it in training, and
the Domino recipe set it, so checkpoints carry it in their modelopt_state.
Restore drops either unchecked: DSpark used to accept the field and ignore it in training,
and the Domino recipe set it, so checkpoints carry it in their modelopt_state.
"""
config = get_dflash_config()
config["dflash_architecture_config"].update(head_fields)
@@ -1625,8 +1626,18 @@ def test_shift_label_is_refused_at_convert_but_restores(head_fields, shift_label
assert restored._label_shift == model._label_shift
config["dflash_architecture_config"]["shift_label"] = shift_label
with pytest.raises(ValueError, match="shift_label is no longer a setting"):
mtsp.convert(get_tiny_llama(num_hidden_layers=4), [("dflash", config)])
legacy = get_tiny_llama(num_hidden_layers=4)
if shift_label != bool(model._label_shift):
base_cls = type(legacy)
with pytest.raises(ValueError, match="shift_label"):
mtsp.convert(legacy, [("dflash", config)])
assert type(legacy) is base_cls # refused before converting
return
with pytest.warns(FutureWarning, match="shift_label"):
mtsp.convert(legacy, [("dflash", config)])
assert legacy._label_shift == model._label_shift
legacy_config = mto.modelopt_state(legacy)["modelopt_state_dict"][0][1]["config"]
assert "shift_label" not in legacy_config["dflash_architecture_config"]
class TestTeacherLogits: