← Back to blog
• Language models

GFusion: How we trained a diffusion LLM inside GigaChat

Valentin Mamedov

TeamLead MLE

I'd like to share a project I worked on during my internship on the GigaChat Pretrain team. For several months we explored diffusion language models (dLLMs) — a relatively new track in LLMs where many ideas are only just starting to be tested in practice.

The main goal was not to spend enormous resources on training from scratch, but to take the base autoregressive model GigaChat3-10B-A1.8B-base and convert it to diffusion mode. That's how our experimental GFusion-10B-A1.8B-base and GFusion-10B-A1.8B came to be!

TLDR

Before diving into the details, here are the key results of the project:

  • Faster generation. In single-user mode, GFusion is on average 70% faster than its sibling GigaChat3, and even outpaces the variant with an extra MTP head by 39%.
  • Model capabilities. GFusion achieves this speedup with a quality drop of only 2–4 p.p. compared to GigaChat3, and the trade-off can be controlled via the diffusion generation parameters.
  • Open source. We added GFusion support to SGLang, along with a new sampling algorithm that speeds up generation for other diffusion LLMs too.
  • Faster training. We optimized attention for text diffusion, which gave us a 60% boost in GFusion's average training speed compared to Flex-Attention.

Decode throughput comparison (OSL = 1024, concurrency = 1)

GigaChat3GigaChat3 + MTPGFusion
Decode TPS+0.0%+23.9%+73.7%+0.0%+21.6%+60.4%+0.0%+19.8%+75.1%
Math
Code
Chat

Generation speed of GFusion vs. GigaChat3 variants

Below, I'll walk through the full training cycle in more detail: which dLLM training approaches worked best, where the speedup comes from, and what limitations we ran into along the way.


Why diffusion?

Most modern LLMs are autoregressive (AR): each next token is predicted from the preceding context. This scheme is extremely well optimized in practice, but it has a fundamental limitation: strictly sequential generation, one token at a time.

Part of this limitation can be worked around with speculative decoding, where a smaller model proposes several consecutive predictions and the main model verifies them in a single pass. This yields a speedup, but the main model remains autoregressive no matter what.

Diffusion models relax this constraint: instead of working with a single next token, they operate on a partially masked block of fixed size. The model iteratively restores the masks, gradually turning the block into meaningful text. Tokens within a block can be decoded not only left to right, but in any order and several at a time per pass. The blocks themselves are still generated autoregressively, which makes it possible to reuse the KV cache for the already generated context.

Diffusion generation process, illustrated with a four-token block

Diffusion generation process, illustrated with a four-token block

If the model decodes several tokens per pass instead of one, generating the same sequence takes fewer forward passes. This is conveniently measured with the TPF (Tokens-Per-Forward) metric — the average number of tokens the model finalizes per pass.

In this framing, ordinary autoregressive generation can be viewed as a special case of diffusion with a block size of 1: the model generates exactly one token, so its TPF is always 1. The diffusion approach only pays off when TPF becomes noticeably greater than 1.

What we'll cover

The full GFusion training cycle consisted of the following stages:

  • Base pretraining: the bulk of adapting the AR model to diffusion generation.
  • Midtraining: a stage for boosting the model's capabilities and knowledge.
  • Context extension: growing the context window to 32k tokens.
  • SFT: teaching the model to follow instructions and formats.
  • Confidence tuning: a short post-SFT stage to speed up generation.

I won't go through every stage in detail; instead I'll focus on what is specific to dLLMs: pretraining experiments, decoding algorithms, and the speedup during SFT.

Adapting an AR model to diffusion

Recent dLLM papers propose plenty of different solutions: new loss functions, attention masks, noising strategies, and modeling approaches. Almost every paper shows its own approach winning, but comparisons are often run on different models, data, and training budgets. So we started by comparing the main options within a single, unified setup.

How is diffusion trained?

Suppose we have a source sequence from the training set:

From it, we obtain a noised version:

To do this, we first sample a noise level t ∈ (0, 1), then replace each token with a mask token with that probability. The model learns to restore the masked tokens, with access to the clean context before the current block and to the noised state of the block itself.

In our experiments, noise drawn from t ∼ 𝒰(0.25, 0.85) worked best.

The intuition is simple: with too little noise the task becomes almost trivial, and with too much it becomes excessively hard. The 0.25–0.85 range gives the model varying levels of difficulty without turning training into guessing almost the entire sequence from scratch.

Unlike standard AR training, the diffusion model receives as input

that is, not only the noised sequence but the original one as well.

This training scheme requires a special attention mask: tokens within a block must be able to interact with each other, while an autoregressive dependency is preserved between blocks. The loss is still ordinary cross-entropy, but we compute it only over the masked positions xt.

We also considered a hybrid setup in which an AR regularization term on the tokens of the original sequence x0 is added to the main diffusion loss. In this variant, the model simultaneously learns to restore masked tokens and to keep updating the context autoregressively.

