Skip to content

[mxfp8 moe training] add MX MoE model converter using torchao mxfp8 moe training; refactor quantization APIs to use unified API - #1701

Merged
danielvegamyhre merged 5 commits into
pytorch:mainfrom
danielvegamyhre:mx-moe-update
Sep 26, 2025
Merged

danielvegamyhre merged 5 commits into
pytorch:mainfrom
danielvegamyhre:mx-moe-update

Conversation

@danielvegamyhre

@danielvegamyhre danielvegamyhre commented Sep 12, 2025 •

Copy link
Copy Markdown
Contributor

Context

  • We've recently landed prototype mxfp8 MoE training support in torchao, with ~1.3x speedup over bf16 in single node. fsdp2 only, llama4 e2e training with seq_len 8192, 2 experts per device: [mxfp8 moe training] use new 3d colwise quantization kernel ao#3037.
  • This PR integrates this feature into torchtitan and refactors the quantized training APIs to use a unified "quantize.[mx|float8].[dense|moe]" API

Changes

  • Replace "float8" and "mx" model converters with the following set of converters, unified under the quantize namespace:
    • quantize.dense.mx
    • quantize.dense.float8
    • quantize.moe.mx
    • quantize.moe.float8
  • This clean separation allows users more flexibility/control, to use mxfp8 for dense layers, MoE layers, or both.

Test plan

  • float8 dense and moe: NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_conf igs/debug_model.toml" sanitize ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.expert_parallel_degree=4 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --model.converters="quantize.dense.mx,quantize.moe.mx" --quantize.dense.mx.recipe_n ame="mxfp8_cublas" --quantize.moe.mx.fqns="experts"
  • mxfp8 dense and moe: NGPU=4 CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml" ./run_train.sh --parallelism.data_parallel_shard_degree=4 --parallelism.tensor_parallel_degree=1 --model.print-after-conversion --metrics.log_freq=10 --training.steps=30 --compile.enable --model.converters="quantize.dense.float8,quantize.moe.float8"

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 12, 2025
@danielvegamyhre
danielvegamyhre marked this pull request as draft September 12, 2025 00:21
@danielvegamyhre
danielvegamyhre marked this pull request as ready for review September 12, 2025 00:27
@danielvegamyhre
danielvegamyhre force-pushed the mx-moe-update branch 2 times, most recently from 960840d to 90582f1 Compare September 12, 2025 00:43
@danielvegamyhre

Copy link
Copy Markdown
Contributor Author

cc @tianyu-l @drisspg for review

# TODO: add warning in torchao when this happens, or find a better way to avoid this.
if self.moe_fqns:
self._convert_moe_layers(model)

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.

it feels like the converter registered for self.config should handle this case specifically

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.

as in having separate converters registered for mxfp8 moe, fp8 moe etc? If so, I kind of agree actually, the converters are becoming a bit of a mess, and having separate converters would also allow users to convert just dense or just MoE (or both), rather than the current state of having to convert dense in order to convert MoE.

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.

Yeah that is one way, another thing I was thinking is that https://github.com/pytorch/ao/blob/93030e750186ace1c1c2ee7a849e2818a9f0ffde/torchao/prototype/moe_training/conversion_utils.py#L50 should be able to gracefully handle the case where the module has already be converted

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.

Separated the dense and MoE converters

@tianyu-l tianyu-l left a comment

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.

In the log

Swapped w1.weight to ScaledGroupedMMTensor

it's hard to tell which w1 is converted. Can we include full fqn?

(eager only currently - compile support in progress)

Does it mean we shouldn't care too much about performance with this PR?
How about numerics?

I'll try to find some time to look into #1651

@danielvegamyhre
danielvegamyhre marked this pull request as draft September 14, 2025 00:23
@danielvegamyhre danielvegamyhre changed the title [mxfp8 moe training] add torchao MXFP8 MoE training integration; bump version guard [WIP] [mxfp8 moe training] add torchao MXFP8 MoE training integration; bump version guard Sep 15, 2025
@danielvegamyhre danielvegamyhre changed the title [WIP] [mxfp8 moe training] add torchao MXFP8 MoE training integration; bump version guard [mxfp8 moe training] add MX MoE model converter using torchao mxfp8 moe training Sep 20, 2025
@danielvegamyhre
danielvegamyhre marked this pull request as ready for review September 20, 2025 18:15
@danielvegamyhre
danielvegamyhre force-pushed the mx-moe-update branch 6 times, most recently from d674008 to 5c45908 Compare September 20, 2025 19:19
@danielvegamyhre
danielvegamyhre force-pushed the mx-moe-update branch 4 times, most recently from 8533644 to 0032b6a Compare September 26, 2025 01:02

@tianyu-l tianyu-l left a comment

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.

nice refactor, lgtm

@danielvegamyhre
danielvegamyhre force-pushed the mx-moe-update branch 2 times, most recently from 5d6046b to 7e1caa0 Compare September 26, 2025 01:50
@danielvegamyhre

Copy link
Copy Markdown
Contributor Author

@tianyu-l tests are failing with a weird CI issue, it cannot stat an artifacts dir? Is this a known issue? Are we ok to merge?

@tianyu-l

Copy link
Copy Markdown
Contributor



register_model_converter(Float8Converter, "float8")
register_model_converter(Float8DenseConverter, "quantize.float8.dense")

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.

IMO ideally the order would be quantize.dense|moe.float8|mx

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.

hmm I agree... updated and retested on h100 + b200



class MXConverter(ModelConverter):
class MXDenseConverter(ModelConverter):

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.

MXLinearConverter?



register_model_converter(MXConverter, "mx")
class MXMoEConverter(ModelConverter):

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.

MXGroupedGemmConverter? the more specific the better

@danielvegamyhre
danielvegamyhre force-pushed the mx-moe-update branch 2 times, most recently from b550f4a to c8ca3c5 Compare September 26, 2025 16:45
@danielvegamyhre
danielvegamyhre force-pushed the mx-moe-update branch 2 times, most recently from daac1f7 to 588966a Compare September 26, 2025 17:27
@danielvegamyhre
danielvegamyhre merged commit 5b5d468 into pytorch:main Sep 26, 2025
danielvegamyhre added a commit that referenced this pull request Sep 29, 2025
In #1701 we split out the `Float8` job config to `Float8Dense` and
`Float8MoE`. This forge config was inadvertently not updated.

cc @tianyu-l
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
…oe training; refactor quantization APIs to use unified API (pytorch#1701)

## Context
- We've recently landed prototype mxfp8 MoE training support in torchao,
with **~1.3x speedup** over bf16 in single node. fsdp2 only, llama4 e2e
training with seq_len 8192, 2 experts per device:
pytorch/ao#3037.
- This PR integrates this feature into torchtitan and refactors the
quantized training APIs to use a unified
`"quantize.[mx|float8].[dense|moe]"` API

## Changes
- Replace "float8" and "mx" model converters with the following set of
converters, unified under the `quantize` namespace:
     - `quantize.dense.mx`
     - `quantize.dense.float8`
     - `quantize.moe.mx`
     - `quantize.moe.float8`
- This clean separation allows users more flexibility/control, to use
mxfp8 for dense layers, MoE layers, or both.


## Test plan 
- float8 dense and moe: `NGPU=4
CONFIG_FILE="./torchtitan/experiments/llama4/train_conf
igs/debug_model.toml" sanitize ./run_train.sh
--parallelism.data_parallel_shard_degree=4
--parallelism.expert_parallel_degree=4
--parallelism.tensor_parallel_degree=1 --model.print-after-conversion
--metrics.log_freq=10 --training.steps=30
--model.converters="quantize.dense.mx,quantize.moe.mx"
--quantize.dense.mx.recipe_n
ame="mxfp8_cublas"  --quantize.moe.mx.fqns="experts"`
- mxfp8 dense and moe: `NGPU=4
CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml"
./run_train.sh --parallelism.data_parallel_shard_degree=4
--parallelism.tensor_parallel_degree=1 --model.print-after-conversion
--metrics.log_freq=10 --training.steps=30 --compile.enable
--model.converters="quantize.dense.float8,quantize.moe.float8"`
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
In pytorch#1701 we split out the `Float8` job config to `Float8Dense` and
`Float8MoE`. This forge config was inadvertently not updated.

cc @tianyu-l
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
…oe training; refactor quantization APIs to use unified API (pytorch#1701)

## Context
- We've recently landed prototype mxfp8 MoE training support in torchao,
with **~1.3x speedup** over bf16 in single node. fsdp2 only, llama4 e2e
training with seq_len 8192, 2 experts per device:
pytorch/ao#3037.
- This PR integrates this feature into torchtitan and refactors the
quantized training APIs to use a unified
`"quantize.[mx|float8].[dense|moe]"` API

## Changes
- Replace "float8" and "mx" model converters with the following set of
converters, unified under the `quantize` namespace:
     - `quantize.dense.mx`
     - `quantize.dense.float8`
     - `quantize.moe.mx`
     - `quantize.moe.float8`
- This clean separation allows users more flexibility/control, to use
mxfp8 for dense layers, MoE layers, or both.


## Test plan 
- float8 dense and moe: `NGPU=4
CONFIG_FILE="./torchtitan/experiments/llama4/train_conf
igs/debug_model.toml" sanitize ./run_train.sh
--parallelism.data_parallel_shard_degree=4
--parallelism.expert_parallel_degree=4
--parallelism.tensor_parallel_degree=1 --model.print-after-conversion
--metrics.log_freq=10 --training.steps=30
--model.converters="quantize.dense.mx,quantize.moe.mx"
--quantize.dense.mx.recipe_n
ame="mxfp8_cublas"  --quantize.moe.mx.fqns="experts"`
- mxfp8 dense and moe: `NGPU=4
CONFIG_FILE="./torchtitan/experiments/llama4/train_configs/debug_model.toml"
./run_train.sh --parallelism.data_parallel_shard_degree=4
--parallelism.tensor_parallel_degree=1 --model.print-after-conversion
--metrics.log_freq=10 --training.steps=30 --compile.enable
--model.converters="quantize.dense.float8,quantize.moe.float8"`
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
In pytorch#1701 we split out the `Float8` job config to `Float8Dense` and
`Float8MoE`. This forge config was inadvertently not updated.

cc @tianyu-l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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