Repository navigation
Always ensure correct dtype for _keep_in_fp32_modules_strict - #50975
Conversation
There was a problem hiding this comment.
Model linter — first pass
transformers-mlinter found 1 item(s) in the model files this PR touches. These are structural conventions a maintainer would otherwise flag by hand.
This is automated and advisory — it does not block merging.
| rule | count | what it checks |
|---|---|---|
TRF055 |
1 | PreTrainedModel classes declare their config with a config: SomeConfig annotation, matched by __init__(config: SomeConfig); never config_class. |
1 item(s) outside this diff
src/transformers/models/voxtral/modular_voxtral.py:67TRF055 — TRF055: generated modeling_voxtral.py:257:VoxtralEncoder.__init__takesconfig: VoxtralConfigbut the class overridesconfig: VoxtralEncoderConfig. Make them match; add or updateconfig: VoxtralConfigin the class body if that is intended.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: afmoe, apertus1p5, axk1, axk2, bailing_hybrid, beam, deepseek_ocr2, deepseek_v2, deepseek_v3, deepseek_v32, deepseek_v4, dots1, dots3_note, ernie4_5_moe, ernie4_5_vl_moe, esmfold2 |
The sinks, the hyper-connections and the router biases are listed in `_keep_in_fp32_modules_strict`, but only `from_pretrained` enforces that list. A model built straight from a config got them in the default dtype, which the common test from #50975 now catches. They are created in float32 in their `__init__` instead.
vasqu
left a comment
There was a problem hiding this comment.
Not a fan of this tbh because now we need to keep track of this for all the keep fp32 flags no? It creates easy misses during model additions imo
- Rename `routed_expert_hidden_size` to `moe_hidden_size` (keeping a BC alias for published checkpoints) and update `FP8Experts` to resolve `hidden_dim` via `_first_attr(config, "moe_hidden_size", "hidden_size")`. - Inherit `HYV4FlashAttention` from `DeepseekV3Attention` using `config.per_layer_config[layer_idx]` and move `post_proj_norm` out of attention onto `HYV4FlashDecoderLayer.post_self_attn_layernorm` with a reversible `WeightRenaming` mapping. - Remove redundant `position_ids.expand(3, -1, -1)` inside `HYV4FlashRotaryEmbedding.forward`, split the latent-space MoE steps onto separate lines with a comment, and mark the `vision_config.model_type` redirect with `# BC:`. - Align with latest `main` (`huggingface#50379` `MultimodalMoeBaseModelOutputWithPast`, `huggingface#50975` fp32-strict parameter dtypes, `huggingface#50897` deprecated MoE TP plan entries). - Fix CI checks: prune `HYV4VL*` submodel names from `_no_split_modules` (TRF022/TRF068), add a minimal `test_processing_hy_v4_flash.py` subclassing `HYV4VLProcessorTest` (TRF038 without touching `utils/rules.toml`), and add the model contribution date to `hy_v4_flash.md`.
The sinks, the hyper-connections and the router biases are listed in `_keep_in_fp32_modules_strict`, but only `from_pretrained` enforces that list. A model built straight from a config got them in the default dtype, which the common test from #50975 now catches. They are created in float32 in their `__init__` instead.
The sinks, the hyper-connections and the router biases are listed in `_keep_in_fp32_modules_strict`, but only `from_pretrained` enforces that list. A model built straight from a config got them in the default dtype, which the common test from #50975 now catches. They are created in float32 in their `__init__` instead.
…huggingface#51067) huggingface#50975 keeps `_keep_in_fp32_modules_strict` params (incl. router `gate.weight`) in fp32 at load: - dots3_note: the bf16-only dtype check now expects fp32 for params matching `_keep_in_fp32_modules_strict` - axk1: tiny-axk1 stores router weights in fp32 (no longer rounded to bf16), update CUDA (8, 6) expected logits Co-authored-by: ydshieh <ydshieh@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The sinks, the hyper-connections and the router biases are listed in `_keep_in_fp32_modules_strict`, but only `from_pretrained` enforces that list. A model built straight from a config got them in the default dtype, which the common test from #50975 now catches. They are created in float32 in their `__init__` instead.
- Rename `routed_expert_hidden_size` to `moe_hidden_size` (keeping a BC alias for published checkpoints) and update `FP8Experts` to resolve `hidden_dim` via `_first_attr(config, "moe_hidden_size", "hidden_size")`. - Inherit `HYV4FlashAttention` from `DeepseekV3Attention` using `config.per_layer_config[layer_idx]` and move `post_proj_norm` out of attention onto `HYV4FlashDecoderLayer.post_self_attn_layernorm` with a reversible `WeightRenaming` mapping. - Remove redundant `position_ids.expand(3, -1, -1)` inside `HYV4FlashRotaryEmbedding.forward`, split the latent-space MoE steps onto separate lines with a comment, and mark the `vision_config.model_type` redirect with `# BC:`. - Align with latest `main` (`huggingface#50379` `MultimodalMoeBaseModelOutputWithPast`, `huggingface#50975` fp32-strict parameter dtypes, `huggingface#50897` deprecated MoE TP plan entries). - Fix CI checks: prune `HYV4VL*` submodel names from `_no_split_modules` (TRF022/TRF068), add a minimal `test_processing_hy_v4_flash.py` subclassing `HYV4VLProcessorTest` (TRF038 without touching `utils/rules.toml`), and add the model contribution date to `hy_v4_flash.md`.
The sinks, the hyper-connections and the router biases are listed in `_keep_in_fp32_modules_strict`, but only `from_pretrained` enforces that list. A model built straight from a config got them in the default dtype, which the common test from #50975 now catches. They are created in float32 in their `__init__` instead.
What does this PR do?
This PR makes sure that everywhere we a parameter/buffer/module inside
_keep_in_fp32_modules_strict, then that param/buffer/module must be hardcoded withtorch.float32inside the__init__during model construction. See also my comment here for context.If we do not do it, then initializing a model with
__init__orfrom_configwill NOT respect the dtype, which is wrong (onlyfrom_pretrainedwould respect it).It also adds
gate.weightinside_keep_in_fp32_modules_strictfor MANY moe models, where that weight is always upcasted to fp32 (so we want to keep it always in fp32 instead of always upcasting insideforward)