Attention masks for different modeling approaches

Attention masks for different modeling approaches

Block size

The target block size is usually between 16 and 64 tokens. It has to be large enough for parallelism and potential speedup to appear, but not so large that the reconstruction task becomes impossible.

The simplest way to turn an AR model into a dLLM is to train it with the target block size right away. For an autoregressive model, however, this transition is too abrupt: the task changes from predicting a single next token to restoring an entire block.

A more stable option turned out to be gradually increasing the block size, for example:

In this regime, convergence improves noticeably and the model reaches higher metric values. With a block size of 1, the task almost coincides with autoregressive generation, so the transition from AR to dLLM is smoother. As the block keeps growing, the task gets progressively harder, forcing the model to restore more and more tokens per pass.

Effect of gradual block adaptation for a 3B model

Effect of gradual block adaptation for a 3B model

Modeling details

To train the model, you first need to choose the generation method. There are two main options:

  • Predict the next token if it is masked. This method makes better use of the original AR model's knowledge, since it was trained on almost the same task.
  • Predict the current masked token. This is the standard setup for modern dLLMs: the model restores the tokens at positions occupied by mask tokens.

Illustration of the modeling approaches

Illustration of the modeling approaches

We compared both options and saw no significant difference in results. In the end, we went with standard modeling — predicting the current masked token — since it is conceptually simpler and doesn't create extra problems at generation time.

Besides purely diffusion-based training, a hybrid setup is also possible. The idea is to add, with some weight λ, an autoregressive loss over the clean sequence x0 to the main dLLM loss, which is computed over the noised part of the input xt:

In this case, LAR acts as a regularizer that helps preserve the original AR model's knowledge, while the diffusion part learns to generate blocks.

Metric comparison for the standard and hybrid diffusion setups during pretraining

The hybrid setup did improve metrics in the early steps, but as training went on, the variant without the autoregressive component pulled clearly ahead. AR regularization helps early in adaptation, but at later steps it starts getting in the way of the model fully switching to diffusion mode. For the main training stage, we chose a purely diffusion-based loss.

Autoregression won't let go

Intuitively, tokens at the start of a block are much easier to predict, since they are closer to the already decoded context. If you look at the average step at which each token is finalized for a block of size 32, this hypothesis holds up in practice too.

Mean Unmask Step by Token Position

Mean Unmask Step1,481,882,212,622,963,413,814,224,685,035,425,786,176,576,917,287,688,058,388,789,149,489,8910,2410,5910,9111,2611,6111,9512,312,612,96
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Average step at which the mask token is decoded, by position

This observation suggests a mismatch between training and inference. At generation time, the model often sees blocks where the clean context is on the left and the masked tokens are on the right. During training, however, tokens are masked independently and uniformly, so the input distribution is different.

We tried several autoregressive sampling variants that make training examples look more like the generation regime. As with the extra AR loss, quality improved in the early steps but fell well behind uniform masking as training progressed.

Relative change in metrics when using autoregressive sampling

Pretraining stage

After these experiments, we settled on the final pretraining recipe: predicting the current masked token, gradually growing the block size, and the standard diffusion loss.

The model was initialized from the GigaChat3-10B-A1.8B-base weights and trained in several stages with a 4k-token context. For the initial block sizes of 1 and 2, we used an additional AR loss and then switched it off. The number of steps for each block size was chosen so that the model had time to adapt at every stage.

Learning Rate Schedule

B = 1B = 2B = 4B = 8B = 16B = 32Midtrain
Learning rate, ×10⁻⁶
Training step

Learning rate schedule for pretraining

The stage with block size 8 deserves a separate note. We saw noticeable metric dips there, so we decided to make it shorter. The likely reason is that at this block size the reconstruction task is already fairly hard, yet the block doesn't give the model enough context to decode it.

After base pretraining, we moved on to midtraining, where the focus shifted from adapting to diffusion mode to boosting the model's capabilities with higher-quality data. At this stage the model made 20k steps, and across both stages it saw about 530B tokens in total.

Decoding: where the speedup comes from

A trained model needs a sampling algorithm: after each step, it decides which mask tokens can be replaced with regular tokens and which cannot yet.

Most modern dLLMs use threshold sampling. With this method, a mask token is decoded only at positions where the probability of the most confident token exceeds a predefined threshold τ ∈ [0, 1). The algorithm is nice and simple, but it has one drawback: it treats each position independently of the others.

We decided to also look at an alternative approach from this paper — entropy-bounded sampling. First, we compute the entropy of the predicted distribution for each masked position. Then we decode tokens in order from the most confident to the more uncertain ones, until the accumulated entropy exceeds a predefined threshold γ ≥ 0.

Decoding quality–speed tradeoff by domain and sampler

AlgorithmThreshold-basedEntropy-bounded
DomainKnowledgeMathCoding
Threshold valueLowMidHigh
TPT
Benchmark score

