Repository navigation
quantize on config instead of on model - #3032
Merged
Merged
Conversation
[ghstack-poisoned]
acisseJZhong
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
April 20, 2026 19:59
acisseJZhong
marked this pull request as draft
April 20, 2026 19:59
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
## Summary Apply quantization converters on model configs instead of on built models. Previously, the trainer built the model first, then walked the entire module tree to swap `nn.Linear` with `Float8Linear`. This required a save/restore dance (`capture_module_attrs` / `inject_module_protocol` / `verify_module_protocol`) because `Float8Linear.from_float` creates new module instances, losing `_param_init` and the `Linear`/`Module` protocol. Now, converters inject a `_convert_fn` into matching configs before `build()`. Each module is converted immediately after construction inside `Module.Config.build()`, which controls the full sequence: create → convert → transfer `_param_init`. Since conversion happens *during* build rather than *after*, the external save/restore is no longer needed — `build()` holds `_param_init` across the conversion inline. **Changes:** - Add `Configurable.Config.walk()` — generic config tree traversal yielding `(fqn, config)` pairs - Add `Module.Config._convert_fn` — optional callback applied in `build()` after construction - Add `ModelConverter.convert_config()` — config-level conversion interface - `Float8LinearConverter` / `Float8GroupedMMConverter` / `MXFP8Converter`: conversion logic moved from `convert(model)` to `convert_config(model_config)` - `module_filter_fn` now accepts `Linear.Config` in addition to `nn.Module` - Trainer calls `convert_config(model_config)` before `build()`, then `convert(model)` for any remaining model-level converters ## Test plan - [ ] `pytest tests/unit_tests/test_model_converter.py` — passes - [ ] `pytest tests/unit_tests/test_linear.py` — passes - [ ] Full unit test suite (219 passed, 0 new failures) - [ ] Verify float8 training produces identical loss with `--debug.seed=42 --debug.deterministic` before vs after [ghstack-poisoned]
acisseJZhong
marked this pull request as ready for review
April 20, 2026 22:37
## Summary Apply quantization converters on model configs instead of on built models. Previously, the trainer built the model first, then walked the entire module tree to swap `nn.Linear` with `Float8Linear`. This required a save/restore dance (`capture_module_attrs` / `inject_module_protocol` / `verify_module_protocol`) because `Float8Linear.from_float` creates new module instances, losing `_param_init` and the `Linear`/`Module` protocol. Now, converters inject a `_convert_fn` into matching configs before `build()`. Each module is converted immediately after construction inside `Module.Config.build()`, which controls the full sequence: create → convert → transfer `_param_init`. Since conversion happens *during* build rather than *after*, the external save/restore is no longer needed — `build()` holds `_param_init` across the conversion inline. Addresses #2960 (comment) (but not #2981). **Changes:** - Add `Configurable.Config.walk()` — generic config tree traversal yielding `(fqn, config)` pairs - Add `Module.Config._convert_fn` — optional callback applied in `build()` after construction - Add `ModelConverter.convert_config()` — config-level conversion interface - `Float8LinearConverter` / `Float8GroupedMMConverter` / `MXFP8Converter`: conversion logic moved from `convert(model)` to `convert_config(model_config)` - `module_filter_fn` now accepts `Linear.Config` in addition to `nn.Module` - Trainer calls `convert_config(model_config)` before `build()`, then `convert(model)` for any remaining model-level converters - `TorchAOTokenDispatcher` selection moved from `make_token_dispatcher_config` to the quantization converters' `convert_config()`, so the model config always uses standard `AllToAllTokenDispatcher` and the converter swaps it when needed ## Test plan - [ ] `pytest tests/unit_tests/test_model_converter.py` — passes - [ ] `pytest tests/unit_tests/test_linear.py` — passes - [ ] Full unit test suite (219 passed, 0 new failures) - [ ] Verify float8 training produces identical loss with `--debug.seed=42 --debug.deterministic` before vs after [ghstack-poisoned]
4 tasks
| matching the target FQNs so that ``build()`` applies dynamic | ||
| MXFP8 quantization on grouped GEMM operations. | ||
| matching the target FQNs so that ``build()`` replaces instances of | ||
| nn.Parameter with ScaledGroupedMMTensor. This will use low precision grouped |
Contributor
There was a problem hiding this comment.
ScaledGroupedMMTensor
it's called MXFP8TrainingWeightWrapperTensor now
## Summary Apply quantization converters on model configs instead of on built models. Previously, the trainer built the model first, then walked the entire module tree to swap `nn.Linear` with `Float8Linear`. This required a save/restore dance (`capture_module_attrs` / `inject_module_protocol` / `verify_module_protocol`) because `Float8Linear.from_float` creates new module instances, losing `_param_init` and the `Linear`/`Module` protocol. Now, converters inject a `_convert_fn` into matching configs before `build()`. Each module is converted immediately after construction inside `Module.Config.build()`, which controls the full sequence: create → convert → transfer `_param_init`. Since conversion happens *during* build rather than *after*, the external save/restore is no longer needed — `build()` holds `_param_init` across the conversion inline. Addresses #2960 (comment) (but not #2981). **Changes:** - Add `Configurable.Config.walk()` — generic config tree traversal yielding `(fqn, config)` pairs - Add `Module.Config._convert_fn` — optional callback applied in `build()` after construction - Add `ModelConverter.convert_config()` — config-level conversion interface - `Float8LinearConverter` / `Float8GroupedMMConverter` / `MXFP8Converter`: conversion logic moved from `convert(model)` to `convert_config(model_config)` - `module_filter_fn` now accepts `Linear.Config` in addition to `nn.Module` - Trainer calls `convert_config(model_config)` before `build()`, then `convert(model)` for any remaining model-level converters - `TorchAOTokenDispatcher` selection moved from `make_token_dispatcher_config` to the quantization converters' `convert_config()`, so the model config always uses standard `AllToAllTokenDispatcher` and the converter swaps it when needed ## Test plan - [ ] `pytest tests/unit_tests/test_model_converter.py` — passes - [ ] `pytest tests/unit_tests/test_linear.py` — passes - [ ] Full unit test suite (219 passed, 0 new failures) - [ ] Verify float8 training produces identical loss with `--debug.seed=42 --debug.deterministic` before vs after [ghstack-poisoned]
## Summary Apply quantization converters on model configs instead of on built models. Previously, the trainer built the model first, then walked the entire module tree to swap `nn.Linear` with `Float8Linear`. This required a save/restore dance (`capture_module_attrs` / `inject_module_protocol` / `verify_module_protocol`) because `Float8Linear.from_float` creates new module instances, losing `_param_init` and the `Linear`/`Module` protocol. Now, converters inject a `_convert_fn` into matching configs before `build()`. Each module is converted immediately after construction inside `Module.Config.build()`, which controls the full sequence: create → convert → transfer `_param_init`. Since conversion happens *during* build rather than *after*, the external save/restore is no longer needed — `build()` holds `_param_init` across the conversion inline. Addresses #2960 (comment) (but not #2981). **Changes:** - Add `Configurable.Config.walk()` — generic config tree traversal yielding `(fqn, config)` pairs - Add `Module.Config._convert_fn` — optional callback applied in `build()` after construction - Add `ModelConverter.convert_config()` — config-level conversion interface - `Float8LinearConverter` / `Float8GroupedMMConverter` / `MXFP8Converter`: conversion logic moved from `convert(model)` to `convert_config(model_config)` - `module_filter_fn` now accepts `Linear.Config` in addition to `nn.Module` - Trainer calls `convert_config(model_config)` before `build()`, then `convert(model)` for any remaining model-level converters - `TorchAOTokenDispatcher` selection moved from `make_token_dispatcher_config` to the quantization converters' `convert_config()`, so the model config always uses standard `AllToAllTokenDispatcher` and the converter swaps it when needed ## Test plan - [ ] `pytest tests/unit_tests/test_model_converter.py` — passes - [ ] `pytest tests/unit_tests/test_linear.py` — passes - [ ] Full unit test suite (219 passed, 0 new failures) - [ ] Verify float8 training produces identical loss with `--debug.seed=42 --debug.deterministic` before vs after [ghstack-poisoned]
## Summary Apply quantization converters on model configs instead of on built models. Previously, the trainer built the model first, then walked the entire module tree to swap `nn.Linear` with `Float8Linear`. This required a save/restore dance (`capture_module_attrs` / `inject_module_protocol` / `verify_module_protocol`) because `Float8Linear.from_float` creates new module instances, losing `_param_init` and the `Linear`/`Module` protocol. Now, converters inject a `_convert_fn` into matching configs before `build()`. Each module is converted immediately after construction inside `Module.Config.build()`, which controls the full sequence: create → convert → transfer `_param_init`. Since conversion happens *during* build rather than *after*, the external save/restore is no longer needed — `build()` holds `_param_init` across the conversion inline. Addresses #2960 (comment) (but not #2981). **Changes:** - Add `Configurable.Config.walk()` — generic config tree traversal yielding `(fqn, config)` pairs - Add `Module.Config._convert_fn` — optional callback applied in `build()` after construction - Add `ModelConverter.convert_config()` — config-level conversion interface - `Float8LinearConverter` / `Float8GroupedMMConverter` / `MXFP8Converter`: conversion logic moved from `convert(model)` to `convert_config(model_config)` - `module_filter_fn` now accepts `Linear.Config` in addition to `nn.Module` - Trainer calls `convert_config(model_config)` before `build()`, then `convert(model)` for any remaining model-level converters - `TorchAOTokenDispatcher` selection moved from `make_token_dispatcher_config` to the quantization converters' `convert_config()`, so the model config always uses standard `AllToAllTokenDispatcher` and the converter swaps it when needed ## Test plan - [ ] `pytest tests/unit_tests/test_model_converter.py` — passes - [ ] `pytest tests/unit_tests/test_linear.py` — passes - [ ] Full unit test suite (219 passed, 0 new failures) - [ ] Verify float8 training produces identical loss before vs after: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
acisseJZhong
requested review from
SherlockNoMad,
aditvenk,
xmfan and
yiming0416
as code owners
April 21, 2026 03:59
Fixes #2981 ## Summary Apply quantization at model config construction time by swapping config types, instead of post-build model mutation. Previously, the trainer built the model, then walked the module tree to swap `nn.Linear` with `Float8Linear`, requiring save/restore of `_param_init` and the `Module` protocol. Now, quantization is a config pass in `model_registry()`: ```python model_registry("405B", quantization=[ Float8LinearQuant(filter_fqns=["output"]), Float8MoEQuant(), ]) ``` Each `QuantizationConfig` subclass calls a standalone function that walks the config tree: - `convert_to_float8()` swaps `Linear.Config` → `Float8LinearConfig` (whose `build()` produces `Float8Linear` directly) - `convert_moe_to_float8()` / `convert_moe_to_mxfp8()` walk `GroupedExperts.Config` by type and set `_convert_fn` **Removed:** - `ModelConverter`, `ModelConvertersContainer`, `Float8LinearConverter`, `Float8GroupedMMConverter`, `MXFP8Converter`, `QuantizationConverter` classes and `model_converter.py`, `float8.py`, `mx.py` files - `enable_fsdp_float8_all_gather`, `precompute_float8_dynamic_scale_for_fsdp`, `enable_float8_tensorwise_tp` - `model_converters` from `Trainer.Config` and all parallelize functions - `parallel_dims` dependency from converters **Added:** - `QuantizationConfig` hierarchy (`Float8LinearQuant`, `Float8MoEQuant`, `MXFP8MoEQuant`, `MXFP8Quant`) - `Float8LinearConfig(Linear.Config)` — builds `Float8Linear` directly - `Configurable.Config.walk()` yields `(fqn, config, parent, attr)` for config tree traversal and replacement - `has_quantization()` — type-based check - Token dispatcher swap and `pad_multiple` handled at config time ## Test plan - [ ] Full unit test suite passes (219 passed) - [ ] Verify float8 training produces identical loss: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
tianyu-l
reviewed
Apr 27, 2026
Contributor
There was a problem hiding this comment.
can we move these docs to be under components/quantization? The long term goal is to move all docs to be close to where relevant.
Fixes #2981 ## Summary Apply quantization at model config construction time by swapping config types, instead of post-build model mutation. Previously, the trainer built the model, then walked the module tree to swap `nn.Linear` with `Float8Linear`, requiring save/restore of `_param_init` and the `Module` protocol. Now, quantization is a config pass in `model_registry()`: ```python model_registry("405B", quantization=[ Float8LinearQuant(filter_fqns=["output"]), Float8MoEQuant(), ]) ``` Each `QuantizationConfig` subclass calls a standalone function that walks the config tree: - `convert_to_float8()` swaps `Linear.Config` → `Float8LinearConfig` (whose `build()` produces `Float8Linear` directly) - `convert_moe_to_float8()` / `convert_moe_to_mxfp8()` walk `GroupedExperts.Config` by type and set `_convert_fn` **Removed:** - `ModelConverter`, `ModelConvertersContainer`, `Float8LinearConverter`, `Float8GroupedMMConverter`, `MXFP8Converter`, `QuantizationConverter` classes and `model_converter.py`, `float8.py`, `mx.py` files - `enable_fsdp_float8_all_gather`, `precompute_float8_dynamic_scale_for_fsdp`, `enable_float8_tensorwise_tp` - `model_converters` from `Trainer.Config` and all parallelize functions - `parallel_dims` dependency from converters **Added:** - `QuantizationConfig` hierarchy (`Float8LinearQuant`, `Float8MoEQuant`, `MXFP8MoEQuant`, `MXFP8Quant`) - `Float8LinearConfig(Linear.Config)` — builds `Float8Linear` directly - `Configurable.Config.walk()` yields `(fqn, config, parent, attr)` for config tree traversal and replacement - `has_quantization()` — type-based check - Token dispatcher swap and `pad_multiple` handled at config time ## Test plan - [ ] Full unit test suite passes (219 passed) - [ ] Verify float8 training produces identical loss: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
acisseJZhong
commented
Apr 27, 2026
Contributor
Author
|
auto parallel tests failing due to meta-pytorch/autoparallel#415, update in #3114 graph trainer issue was known: same as https://github.com/pytorch/torchtitan/actions/runs/25016687204/job/73266229364 |
Fixes #2981 ## Summary Apply quantization at model config construction time by swapping config types, instead of post-build model mutation. Previously, the trainer built the model, then walked the module tree to swap `nn.Linear` with `Float8Linear`, requiring save/restore of `_param_init` and the `Module` protocol. Now, quantization is a config pass in `model_registry()`: ```python model_registry("405B", quantization=[ Float8LinearQuant(filter_fqns=["output"]), Float8MoEQuant(), ]) ``` Each `QuantizationConfig` subclass calls a standalone function that walks the config tree: - `convert_to_float8()` swaps `Linear.Config` → `Float8LinearConfig` (whose `build()` produces `Float8Linear` directly) - `convert_moe_to_float8()` / `convert_moe_to_mxfp8()` walk `GroupedExperts.Config` by type and set `_convert_fn` **Removed:** - `ModelConverter`, `ModelConvertersContainer`, `Float8LinearConverter`, `Float8GroupedMMConverter`, `MXFP8Converter`, `QuantizationConverter` classes and `model_converter.py`, `float8.py`, `mx.py` files - `enable_fsdp_float8_all_gather`, `precompute_float8_dynamic_scale_for_fsdp`, `enable_float8_tensorwise_tp` - `model_converters` from `Trainer.Config` and all parallelize functions - `parallel_dims` dependency from converters **Added:** - `QuantizationConfig` hierarchy (`Float8LinearQuant`, `Float8MoEQuant`, `MXFP8MoEQuant`, `MXFP8Quant`) - `Float8LinearConfig(Linear.Config)` — builds `Float8Linear` directly - `Configurable.Config.walk()` yields `(fqn, config, parent, attr)` for config tree traversal and replacement - `has_quantization()` — type-based check - Token dispatcher swap and `pad_multiple` handled at config time ## Test plan - [ ] Full unit test suite passes (219 passed) - [ ] Verify float8 training produces identical loss: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
Fixes #2981 ## Summary Apply quantization at model config construction time by swapping config types, instead of post-build model mutation. Previously, the trainer built the model, then walked the module tree to swap `nn.Linear` with `Float8Linear`, requiring save/restore of `_param_init` and the `Module` protocol. Now, quantization is a config pass in `model_registry()`: ```python model_registry("405B", quantization=[ Float8LinearQuant(filter_fqns=["output"]), Float8MoEQuant(), ]) ``` Each `QuantizationConfig` subclass calls a standalone function that walks the config tree: - `convert_to_float8()` swaps `Linear.Config` → `Float8LinearConfig` (whose `build()` produces `Float8Linear` directly) - `convert_moe_to_float8()` / `convert_moe_to_mxfp8()` walk `GroupedExperts.Config` by type and set `_convert_fn` **Removed:** - `ModelConverter`, `ModelConvertersContainer`, `Float8LinearConverter`, `Float8GroupedMMConverter`, `MXFP8Converter`, `QuantizationConverter` classes and `model_converter.py`, `float8.py`, `mx.py` files - `enable_fsdp_float8_all_gather`, `precompute_float8_dynamic_scale_for_fsdp`, `enable_float8_tensorwise_tp` - `model_converters` from `Trainer.Config` and all parallelize functions - `parallel_dims` dependency from converters **Added:** - `QuantizationConfig` hierarchy (`Float8LinearQuant`, `Float8MoEQuant`, `MXFP8MoEQuant`, `MXFP8Quant`) - `Float8LinearConfig(Linear.Config)` — builds `Float8Linear` directly - `Configurable.Config.walk()` yields `(fqn, config, parent, attr)` for config tree traversal and replacement - `has_quantization()` — type-based check - Token dispatcher swap and `pad_multiple` handled at config time ## Test plan - [ ] Full unit test suite passes (219 passed) - [ ] Verify float8 training produces identical loss: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
Fixes #2981 ## Summary Apply quantization at model config construction time by swapping config types, instead of post-build model mutation. Previously, the trainer built the model, then walked the module tree to swap `nn.Linear` with `Float8Linear`, requiring save/restore of `_param_init` and the `Module` protocol. Now, quantization is a config pass in `model_registry()`: ```python model_registry("405B", quantization=[ Float8LinearQuant(filter_fqns=["output"]), Float8MoEQuant(), ]) ``` Each `QuantizationConfig` subclass calls a standalone function that walks the config tree: - `convert_to_float8()` swaps `Linear.Config` → `Float8LinearConfig` (whose `build()` produces `Float8Linear` directly) - `convert_moe_to_float8()` / `convert_moe_to_mxfp8()` walk `GroupedExperts.Config` by type and set `_convert_fn` **Removed:** - `ModelConverter`, `ModelConvertersContainer`, `Float8LinearConverter`, `Float8GroupedMMConverter`, `MXFP8Converter`, `QuantizationConverter` classes and `model_converter.py`, `float8.py`, `mx.py` files - `enable_fsdp_float8_all_gather`, `precompute_float8_dynamic_scale_for_fsdp`, `enable_float8_tensorwise_tp` - `model_converters` from `Trainer.Config` and all parallelize functions - `parallel_dims` dependency from converters **Added:** - `QuantizationConfig` hierarchy (`Float8LinearQuant`, `Float8MoEQuant`, `MXFP8MoEQuant`, `MXFP8Quant`) - `Float8LinearConfig(Linear.Config)` — builds `Float8Linear` directly - `Configurable.Config.walk()` yields `(fqn, config, parent, attr)` for config tree traversal and replacement - `has_quantization()` — type-based check - Token dispatcher swap and `pad_multiple` handled at config time ## Test plan - [ ] Full unit test suite passes (219 passed) - [ ] Verify float8 training produces identical loss: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
Fixes #2981 ## Summary Apply quantization at model config construction time by swapping config types, instead of post-build model mutation. Previously, the trainer built the model, then walked the module tree to swap `nn.Linear` with `Float8Linear`, requiring save/restore of `_param_init` and the `Module` protocol. Now, quantization is a config pass in `model_registry()`: ```python model_registry("405B", quantization=[ Float8LinearQuant(filter_fqns=["output"]), Float8MoEQuant(), ]) ``` Each `QuantizationConfig` subclass calls a standalone function that walks the config tree: - `convert_to_float8()` swaps `Linear.Config` → `Float8LinearConfig` (whose `build()` produces `Float8Linear` directly) - `convert_moe_to_float8()` / `convert_moe_to_mxfp8()` walk `GroupedExperts.Config` by type and set `_convert_fn` **Removed:** - `ModelConverter`, `ModelConvertersContainer`, `Float8LinearConverter`, `Float8GroupedMMConverter`, `MXFP8Converter`, `QuantizationConverter` classes and `model_converter.py`, `float8.py`, `mx.py` files - `enable_fsdp_float8_all_gather`, `precompute_float8_dynamic_scale_for_fsdp`, `enable_float8_tensorwise_tp` - `model_converters` from `Trainer.Config` and all parallelize functions - `parallel_dims` dependency from converters **Added:** - `QuantizationConfig` hierarchy (`Float8LinearQuant`, `Float8MoEQuant`, `MXFP8MoEQuant`, `MXFP8Quant`) - `Float8LinearConfig(Linear.Config)` — builds `Float8Linear` directly - `Configurable.Config.walk()` yields `(fqn, config, parent, attr)` for config tree traversal and replacement - `has_quantization()` — type-based check - Token dispatcher swap and `pad_multiple` handled at config time ## Test plan - [ ] Full unit test suite passes (219 passed) - [ ] Verify float8 training produces identical loss: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
Fixes #2981 ## Summary Apply quantization at model config construction time by swapping config types, instead of post-build model mutation. Previously, the trainer built the model, then walked the module tree to swap `nn.Linear` with `Float8Linear`, requiring save/restore of `_param_init` and the `Module` protocol. Now, quantization is a config pass in `model_registry()`: ```python model_registry("405B", quantization=[ Float8LinearQuant(filter_fqns=["output"]), Float8MoEQuant(), ]) ``` Each `QuantizationConfig` subclass calls a standalone function that walks the config tree: - `convert_to_float8()` swaps `Linear.Config` → `Float8LinearConfig` (whose `build()` produces `Float8Linear` directly) - `convert_moe_to_float8()` / `convert_moe_to_mxfp8()` walk `GroupedExperts.Config` by type and set `_convert_fn` **Removed:** - `ModelConverter`, `ModelConvertersContainer`, `Float8LinearConverter`, `Float8GroupedMMConverter`, `MXFP8Converter`, `QuantizationConverter` classes and `model_converter.py`, `float8.py`, `mx.py` files - `enable_fsdp_float8_all_gather`, `precompute_float8_dynamic_scale_for_fsdp`, `enable_float8_tensorwise_tp` - `model_converters` from `Trainer.Config` and all parallelize functions - `parallel_dims` dependency from converters **Added:** - `QuantizationConfig` hierarchy (`Float8LinearQuant`, `Float8MoEQuant`, `MXFP8MoEQuant`, `MXFP8Quant`) - `Float8LinearConfig(Linear.Config)` — builds `Float8Linear` directly - `Configurable.Config.walk()` yields `(fqn, config, parent, attr)` for config tree traversal and replacement - `has_quantization()` — type-based check - Token dispatcher swap and `pad_multiple` handled at config time ## Test plan - [ ] Full unit test suite passes (219 passed) - [ ] Verify float8 training produces identical loss: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
Fixes #2981 ## Summary Apply quantization at model config construction time by swapping config types, instead of post-build model mutation. Previously, the trainer built the model, then walked the module tree to swap `nn.Linear` with `Float8Linear`, requiring save/restore of `_param_init` and the `Module` protocol. Now, quantization is a config pass in `model_registry()`: ```python model_registry("405B", quantization=[ Float8LinearQuant(filter_fqns=["output"]), Float8MoEQuant(), ]) ``` Each `QuantizationConfig` subclass calls a standalone function that walks the config tree: - `convert_to_float8()` swaps `Linear.Config` → `Float8LinearConfig` (whose `build()` produces `Float8Linear` directly) - `convert_moe_to_float8()` / `convert_moe_to_mxfp8()` walk `GroupedExperts.Config` by type and set `_convert_fn` **Removed:** - `ModelConverter`, `ModelConvertersContainer`, `Float8LinearConverter`, `Float8GroupedMMConverter`, `MXFP8Converter`, `QuantizationConverter` classes and `model_converter.py`, `float8.py`, `mx.py` files - `enable_fsdp_float8_all_gather`, `precompute_float8_dynamic_scale_for_fsdp`, `enable_float8_tensorwise_tp` - `model_converters` from `Trainer.Config` and all parallelize functions - `parallel_dims` dependency from converters **Added:** - `QuantizationConfig` hierarchy (`Float8LinearQuant`, `Float8MoEQuant`, `MXFP8MoEQuant`, `MXFP8Quant`) - `Float8LinearConfig(Linear.Config)` — builds `Float8Linear` directly - `Configurable.Config.walk()` yields `(fqn, config, parent, attr)` for config tree traversal and replacement - `has_quantization()` — type-based check - Token dispatcher swap and `pad_multiple` handled at config time ## Test plan - [ ] Full unit test suite passes (219 passed) - [ ] Verify float8 training produces identical loss: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
Fixes #2981 ## Summary Apply quantization at model config construction time by swapping config types, instead of post-build model mutation. Previously, the trainer built the model, then walked the module tree to swap `nn.Linear` with `Float8Linear`, requiring save/restore of `_param_init` and the `Module` protocol. Now, quantization is a config pass in `model_registry()`: ```python model_registry("405B", quantization=[ Float8LinearQuant(filter_fqns=["output"]), Float8MoEQuant(), ]) ``` Each `QuantizationConfig` subclass calls a standalone function that walks the config tree: - `convert_to_float8()` swaps `Linear.Config` → `Float8LinearConfig` (whose `build()` produces `Float8Linear` directly) - `convert_moe_to_float8()` / `convert_moe_to_mxfp8()` walk `GroupedExperts.Config` by type and set `_convert_fn` **Removed:** - `ModelConverter`, `ModelConvertersContainer`, `Float8LinearConverter`, `Float8GroupedMMConverter`, `MXFP8Converter`, `QuantizationConverter` classes and `model_converter.py`, `float8.py`, `mx.py` files - `enable_fsdp_float8_all_gather`, `precompute_float8_dynamic_scale_for_fsdp`, `enable_float8_tensorwise_tp` - `model_converters` from `Trainer.Config` and all parallelize functions - `parallel_dims` dependency from converters **Added:** - `QuantizationConfig` hierarchy (`Float8LinearQuant`, `Float8MoEQuant`, `MXFP8MoEQuant`, `MXFP8Quant`) - `Float8LinearConfig(Linear.Config)` — builds `Float8Linear` directly - `Configurable.Config.walk()` yields `(fqn, config, parent, attr)` for config tree traversal and replacement - `has_quantization()` — type-based check - Token dispatcher swap and `pad_multiple` handled at config time ## Test plan - [ ] Full unit test suite passes (219 passed) - [ ] Verify float8 training produces identical loss: ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama3' --baseline-config='llama3_debugmodel_float8' --baseline-ngpus=8 --test-module='llama3' --test-config='llama3_debugmodel_float8' --test-ngpus=8 --assert-equal --no-seed-checkpoint ``` [ghstack-poisoned]
acisseJZhong
added a commit
that referenced
this pull request
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2981
Summary
Apply quantization at model config construction time by swapping config types, instead of post-build model mutation.
Previously, the trainer built the model, then walked the module tree to swap
nn.LinearwithFloat8Linear, requiring save/restore of_param_initand theModuleprotocol. Now, quantization is a config pass inmodel_registry():Each
QuantizationConfigsubclass calls a standalone function that walks the config tree:convert_to_float8()swapsLinear.Config→Float8LinearConfig(whosebuild()producesFloat8Lineardirectly)convert_moe_to_float8()/convert_moe_to_mxfp8()walkGroupedExperts.Configby type and set_convert_fnRemoved:
ModelConverter,ModelConvertersContainer,Float8LinearConverter,Float8GroupedMMConverter,MXFP8Converter,QuantizationConverterclasses andmodel_converter.py,float8.py,mx.pyfilesenable_fsdp_float8_all_gather,precompute_float8_dynamic_scale_for_fsdp,enable_float8_tensorwise_tpmodel_convertersfromTrainer.Configand all parallelize functionsparallel_dimsdependency from convertersAdded:
QuantizationConfighierarchy (Float8LinearQuant,Float8MoEQuant,MXFP8MoEQuant,MXFP8Quant)Float8LinearConfig(Linear.Config)— buildsFloat8LineardirectlyConfigurable.Config.walk()yields(fqn, config, parent, attr)for config tree traversal and replacementhas_quantization()— type-based checkpad_multiplehandled at config timeTest plan