[Distributed w/ TorchTitan] FLUX is Here: Experience Diffusion Model Training on TorchTitan

jianiw: <p>With <a href="mailto:lty@meta.com">Tianyu Liu</a> (<a class="mention" href="/u/tianyu">@tianyu</a>), <a href="mailto:chienchin@meta.com">Chien-Chin Huang</a> (<a class="mention" href="/u/fegin">@fegin</a>), <a href="mailto:weif@meta.com">Wei (Will) Feng</a>,  <a href="mailto:gnadathur@meta.com">Gokul Nadathur</a> (<a class="mention" href="/u/gnadathur">@gnadathur</a>)</p>
<h2><a name="p-472268-tldr-1" class="anchor" href="#p-472268-tldr-1"></a>TL;DR</h2>
<p>We enabled FLUX.1 model suite large-scale pre-training on TorchTitan with FSDP and HSDP support, showcasing diffusion model pre-training on TorchTitan. We also illustrated the training process by running large-scale pre-training using FLUX.1[schnell] model, showing meaningful training results. We showcased the process of onboarding custom models onto torchtitan, empowering the advanced model with TorchTitan’s powerful large-scale training techniques.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/4/b48562b5c0ad09988d7076d0eef4ed76af4521f9.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/b48562b5c0ad09988d7076d0eef4ed76af4521f9" title="final-results"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/4/b48562b5c0ad09988d7076d0eef4ed76af4521f9_2_690x77.jpeg" alt="final-results" data-base62-sha1="pKXILi9ZWbx0FNVY0ydjEEj0SCZ" width="690" height="77" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/4/b48562b5c0ad09988d7076d0eef4ed76af4521f9_2_690x77.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/b/4/b48562b5c0ad09988d7076d0eef4ed76af4521f9_2_1035x115.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/b/4/b48562b5c0ad09988d7076d0eef4ed76af4521f9_2_1380x154.jpeg 2x" data-dominant-color="5C5E54"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">final-results</span><span class="informations">1920×215 74.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p><em>Image generated from TorchTitan trained FLUX.1[schnell] model</em></p>
<h2><a name="p-472268-distributed-with-torchtitan-2" class="anchor" href="#p-472268-distributed-with-torchtitan-2"></a>Distributed with TorchTitan</h2>
<p>The GitHub repository <a href="https://github.com/pytorch/torchtitan" rel="noopener nofollow ugc">torchtitan</a> is a proof of concept for large-scale LLM training using native PyTorch, designed to be easy to understand, use, and extend for different training purposes, supporting multi-dimensional parallelisms with modular components. In this series of topics, we introduce the latest PyTorch features for distributed training enabled in TorchTitan.</p>
<ul>
<li>Topic 1: <a href="https://discuss.pytorch.org/t/distributed-w-torchtitan-enabling-float8-all-gather-in-fsdp2/209323">Enabling Float8 All-Gather in FSDP2</a></li>
<li>Topic 2: <a href="https://discuss.pytorch.org/t/distributed-w-torchtitan-introducing-async-tensor-parallelism-in-pytorch/209487">Introducing Async Tensor Parallelism in PyTorch</a></li>
<li>Topic 3: <a href="https://discuss.pytorch.org/t/distributed-w-torchtitan-optimizing-checkpointing-efficiency-with-pytorch-dcp/211250">Optimizing Checkpointing Efficiency with PyTorch DCP</a></li>
<li>Topic 4: <a href="https://discuss.pytorch.org/t/distributed-w-torchtitan-training-with-zero-bubble-pipeline-parallelism/214420">Training with Zero-Bubble Pipeline Parallelism</a></li>
<li>Topic 5: <a href="https://discuss.pytorch.org/t/distributed-w-torchtitan-breaking-barriers-training-long-context-llms-with-1m-sequence-length-in-pytorch-using-context-parallel/215082">Breaking Barriers: Training Long Context LLMs with 1M Sequence Length in PyTorch Using Context Parallel</a></li>
<li>Topic 6: <a href="https://discuss.pytorch.org/t/distributed-w-torchtitan-semi-synchronous-training-using-torchft/219874">Semi synchronous training in combination using TorchFT</a></li>
<li>→ Topic 7: FLUX is Here: Experience Diffusion Model Training on TorchTitan</li>
</ul>
<h2><a name="p-472268-onboard-custom-models-to-torchtitan-3" class="anchor" href="#p-472268-onboard-custom-models-to-torchtitan-3"></a>Onboard custom models to TorchTitan</h2>
<p>TorchTitan’s framework and modular components are crafted to simplify the integration of custom models, enabling you to fully leverage its capabilities for your projects. To optimize the use of this robust framework, we suggest the following steps for your model development lifecycle:</p>
<ol>
<li>Select dataset: Begin with data preparation. TorchTitan offers a comprehensive dataloader (<a href="https://github.com/pytorch/torchtitan/blob/main/torchtitan/datasets/hf_datasets.py" rel="noopener nofollow ugc">link</a>) that seamlessly integrates with various HuggingFace datasets, tokenizers, and data processing functions. Additional examples, such as a multimodal dataloader, are available in the experiment folder (<a href="https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/multimodal/mm_dataset.py" rel="noopener nofollow ugc">link</a>).</li>
<li>Model and Training components Definition: Define the model architecture and training components, including loss function, optimizer, learning rate scheduler, etc. Utilize the TrainSpec abstraction (<a href="https://github.com/pytorch/torchtitan/blob/main/docs/extension.md#trainspec" rel="noopener nofollow ugc">link</a>) provided by TorchTitan to define your model’s training components</li>
<li>Training Configuration: Create a training configuration to manage the training loop. The components in TorchTitan are designed as reusable blocks that can be toggled on or off via config files. You can use the provided train loop (<a href="https://github.com/pytorch/torchtitan/blob/main/torchtitan/train.py" rel="noopener nofollow ugc">link</a>) to effortlessly enable advanced training technologies.</li>
<li>Parallelization Plan: Crafting a parallelism plan tailored to your model is made easier with TorchTitan. You can refer to the comprehensive, all-inclusive Llama3 example (<a href="https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/llama3/parallelize_llama.py" rel="noopener nofollow ugc">link</a>) for guidance on applying DDP, FSDP, tensor parallelism, and activation checkpointing.</li>
<li>Performance Analysis and Debugging: Enhance your model’s performance by utilizing existing tools like profiling, and deterministic training options. This step is crucial for model performance but you can get it done by simply incorporating existing tools provided by TorchTitan.</li>
</ol>
<p>We will publish a thorough guidance for adding new models in TorchTitan, with more details explained. Following the above brief path, we introduced FLUX model, the state-of-the art diffusion model onto TorchTitan as a step-by-step example:</p>
<ol>
<li>FLUX.1 Dataset and Processing: We adapted the dataloader logic for the CC12M dataset, adding a function for customized processing. Images were standardized to 256 x 256 pixels by resizing, cropping, and filtering to ensure quality.</li>
<li>FLUX.1 Model and Training Components Definition: The model architecture is integrated from the open-source version (<a href="https://github.com/black-forest-labs/flux" rel="noopener nofollow ugc">github</a>), and we use the MSE loss function for training.</li>
<li>FLUX.1 Training Config and Loops: Developed three training configurations to control the loop, with minor adjustments to the forward-backward step by extending the main trainer class.</li>
<li>FLUX.1 Parallelization Function: Designed an FSDP plan based on Llama practices, applying FSDP to the T5 encoder and FLUX.1 model.</li>
<li>Training, Performance Analysis, and Debugging: Optimized the FLUX.1 model on TorchTitan, reducing training time through detailed process analysis.</li>
</ol>
<p>In the following sections, we will dive deeper into the FLUX.1 model on TorchTitan, discussing design choices to provide more insight about onboarding models, as well as showcasing diffusion model training on TorchTitan.</p>
<h2><a name="p-472268-diffusion-model-and-flux1-model-4" class="anchor" href="#p-472268-diffusion-model-and-flux1-model-4"></a>Diffusion model and FLUX.1 model</h2>
<p>Diffusion models are a class of generative models that have gained popularity for their ability to generate high-quality data, such as images, by simulating a diffusion process. Diffusion models work by gradually transforming a simple, structured distribution (like Gaussian noise) into a complex data distribution (such as natural images) through a series of small, reversible steps<sup class="footnote-ref"><a href="#footnote-472268-1" id="footnote-ref-472268-1">[1]</a></sup>. This transformation is typically modeled as a stochastic process, where each step adds a small amount of noise to the data, and the model learns to reverse this process to generate new samples. In recent years, the diffusion models has been proven to be very effective in generating high-resolution images<sup class="footnote-ref"><a href="#footnote-472268-2" id="footnote-ref-472268-2">[2]</a></sup> and videos<sup class="footnote-ref"><a href="#footnote-472268-3" id="footnote-ref-472268-3">[3]</a></sup>,</p>
<p>FLUX.1 model is the state-of-the-art diffusion model, developed by <a href="https://bfl.ai/" rel="noopener nofollow ugc">Black Forest Labs</a>. FLUX.1 is a suite of text-to-image models that define a new state-of-the-art in image detail, prompt adherence, style diversity and scene complexity for text-to-image synthesis<sup class="footnote-ref"><a href="#footnote-472268-4" id="footnote-ref-472268-4">[4]</a></sup>. From the FLUX.1 model suite, Black Forest Lab open-sourced FLUX.1[dev] and FLUX.1[schnell] models. Our work is based on the open-sourced version (<a href="https://github.com/black-forest-labs/flux" rel="noopener nofollow ugc">github</a>). For more information about FLUX.1 model suite, please refer to the blog (<a href="https://bfl.ai/announcements/24-08-01-bfl" rel="noopener nofollow ugc">link</a>) from Black Forest Labs.</p>
<h2><a name="p-472268-flux1-model-on-torchtitan-5" class="anchor" href="#p-472268-flux1-model-on-torchtitan-5"></a>FLUX.1 Model on TorchTitan</h2>
<p>Now the FLUX.1 Models are available on torchtian, supporting pre-training from scratch.</p>
<p>What feature we support:</p>
<ul>
<li>Parallelism: The model supports FSDP, HSDP for training on multiple GPUs. The FLUX.1 models are using TorchTitan compatible architecture, ready to integrate more parallelism.</li>
<li>Activation checkpointing: The model uses activation checkpointing to reduce memory usage during training.</li>
<li>Checkpointing: save and load DCP format checkpoint.</li>
<li>Classifier-free diffusion guidance support: We support classifier-free guidance for FLUX.1 models.</li>
</ul>
<p>We support 3 different flavors of FLUX model:</p>
<ul>
<li>Debug model: smaller-size model (~0.25B), used mainly for local debugging on TorchTitan</li>
<li>FLUX.1 [dev]: FLUX.1 [dev] is an open-weight (<a href="https://github.com/black-forest-labs/flux" rel="noopener nofollow ugc">link</a>), guidance-distilled model, with ~12B parameters.</li>
<li>FLUX.1 [schnell]: FLUX.1[schnell] is the open-sourced, fastest model that is tailored for local development and personal use. This model has ~12B parameters.</li>
</ul>
<h3><a name="p-472268-fsdp-6" class="anchor" href="#p-472268-fsdp-6"></a>FSDP</h3>
<p>In this section, we will analyze FSDP performance on the FLUX.1 [schnell] model. In the profiler shown below, the FLUX model is sharded across 8 GPUs (Local batch size = 64, FSDP shard degree = 8, other detailed parameters can be found <a href="https://github.com/pytorch/torchtitan/blob/main/torchtitan/experiments/flux/train_configs/flux_schnell_model.toml" rel="noopener nofollow ugc">here</a>). The FLUX.1 [schnell] model consists of 19 SingleBlocks (a transformer-based layer), and 38 DoubleBlocks, we wrapped each block as a separate FSDP module. For linear layers and Multi-Layer Perceptron (MLP) blocks, we also wrapped each layer into separate FSDP modules.</p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXd3-IGMaew3-1QQLpgTmWuvbydy8plSSJQ2oAqwtGRLAOeZkJf2zuSokPpkmgOTXKoePB83VRng_0m0jNeGeKfav_62CWmcThradGxXJUYtb_Lvs-v7QQS7T4LD3RQXtNlfSg1dyg?key=l_rx6Ncw3SKqj-tVLlmPXA" alt="" width="624" height="280" role="presentation"></p>
<p><em>Fig 1. Overview of FLUX.1[schnell] model profiler performance w/ FSDP</em></p>
<p>The above diagram shows the forward pass and the backward pass of FLUX.1[schnell] model, it shows communication-computation overlapping with FSDP applied.</p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXfCzkuT7qnOMKRrbpwO0vEPPVBlm9S5uSuFgc2J1-w6_Gbzi3FQOtd1zDgdkJAJ94oWNwUjsM11cWvHycI2Wl7cZ0lJ5Vuj_jY3vdTFuMEe3nze0joajDrP8fiCQu-HSRwGJdkMRg?key=l_rx6Ncw3SKqj-tVLlmPXA" alt="" width="669" height="286" role="presentation"></p>
<p><em>Figure 2: Detailed examination of the forward pass performance of the FLUX.1[schnell] model</em></p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeV07zoirqvcCW0dHiN6OkZgQw1IMKpx-rSjojfJ5oC_kXcZ78gPtQRgTCAjG37TxDpLpPRG2FPMMnl8SsfYfSw4rvOwufF9pOQRnDmEvWOFNzGRwXwc40wlXtYa3abC7FjE9Pf_A?key=l_rx6Ncw3SKqj-tVLlmPXA" alt="" width="681" height="292" role="presentation"></p>
<p><em>Figure 3: Detailed examination of the backward pass performance of the FLUX.1[schnell] model</em></p>
<h3><a name="p-472268-activation-checkpointing-7" class="anchor" href="#p-472268-activation-checkpointing-7"></a>Activation Checkpointing</h3>
<p>To further mitigate peak GPU memory usage, we used activation checkpointing to reduce the GPU memory usage associated with activations. Activation checkpointing selectively drops these activations and recalculates them on-the-fly, which uses more computation in exchange for lower GPU memory. For the FLUX.1 model, the T5 text encoder generates an encoding with a hidden dimension of 4096, which is subsequently processed by the FLUX.1 model, resulting in huge activation size during forward pass calculations. In this context, the tradeoff between GPU memory and computation is justified. Specifically, for each single block and double block within the FLUX.1 model, we store activations at the block level and recompute all intermediate results within each block. During the backward pass, we load the input activations for each block and recompute intermediate activations prior to computing gradients.</p>
<h3><a name="p-472268-sharded-encoder-8" class="anchor" href="#p-472268-sharded-encoder-8"></a>Sharded Encoder</h3>
<p>The FLUX.1[schnell] model uses the output of multiple pretrained, frozen networks as inputs, including autoencoder latents and 2 text encoder representations: CLIP L/14 model<sup class="footnote-ref"><a href="#footnote-472268-5" id="footnote-ref-472268-5">[5]</a></sup> based text encoder (<a href="https://huggingface.co/openai/clip-vit-large-patch14/tree/main" rel="noopener nofollow ugc">link</a>), and T5-v1.1-xxl<sup class="footnote-ref"><a href="#footnote-472268-6" id="footnote-ref-472268-6">[6]</a></sup> text encoder (<a href="https://huggingface.co/docs/transformers/en/model_doc/t5v1.1" rel="noopener nofollow ugc">link</a>). The CLIP L/14 model was originally developed by researchers at OpenAI to learn about what contributes to robustness in computer vision tasks. The CLIP text encoder will generate a text representation for each prompt with length 768. The T5-v1.1-xxl text encoder is based on the T5 pre-trained model, with ~11 billion parameters, and it generates a text representation with shape 256 * 4096 for each input prompt.</p>
<p>The computation for CLIP text encoders is relatively low. Applying FSDP to the CLIP text encoder will introduce significant communication overhead, resulting in idle periods (“bubbles”) that slow down end-to-end training. In contrast, the T5 encoder involves more substantial computations, so the communication brought by FSDP can be hidden by computation. In our training, we opt to parallelize the T5 text encoder across GPUs using FSDP, while maintaining a full copy of the CLIP text encoder on each GPU.</p>
<h2><a name="p-472268-h-624x280httpslh7-rtgoogleusercontentcomdocszad_4nxeanqfmbzcmltpbyz3d2tnokda2nw48je31u9h5sailh7vkqvd9xcqtaqbjzbbfenzrhseob5amk7lgyjw5l2i0fhfpmupr8qqswqkf1xglzxmxfnvhdyyx9-cl6lapu4tgocxaakeyl_rx6ncw3skqj-tvllmpxa-9" class="anchor" href="#p-472268-h-624x280httpslh7-rtgoogleusercontentcomdocszad_4nxeanqfmbzcmltpbyz3d2tnokda2nw48je31u9h5sailh7vkqvd9xcqtaqbjzbbfenzrhseob5amk7lgyjw5l2i0fhfpmupr8qqswqkf1xglzxmxfnvhdyyx9-cl6lapu4tgocxaakeyl_rx6ncw3skqj-tvllmpxa-9"></a><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeAnQFmbzcMltPbYz3d2TNOkda2nW48je31U9h5sAIlh7vkqVd9XcqTAQbjZBBFEnZrhSeob5AMK7lgyjw5L2i0FHfPmUpR8QqSWQKf1XgLzXMXFnvHdyYx9--cl6LApU4TGoCxAA?key=l_rx6Ncw3SKqj-tVLlmPXA" alt="" width="624" height="280" role="presentation"></h2>
<p><em>Fig 4. FSDP all-gather collectives from T5 encoder are overlapped except the first one</em></p>
<h3><a name="p-472268-data-preprocessing-10" class="anchor" href="#p-472268-data-preprocessing-10"></a>Data Preprocessing</h3>
<p>In FLUX.1 model training, the text input will be encoded into encodings by 2 pre-trained, frozen text encoders: T5 text encoder and CLIP text encoder. The input image will also be encoded into latent space using frozen Variational AutoEncoder (VAE), and the VAE weights are loaded from the open-sourced <a href="https://huggingface.co/black-forest-labs/FLUX.1-schnell" rel="noopener nofollow ugc">version</a> from Black Forest Labs). This process is shared by all training runs, thus we could save end-to-end time by saving the pre-calculated encodings. We supported data preprocessing in TorchTitan. During preprocessing, the text encodings from 2 encoders are saved and written to disk. For the image encoder, instead of saving the encoded image latents, we save the mean and logarithmic variation of VAE. This is in order to still perform the usual behaviour of an VAE, where latents are not deterministically produced, but rather sampled from a Gaussian which it parametrizes.</p>
<p>One caveat is that the preprocessed data might take up a huge storage space, mainly because the generated t5 encoding is huge, with shape (seq_len, 4096). To fully store the preprocessed 12 million data samples from CC12M dataset with sequence length 256, it needs more than 12TB only for T5 text encodings. In our end-to-end training, we didn’t apply data preprocess because of the enormous storage it would take.</p>
<h2><a name="p-472268-end-to-end-training-on-torchtitan-11" class="anchor" href="#p-472268-end-to-end-training-on-torchtitan-11"></a>End-to-End Training on TorchTitan</h2>
<p>We also performed a large-scale pre-training of the FLUX.1[schnell] model, with TorchTitan implementation. In this training, we leveraged the open-source dataset Conceptual 12M (<a href="https://huggingface.co/datasets/pixparse/cc12m-wds/viewer/default/train?p=1" rel="noopener nofollow ugc">cc12m-wds</a>), which was originally developed and described in <a href="https://arxiv.org/abs/2102.08981" rel="noopener nofollow ugc">this paper</a>. Conceptual 12M (CC12M) is a dataset with 12 million image-text pairs specifically meant to be used for vision and-language pre-training.</p>
<p><strong>Training setup</strong></p>
<div class="md-table">
<table>
<thead>
<tr>
<th></th>
<th>Parameters</th>
</tr>
</thead>
<tbody>
<tr>
<td>Steps</td>
<td>40k</td>
</tr>
<tr>
<td>Batch size</td>
<td>Local batch size = 16, global batch size = 2048</td>
</tr>
<tr>
<td>Parallelism setting</td>
<td>dp_shard_degree = 8, dp_replicate_degree = 16 (total 128 GPUs)</td>
</tr>
<tr>
<td>Lr_schduler setting</td>
<td>Warmup step = 30k, no learning rate decay after stable stage. Max learning rate = 1e-4</td>
</tr>
<tr>
<td>Classifier free guidance setup</td>
<td>In training: dropout rate is 0.447, train unconditional model on ~20% data samples. In inference: classifer_free_guidance_scale = 5.0</td>
</tr>
</tbody>
</table>
</div><p>We have proposed this training setup based on relevant research<sup class="footnote-ref"><a href="#footnote-472268-7" id="footnote-ref-472268-7">[7]</a></sup> utilizing the CC12M dataset. The FLUX.1[schnell] model was trained using a total of 128 GPUs, with a global batch size of 2048. We also encourage users to explore the training setup with better performance using torchtitan. It is important to note that our end-to-end training employed only a portion of the CC12M dataset, rather than the complete dataset, due to an issue (<a href="https://github.com/huggingface/datasets/issues/7612" rel="noopener nofollow ugc">link</a>) in the dataloader. Subsequent runs have demonstrated a similar trend in loss convergence, indicating that the results here are meaningful and representative.</p>
<p><strong>Training loss curve</strong></p>
<p><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXeVlYyFU3fcZGXXeJ-aWzMAh7N3A7pJ5E8cK_A8FLnTCp0_z98dEUn-Gfqi75X8dsgBz8vP7umChCFLen4_5UeOrljvaIhtv6p_WNVZYBIIQ7w0yrdEnWwmCp2vjMAobudjRME3?key=l_rx6Ncw3SKqj-tVLlmPXA" alt="" width="624" height="245" role="presentation"></p>
<p><em>Fig 5. FLUX.1[schnell] model Training loss curve</em></p>
<p>We reported the training loss in Figure 5, which still shows a slight downward trend. This indicates that the model is continuing to learn and improve, and not fully converged yet. Due to computational resources and time constraints, we have only showcased the initial results, focusing on the convergence and correctness of the FLUX.1 model pre-training on TorchTitan. The training loss shown in Figure 3 represents the average loss across different noise levels during the diffusion steps within a training step. The averaged training loss would indicate the overall convergence level but might lack a detailed look at specific noise level.</p>
<p>To further enhance our evaluation, we are in the process of implementing validation loss measurements (as mentioned in <a href="https://arxiv.org/pdf/2403.03206" rel="noopener nofollow ugc">paper</a>) on a separate validation dataset. This will allow us to better assess the training process by providing insights into the model’s generalization capabilities and its performance on unseen data.</p>
<p><strong>Inference Results at different steps</strong></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/e/2e312a0a641ee4aaf0595efcd21ab95c81698217.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/2e312a0a641ee4aaf0595efcd21ab95c81698217" title="inference results"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/e/2e312a0a641ee4aaf0595efcd21ab95c81698217_2_365x500.jpeg" alt="inference results" data-base62-sha1="6ADirAdoXffUx0jr0ZpJId1QQkv" width="365" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/e/2e312a0a641ee4aaf0595efcd21ab95c81698217_2_365x500.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/2/e/2e312a0a641ee4aaf0595efcd21ab95c81698217_2_547x750.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/2/e/2e312a0a641ee4aaf0595efcd21ab95c81698217_2_730x1000.jpeg 2x" data-dominant-color="A8ABAC"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">inference results</span><span class="informations">1920×2644 389 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p><em>Fig 6. Inference result from TorchTitan trained FLUX.1[schnell] model</em></p>
<p>From the visualization results above, the trained FLUX.1 model could generate meaningful images based on the given prompt, with great details, such as “cherry blossoms” and “reflecting golden sky.” These results demonstrate the model’s ability to interpret and render complex scenes with impressive accuracy and aesthetic appeal. However, for some of the longer prompts, it failed to capture certain details. For example, when given the prompt “A space station orbiting a colorful nebula,” the model produced an image of a nebula but lacked details of a space station. This limitation might be attributed to insufficient training steps in our experiments, which could prevent the model from fully learning the nuances of more complex prompts. Additionally, the underlying distribution of the CC12M training dataset may have intrinsic differences from the given prompts, leading to a mismatch in the model’s ability to generalize to unseen or less frequent scenarios.</p>
<p>To address these challenges, future work could involve extending the training duration, diversifying the training dataset, or incorporating additional data augmentation techniques to better align the model’s learning process with the desired output characteristics. Furthermore, fine-tuning strategies could enhance the model’s capacity to handle intricate and detailed prompts more effectively.</p>
<h2><a name="p-472268-next-step-12" class="anchor" href="#p-472268-next-step-12"></a>Next Step</h2>
<p>In the next phase, we plan to improve the training of the FLUX.1 model in TorchTitan mode by adding more parallelism and features to ensure a seamless and user-friendly experience. Additionally, we aim to expand the use of FLUX.1 TorchTitan in collaboration with the open-source community.</p>
<ul>
<li>We collaborated with MLCommons and NVIDIA to develop the MLPerf training reference implementation for FLUX.1. This benchmark (<a href="https://github.com/pytorch/torchtitan/tree/mlperf-training-flux.1" rel="noopener nofollow ugc">link</a>) will be part of the MLPerf Training benchmark suite soon.</li>
<li>Expanding Parallelism Support: We plan to extend the current FSDP/HSDP parallelism framework to include parallelisms such as Tensor Parallel and Context Parallel.</li>
<li>Adding validation support: We will support diverse evaluation metrics for the FLUX.1 model on validation dataset, such as the validation loss, CLIP score, and FID score.</li>
<li>Adding torch.compile support: We will enable support for torch.compile on the FLUX.1 model to optimize performance and efficiency.</li>
</ul>
<h2><a name="p-472268-acknowledgment-13" class="anchor" href="#p-472268-acknowledgment-13"></a>Acknowledgment</h2>
<ul>
<li>We would like to express our gratitude to <a href="https://bfl.ai/models/flux-kontext" rel="noopener nofollow ugc">Black Forest Labs</a> for their significant contributions to the onboarding of FLUX to TorchTitan. Their technical expertise and collaborative efforts were instrumental in facilitating a successful integration and benefiting open-source users, and we are grateful for their support throughout this process.</li>
<li>We deeply appreciate <a href="https://mlcommons.org/" rel="noopener nofollow ugc">MLCommons</a> and <a href="https://www.nvidia.com/en-us/" rel="noopener nofollow ugc">NVIDIA</a> for their exceptional technical expertise and collaborative spirit, which played a crucial role in achieving a seamless integration. Their support has significantly benefited the open-source community, and we are thankful for their dedication throughout this journey.</li>
</ul>
<hr class="footnotes-sep">