Threshold vs. entropy-bounded algorithms for the post-midtraining checkpoint

We then compared both algorithms on our post-midtraining model. The EB sampler beat the baseline algorithm across the board — generation got faster, and the metrics went up too. The takeaway: the decoding algorithm directly determines both generation quality and how much speedup you can get. From then on, we used EB sampling everywhere.

Context extension

Next, we extended the model's context to a 32k-token window by further training it on 30B tokens of long examples. We used YaRN to interpolate RoPE from 4k to 32k.

This stage is less specific to diffusion generation, but it matters for practical use of the model and for further SFT training. Notably, after pretraining we managed to almost completely avoid quality loss compared to the autoregressive checkpoint.

Base models vs. GFusion-10B-A1.8B-base; * marks the autoregressive model.

SFT stage

Complementary masking

At the SFT stage, we used the idea of complementary masking. In our setup, the loss is computed only over masked positions, and the rest of the tokens go unused. As a fix, for each training example we add a paired example with the inverted mask: visible tokens get masked, and vice versa.

Example of applying complementary masking

Example of applying complementary masking

Interestingly, we got the best result after six epochs of training — twice as many as autoregression usually needs. The difference comes from the fact that in each epoch diffusion can mask the same example in many different ways, which reduces overfitting and lets us extract more signal from the data.

Confidence tuning (CT)

After SFT, we added a short stage to speed the model up further. To do this, we added an extra term to the loss that penalizes the model for high entropy of the distribution for correctly predicted tokens:

where 𝒯 is the set of correctly predicted tokens and β ≥ 0.

The more confident the diffusion model's predictions, the more positions EB sampling can decode in a single step. That raises TPF, and generating a response requires less compute.

That said, enabling CT right away would be a bad idea. Early in training, the model mostly predicts frequent words, punctuation, and obvious continuations correctly. If you start lowering entropy at the very beginning of SFT, you introduce a bias toward speeding up the generation of exactly these simple tokens.

In practice, β = 0.3 and 800 additional training steps worked best in terms of speedup without significant model degradation.

Results

We mainly compared the final GFusion variants with GigaChat3, as well as with other diffusion language models of similar size (LLaDA-MoE-7B, LLaDA2.0-mini preview). The results are shown below: the quality degradation relative to autoregression is indeed much more noticeable than after pretraining, but GFusion holds its own against comparable dLLMs.

Model comparison with GFusion-10B-A1.8B; * marks the autoregressive model

We separately measured GFusion's generation speed before and after the confidence tuning stage, using aiperf + SGLang in single-user mode (concurrency = 1) on 1×H100.

Decode TPS: GigaChat3, GFusion and GFusion-CT

GigaChat3GigaChat3 + MTPGFusion (γ = 0.50)GFusion (γ = 0.70)GFusion-CT (γ = 0.50)GFusion-CT (γ = 0.70)
Decode TPS+0%+24%+59%+72%+65%+74%+0%+22%+46%+52%+46%+60%+0%+20%+59%+71%+62%+75%
Math
Code
Chat

Decode TPS for GigaChat3, GFusion, and GFusion after confidence tuning

On average, GFusion-10B-A1.8B delivers +70% faster generation than GigaChat3-10B-A1.8B and even beats the MTP variant by +39%. Lowering the threshold γ to 0.50 slows the model down noticeably, but answer quality goes up.

Infrastructure

SGLang

To make GFusion easy to use, we added support for it to SGLang. To run MLA in diffusion mode with an attention head size of 192 (not a power of two), we had to implement the missing logic for the Flash-Attention backend.

We also added a new entropy-bounded sampling algorithm. It performs better in both speed and quality not only for GFusion but for other diffusion language models in SGLang, too.

Speeding up training

Diffusion training requires a custom attention mask, so Flash-Attention is off the table. PyTorch's Flex-Attention handles exactly this case and computes attention efficiently with an arbitrary mask, but in our case training was still far from optimal.

We wrote our own kernel implementation in TileLang that natively exploits the clear structure of the diffusion mask. This gave us a +41.7% and +77.4% end-to-end speedup when training with 4k- and 32k-token contexts, respectively. We are also releasing all implementations publicly.

Block-causal Attention Performance

Flex · 4kCustom · 4kFlex · 32kCustom · 32k
Time (ms)401.46x1301.51x1802.16x6502.23x2181.99x7802.06x
Forward
Backward
Forward + Backward

Flex-Attention vs. our TileLang implementation


Conclusions

In the GFusion project, we tried to train our own model and get a speedup over autoregression, but also to dig a bit deeper into how individual components affect different training stages, compare known approaches consistently, and assess their applicability.

The most valuable part of the project turned out to be not the result itself, but the chance to go all the way from designing ML experiments to solving the engineering challenges needed to turn an idea into a working model.

If you're interested in LLMs and everything around them, from experimental ML features and architectures to low-level infrastructure and model optimization. Come join GigaChat projects!