Skip to content

feat:support DiT and VAE for flux2#1983

Open
wang-shuibin wants to merge 2 commits into
xLLM-AI:mainfrom
wang-shuibin:flux2_dit_vae_0720
Open

feat:support DiT and VAE for flux2#1983
wang-shuibin wants to merge 2 commits into
xLLM-AI:mainfrom
wang-shuibin:flux2_dit_vae_0720

Conversation

@wang-shuibin

Copy link
Copy Markdown

Description

support DiT and VAE module for flux2

Related Issues

Feat:support DiT and VAE module for flux2

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactor
  • Documentation
  • Test
  • Build or CI

Pull Request Checklist

Thank you for contributing to xLLM. Before requesting review, please make sure the following items are complete.

PR Title and Commit Messages

  • The PR title and each commit message follow the xLLM commit format: <type>: <subject>.

Allowed types: feat, bugfix, docs, test, refactor, chore, style, revert, perf, model, build, release.
The subject should use clear English, start with a verb, include at least 4 words, and end with ..

Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit or an equivalent command.
  • I have installed the hooks with pre-commit install.
  • I have run pre-commit run --all-files and fixed any reported issues.

If you are unsure how to set up pre-commit, see the pre-commit documentation.

Self Review

  • I have self-reviewed the code according to .agents/skills/code-review/references/custom-code-style.md, especially code written or assisted by AI.
  • I have rebased this PR onto the latest main branch.

Build and Test Coverage

  • Tests have been added or updated as needed.
  • CUDA: python setup.py build test has passed on a CUDA machine.
  • NPU: python setup.py build test has passed on an NPU machine.
  • MLU: python setup.py build test has passed on an MLU machine.

Reviewer Notes

@wang-shuibin wang-shuibin changed the title feat:support DiT and VAE module for flux2 feat:support DiT and VAE for flux2 Jul 20, 2026

PROPERTY(float, batch_norm_eps) = 1e-04f;
PROPERTY(float, batch_norm_momentum) = 0.1f;
PROPERTY(std::vector<int64_t>, ae_patch_size) = {};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

vae_patch_size?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes

class AdaLayerNormContinuousImpl : public torch::nn::Module {
public:
explicit AdaLayerNormContinuousImpl(ModelContext context)
explicit AdaLayerNormContinuousImpl(ModelContext context,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is this change necessary?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, this change is necessary. The norm_out in Flux2-dev weights does not contain bias weights, while AdaLayerNormContinuous defaults to with_bias=true. We have to adjust this parameter to match the weights.
Uploading norm_out.png…

// ── Determine parallelism strategy for QKV ──
std::optional<TpOptions> tp_options = std::nullopt;

if (FLAGS_tp_size > 1) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

use config instead of glags

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Revised, now using config instead of flags.

};
TORCH_MODULE(Flux2PosEmbed);

class Flux2PipelineBaseImpl : public torch::nn::Module {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

when support klein, need think about encapsulating features in base classe.

xiao-yu-chen
xiao-yu-chen previously approved these changes Jul 22, 2026
@@ -0,0 +1,213 @@
/* Copyright 2025 The xLLM Authors. All Rights Reserved.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

2026

Co-authored-by: ethan686 <zbw_ethan@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants