Skip to content

quantize on config instead of on model - #3032

Merged
acisseJZhong merged 36 commits into
gh/acisseJZhong/8/basefrom
gh/acisseJZhong/8/head
Apr 28, 2026
Merged

acisseJZhong merged 36 commits into
gh/acisseJZhong/8/basefrom
gh/acisseJZhong/8/head

Conversation

@acisseJZhong

@acisseJZhong acisseJZhong commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

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():

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 20, 2026
@acisseJZhong
acisseJZhong marked this pull request as draft April 20, 2026 19:59
acisseJZhong added a commit that referenced this pull request Apr 20, 2026
ghstack-source-id: 65957b6
Pull Request resolved: #3032
acisseJZhong added a commit that referenced this pull request Apr 20, 2026
ghstack-source-id: eeca2fa
Pull Request resolved: #3032
acisseJZhong added a commit that referenced this pull request Apr 20, 2026
ghstack-source-id: a7f2953
Pull Request resolved: #3032
acisseJZhong added a commit that referenced this pull request Apr 20, 2026
ghstack-source-id: 91b1fef
Pull Request resolved: #3032
## 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 added a commit that referenced this pull request Apr 20, 2026
ghstack-source-id: c52668d
Pull Request resolved: #3032
@acisseJZhong
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]
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 added a commit that referenced this pull request Apr 27, 2026
ghstack-source-id: 9ca178c
Pull Request resolved: #3032
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 27, 2026
ghstack-source-id: 5132985
Pull Request resolved: #3032

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 added a commit that referenced this pull request Apr 27, 2026
ghstack-source-id: a7043fa
Pull Request resolved: #3032

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @fegin as I am deleting this file.

@acisseJZhong

acisseJZhong commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor Author

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 27, 2026
ghstack-source-id: 35f1b4d
Pull Request resolved: #3032
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 27, 2026
ghstack-source-id: 8c4def5
Pull Request resolved: #3032
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 27, 2026
ghstack-source-id: 0a9f4b7
Pull Request resolved: #3032
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 27, 2026
ghstack-source-id: 403b2c0
Pull Request resolved: #3032
@acisseJZhong acisseJZhong added the ciflow/h100.8 Trigger H100.8 CI label Apr 27, 2026
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 27, 2026
ghstack-source-id: dffcfb7
Pull Request resolved: #3032
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 27, 2026
ghstack-source-id: 8870e68
Pull Request resolved: #3032
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 27, 2026
ghstack-source-id: 52d8d41
Pull Request resolved: #3032
@acisseJZhong
acisseJZhong merged commit 4f16fff into gh/acisseJZhong/8/base Apr 28, 2026
20 of 25 checks passed
acisseJZhong added a commit that referenced this pull request Apr 28, 2026
Continuation of #3032 (accidentally merged to wrong base branch). See
#3032 for full description.
acisseJZhong added a commit that referenced this pull request Apr 28, 2026
ghstack-source-id: 575a18e
Pull Request resolved: #3032
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100.8 Trigger H100.8 CI ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants