Skip to content

Implement torch compile and mxfp8 for flux - #2579

Merged
tianyu-l merged 14 commits into
pytorch:mainfrom
hlahkar:flux_compile
Mar 30, 2026
Merged

tianyu-l merged 14 commits into
pytorch:mainfrom
hlahkar:flux_compile

Conversation

@hlahkar

@hlahkar hlahkar commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

This PR implements torch compile and mxfp8 dtype computation for Flux model. Note: frozen encoder are not included in for mxfp8 quantization.

Test Report fo the test cases implementd for torch compile for Flux:

Running 15 items in this shard: tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_multiple_calls, tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_uses_specified_backend, tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_wraps_all_blocks, tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_forward_after_compile, tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_encoder_forward_after_compile, tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_no_fullgraph_for_encoders, tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_clip_layers, tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_t5_blocks, tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_disabled, tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_with_model_component, tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_without_model_component, tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_encoder_compile_disabled, tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_compiled, tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_when_disabled, tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_without_loss_component

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_multiple_calls PASSED [ 6%]
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_uses_specified_backend PASSED [ 13%]
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_wraps_all_blocks PASSED [ 20%]
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_forward_after_compile PASSED [ 26%]
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_encoder_forward_after_compile PASSED [ 33%]
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_no_fullgraph_for_encoders PASSED [ 40%]
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_clip_layers PASSED [ 46%]
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_t5_blocks PASSED [ 53%]
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_disabled PASSED [ 60%]
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_with_model_component PASSED [ 66%]
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_without_model_component PASSED [ 73%]
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_encoder_compile_disabled PASSED [ 80%]
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_compiled PASSED [ 86%]
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_when_disabled PASSED [ 93%]
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_without_loss_component PASSED [100%]

========================================================================================================================== warnings summary ==========================================================================================================================
../../usr/local/lib/python3.12/dist-packages/torch/jit/_script.py:365: 14 warnings
/usr/local/lib/python3.12/dist-packages/torch/jit/_script.py:365: DeprecationWarning: torch.jit.script_method is deprecated. Please switch to torch.compile or torch.export.
warnings.warn(

:488
:488: DeprecationWarning: builtin type SwigPyPacked has no module attribute

:488
:488: DeprecationWarning: builtin type SwigPyObject has no module attribute

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================================================== 15 passed, 16 warnings in 9.74s ===================================================================================================================

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 15, 2026
@wwwjn wwwjn self-assigned this Mar 16, 2026

@wwwjn wwwjn 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.

Thanks, can you also show the end to end MFU (MFU is implemented here) when compile is enabled?

When MXFP8 is enabled, can you show it's runnable as a sanity check?

For tests, an integration test with --compile enabled would be better than unit test. Can you help add a integration test instead of a unit test? Unit test is more for testing components.

Comment thread torchtitan/models/flux/parallelize.py Outdated
training: TrainingConfig,
compile_config: CompileConfig,
):
if compile_config.enable and "model" in compile_config.components:

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.

Should we do compile.compononts = ["model", "encoder"], so encoder can be optional. And encoders are frozen during training, without fullgraph=True, these encoders can be separated from model?

I was wondering for smaller size model, will user always enable compile for encoder?

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.

Good point. I think if the benefit of compile encoders is small, then we can choose to not compile them at all.

I wouldn't recommend adding "encoder" to the components list before seeing real needs. (I mean, if we add encoder, we should at least rename model to decoder.)

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.

Should we do compile.compononts = ["model", "encoder"], so encoder can be optional. And encoders are frozen during training, without fullgraph=True, these encoders can be separated from model?

I was wondering for smaller size model, will user always enable compile for encoder?

Based on the above conversation have removed compile for the encoder

Comment thread torchtitan/models/flux/README.md Outdated
Comment on lines +91 to +92
--model_converters '["mxfp8"]' \
--model_converters.mxfp8.fqns '["double_blocks","single_blocks","img_in","txt_in","time_in","vector_in","final_layer"]'

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.

Oh, can this (specifying model_converters by str name) still work? I thought we changed to python object based config and tyro can't parse this anymore.

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.

Thanks for pointing this out; updated the README file

@hlahkar