<ol class="footnotes-list">
<li id="footnote-472268-1" class="footnote-item"><p> Song, Y., Sohl-Dickstein, J.N., Kingma, D.P., Kumar, A., Ermon, S., &amp; Poole, B. (2020). Score-Based Generative Modeling through Stochastic Differential Equations. ArXiv, abs/2011.13456. <a href="#footnote-ref-472268-1" class="footnote-backref">↩︎</a></p>
</li>
<li id="footnote-472268-2" class="footnote-item"><p>Ramesh, A., Dhariwal, P., Nichol, A., Chu, C., &amp; Chen, M. (2022). Hierarchical text-conditional image generation with clip latents. arXiv preprint arXiv:2204.06125, 1(2), 3. <a href="#footnote-ref-472268-2" class="footnote-backref">↩︎</a></p>
</li>
<li id="footnote-472268-3" class="footnote-item"><p>Singer, U., Polyak, A., Hayes, T., Yin, X., An, J., Zhang, S., … &amp; Taigman, Y. (2022). Make-a-video: Text-to-video generation without text-video data. arXiv preprint arXiv:2209.14792. <a href="#footnote-ref-472268-3" class="footnote-backref">↩︎</a></p>
</li>
<li id="footnote-472268-4" class="footnote-item"><p> <a href="https://bfl.ai/announcements/24-08-01-bfl" class="inline-onebox" rel="noopener nofollow ugc">Black Forest Labs - Frontier AI Lab</a> <a href="#footnote-ref-472268-4" class="footnote-backref">↩︎</a></p>
</li>
<li id="footnote-472268-5" class="footnote-item"><p>Radford, A., Kim, J. W., Hallacy, C., Ramesh, A., Goh, G., Agarwal, S., … &amp; Sutskever, I. (2021, July). Learning transferable visual models from natural language supervision. In International conference on machine learning (pp. 8748-8763). PmLR. <a href="#footnote-ref-472268-5" class="footnote-backref">↩︎</a></p>
</li>
<li id="footnote-472268-6" class="footnote-item"><p>Raffel, C., Shazeer, N., Roberts, A., Lee, K., Narang, S., Matena, M., … &amp; Liu, P. J. (2020). Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of machine learning research, 21(140), 1-67. <a href="#footnote-ref-472268-6" class="footnote-backref">↩︎</a></p>
</li>
<li id="footnote-472268-7" class="footnote-item"><p>Gu, J., Zhai, S., Zhang, Y., Susskind, J. M., &amp; Jaitly, N. (2023, January). Matryoshka diffusion models. In The Twelfth International Conference on Learning Representations. <a href="#footnote-ref-472268-7" class="footnote-backref">↩︎</a></p>
</li>
</ol>