hlahkar commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, can you also show the end to end MFU (MFU is implemented here) when compile is enabled?

When MXFP8 is enabled, can you show it's runnable as a sanity check?

For tests, an integration test with --compile enabled would be better than unit test. Can you help add a integration test instead of a unit test? Unit test is more for testing components.

Based on the above conversation:

  1. Removed the Unit Test and put a Integartion test for compile
  2. MFU numbers with eager and compile:
    Compile - tps: 15,856  tflops: 626.86  mfu: 25.07%
    Eager - tps: 10,269  tflops: 406.00  mfu: 16.24%
  3. MXFP8 Sanity Logs:
    Command used - MODULE=flux CONFIG=flux_schnell_mxfp8 ./run_train.sh --dataloader.dataset_path /workspace/datasets/cc12m-wds/
    mxfp8.log.rtf

Comment thread tests/integration_tests/flux.py Outdated
"--module flux",
"--config flux_debugmodel",
"--compile.enable",
"--training.local_batch_size 64",

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.

CI failed because of oom, my guess is your batch size is too big. Can we use default? 2 or 4?

Comment thread torchtitan/models/flux/trainer.py Outdated
# Apply FSDP

# Apply FSDP to the T5 model / CLIP model
# Apply compile and FSDP to the T5 model / CLIP 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.

only applying FSDP

Comment thread torchtitan/models/flux/parallelize.py Outdated
# sub-nodes share the same numel, but the Flux backward graph contains
# reductions with mismatched sizes (hidden_size vs hidden_size * mlp_ratio).
# mix_order_reduction was enabled for OSS in pytorch/pytorch#166938.
torch._inductor.config.triton.mix_order_reduction = False

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.

@Lucaskabela @xmfan to review this

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.

do we have the error message paste for the stack trace?

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.

Attaching the stacktrace for reference.
stacktrace.rtf

@Lucaskabela Lucaskabela 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.

Few minor nits and questions on usage/issues encountered

Comment thread torchtitan/models/flux/parallelize.py Outdated
# sub-nodes share the same numel, but the Flux backward graph contains
# reductions with mismatched sizes (hidden_size vs hidden_size * mlp_ratio).
# mix_order_reduction was enabled for OSS in pytorch/pytorch#166938.
torch._inductor.config.triton.mix_order_reduction = False

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.

RE this - are we able to atain a minimized reproduction? If so we could share this with the inductor team to try and fix this bug

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.

Attaching a minimized reproducer for the same.
repro_mix_order_reduction.py

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.

I tried this on nightly and it does not reproduce - what torch version are you on? Can you try on nightly?

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.

Updated the code to remove the workaround

Comment thread torchtitan/models/flux/parallelize.py Outdated
torch._inductor.config.triton.mix_order_reduction = False
# pyrefly: ignore [missing-attribute]
for block_id, block in model.double_blocks.named_children():
block = torch.compile(block, backend=compile_config.backend, fullgraph=True)

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.

nit: Could you try block.compile() here? This is preferred in our programming model and may help prevent needing to reassign/register the module

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.

Thanks for pointing this out; updated the code

Comment thread torchtitan/models/flux/README.md Outdated
## Supported Features
- Parallelism: The model supports FSDP, HSDP, CP for training on multiple GPUs.
- Activation checkpointing: The model uses activation checkpointing to reduce memory usage during training.
- `torch.compile`: Per-block compilation for the Flux transformer (DoubleStreamBlock, SingleStreamBlock) and the T5/CLIP text encoders. See [torch.compile](#torchcompile) below.

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.

Where are you applying compile on the T5/CLIP encoder portion? I don't see that here

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.

Thanks for pointing this out; updated the code

@hlahkar
hlahkar requested a review from Lucaskabela March 27, 2026 10:18
torch._inductor.config.triton.mix_order_reduction = False
# pyrefly: ignore [not-iterable]
for block in model.double_blocks:
block.compile(backend=compile_config.backend, fullgraph=True)

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.

Need linter fix here

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.

Updated with the linter fix

Comment thread torchtitan/models/flux/parallelize.py Outdated
# sub-nodes share the same numel, but the Flux backward graph contains
# reductions with mismatched sizes (hidden_size vs hidden_size * mlp_ratio).
# mix_order_reduction was enabled for OSS in pytorch/pytorch#166938.
torch._inductor.config.triton.mix_order_reduction = False

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.

I tried this on nightly and it does not reproduce - what torch version are you on? Can you try on nightly?

@wwwjn wwwjn assigned Lucaskabela and wwwjn and unassigned wwwjn Mar 27, 2026
@wwwjn wwwjn added this to the New Feature, Model, Misc milestone Mar 27, 2026
@wwwjn wwwjn moved this from Todo to In Progress in TorchTitan Development Mar 27, 2026
@hlahkar
hlahkar requested a review from Lucaskabela March 28, 2026 09:57
@hlahkar
hlahkar requested a review from tianyu-l March 30, 2026 04:45

@Lucaskabela Lucaskabela 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.

Thanks for the change - glad the inductor pass is confirmed fix so we don't need any special casing here :)

@tianyu-l
tianyu-l merged commit 78348c8 into pytorch:main Mar 30, 2026
10 of 11 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in TorchTitan Development Mar 30, 2026
acisseJZhong pushed a commit that referenced this pull request Mar 31, 2026
This PR implements torch compile and mxfp8 dtype computation for Flux
model. Note: frozen encoder are not included in for mxfp8 quantization.

Test Report fo the test cases implementd for torch compile for Flux:

Running 15 items in this shard:
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_multiple_calls,
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_uses_specified_backend,
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_wraps_all_blocks,
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_forward_after_compile,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_encoder_forward_after_compile,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_no_fullgraph_for_encoders,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_clip_layers,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_t5_blocks,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_disabled,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_with_model_component,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_without_model_component,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_encoder_compile_disabled,
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_compiled,
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_when_disabled,
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_without_loss_component


tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_multiple_calls
PASSED [ 6%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_uses_specified_backend
PASSED [ 13%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_wraps_all_blocks
PASSED [ 20%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_forward_after_compile
PASSED [ 26%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_encoder_forward_after_compile
PASSED [ 33%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_no_fullgraph_for_encoders
PASSED [ 40%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_clip_layers
PASSED [ 46%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_t5_blocks
PASSED [ 53%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_disabled
PASSED [ 60%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_with_model_component
PASSED [ 66%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_without_model_component
PASSED [ 73%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_encoder_compile_disabled
PASSED [ 80%]

tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_compiled
PASSED [ 86%]

tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_when_disabled
PASSED [ 93%]

tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_without_loss_component
PASSED [100%]


==========================================================================================================================
warnings summary
==========================================================================================================================
../../usr/local/lib/python3.12/dist-packages/torch/jit/_script.py:365:
14 warnings
/usr/local/lib/python3.12/dist-packages/torch/jit/_script.py:365:
DeprecationWarning: `torch.jit.script_method` is deprecated. Please
switch to `torch.compile` or `torch.export`.
    warnings.warn(

<frozen importlib._bootstrap>:488
<frozen importlib._bootstrap>:488: DeprecationWarning: builtin type
SwigPyPacked has no __module__ attribute

<frozen importlib._bootstrap>:488
<frozen importlib._bootstrap>:488: DeprecationWarning: builtin type
SwigPyObject has no __module__ attribute

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

==================================================================================================================
15 passed, 16 warnings in 9.74s
===================================================================================================================
TXacs pushed a commit to McmillanTAC/torchtitan that referenced this pull request Apr 13, 2026
This PR implements torch compile and mxfp8 dtype computation for Flux
model. Note: frozen encoder are not included in for mxfp8 quantization.

Test Report fo the test cases implementd for torch compile for Flux:

Running 15 items in this shard:
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_multiple_calls,
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_uses_specified_backend,
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_wraps_all_blocks,
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_forward_after_compile,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_encoder_forward_after_compile,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_no_fullgraph_for_encoders,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_clip_layers,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_t5_blocks,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_disabled,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_with_model_component,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_without_model_component,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_encoder_compile_disabled,
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_compiled,
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_when_disabled,
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_without_loss_component


tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_multiple_calls
PASSED [ 6%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_uses_specified_backend
PASSED [ 13%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_wraps_all_blocks
PASSED [ 20%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_forward_after_compile
PASSED [ 26%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_encoder_forward_after_compile
PASSED [ 33%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_no_fullgraph_for_encoders
PASSED [ 40%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_clip_layers
PASSED [ 46%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_t5_blocks
PASSED [ 53%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_disabled
PASSED [ 60%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_with_model_component
PASSED [ 66%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_without_model_component
PASSED [ 73%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_encoder_compile_disabled
PASSED [ 80%]

tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_compiled
PASSED [ 86%]

tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_when_disabled
PASSED [ 93%]

tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_without_loss_component
PASSED [100%]


==========================================================================================================================
warnings summary
==========================================================================================================================
../../usr/local/lib/python3.12/dist-packages/torch/jit/_script.py:365:
14 warnings
/usr/local/lib/python3.12/dist-packages/torch/jit/_script.py:365:
DeprecationWarning: `torch.jit.script_method` is deprecated. Please
switch to `torch.compile` or `torch.export`.
    warnings.warn(

<frozen importlib._bootstrap>:488
<frozen importlib._bootstrap>:488: DeprecationWarning: builtin type
SwigPyPacked has no __module__ attribute

<frozen importlib._bootstrap>:488
<frozen importlib._bootstrap>:488: DeprecationWarning: builtin type
SwigPyObject has no __module__ attribute

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

==================================================================================================================
15 passed, 16 warnings in 9.74s
===================================================================================================================
ACharacterInASimulation pushed a commit to ACharacterInASimulation/torchtitan that referenced this pull request Apr 21, 2026
This PR implements torch compile and mxfp8 dtype computation for Flux
model. Note: frozen encoder are not included in for mxfp8 quantization.

Test Report fo the test cases implementd for torch compile for Flux:

Running 15 items in this shard:
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_multiple_calls,
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_uses_specified_backend,
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_wraps_all_blocks,
tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_forward_after_compile,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_encoder_forward_after_compile,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_no_fullgraph_for_encoders,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_clip_layers,
tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_t5_blocks,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_disabled,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_with_model_component,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_without_model_component,
tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_encoder_compile_disabled,
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_compiled,
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_when_disabled,
tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_without_loss_component


tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_multiple_calls
PASSED [ 6%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_uses_specified_backend
PASSED [ 13%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_apply_compile_wraps_all_blocks
PASSED [ 20%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileFlux::test_forward_after_compile
PASSED [ 26%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_encoder_forward_after_compile
PASSED [ 33%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_no_fullgraph_for_encoders
PASSED [ 40%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_clip_layers
PASSED [ 46%]

tests/unit_tests/test_compile_flux.py::TestApplyCompileToEncoders::test_wraps_t5_blocks
PASSED [ 53%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_disabled
PASSED [ 60%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_with_model_component
PASSED [ 66%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_compile_enabled_without_model_component
PASSED [ 73%]

tests/unit_tests/test_compile_flux.py::TestCompileConfigGating::test_encoder_compile_disabled
PASSED [ 80%]

tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_compiled
PASSED [ 86%]

tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_when_disabled
PASSED [ 93%]

tests/unit_tests/test_compile_flux.py::TestMSELossCompile::test_mse_loss_not_compiled_without_loss_component
PASSED [100%]


==========================================================================================================================
warnings summary
==========================================================================================================================
../../usr/local/lib/python3.12/dist-packages/torch/jit/_script.py:365:
14 warnings
/usr/local/lib/python3.12/dist-packages/torch/jit/_script.py:365:
DeprecationWarning: `torch.jit.script_method` is deprecated. Please
switch to `torch.compile` or `torch.export`.
    warnings.warn(

<frozen importlib._bootstrap>:488
<frozen importlib._bootstrap>:488: DeprecationWarning: builtin type
SwigPyPacked has no __module__ attribute

<frozen importlib._bootstrap>:488
<frozen importlib._bootstrap>:488: DeprecationWarning: builtin type
SwigPyObject has no __module__ attribute

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

==================================================================================================================
15 passed, 16 warnings in 9.74s
===================================================================================================================
@hlahkar
hlahkar deleted the flux_compile branch June 3, 2026 06:32
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

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants