iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🥞

Just Image Transformer: Predicting Real Images in Pixel Space with Flow Matching

に公開

Overview

https://arxiv.org/abs/2511.13720

  • JiT (Just image Transformer) performs flow-matching in pixel space without using a VAE.
  • The model achieves better performance by predicting the actual image x rather than predicting velocity v (x-pred).
  • However, it is better to calculate the loss using the velocity v derived from the actual image x and the noisy image z (v-loss).

Introduction

Image generation models based on diffusion, such as Stable Diffusion, have primarily been U-Net based models. The derivative SDXL is still a base model used as of December 2025 due to its ease of handling.

Recently, in addition to these, diffusion models that primarily use Transformers—starting with DiT—such as Flux.1, Qwen-Image, and Z-Image, have become widely used due to the high quality of their generated images.

A common feature of these diffusion models is that they generate (latent) images in latent space using a VAE.

On the other hand, the Just image Transformer introduced here is a model that does not use a VAE and predicts actual images in pixel space. In this article, we will review the basic prerequisites and explain how this was achieved and the mechanisms behind it.

Review of Prerequisites

Let's briefly review the prerequisite technologies and related methods.

  • Image Generation

    • DDPM: Denoising Diffusion Probabilistic Models
      • → Proposed diffusion models.
      • Adopts U-Net.
      • Learns the reverse of the process where images become noise (reverse diffusion process).
      • The model predicts noise \epsilon in pixel space (eps-pred).
        • Challenge: High computational cost for high-resolution generation.
        • Calculates loss using predicted noise and ground-truth noise \epsilon (eps-loss).
    • LDM: Latent Diffusion Model
      • → Reduces computational cost by compressing images into latent space using a VAE!
      • Adopts VAE in addition to U-Net.
      • Learns the reverse diffusion process.
      • The model predicts noise \epsilon in latent space (eps-pred).
      • Calculates loss using predicted noise and ground-truth noise \epsilon (eps-loss).
    • Velocity Prediction: Imagen Video, SD2.1, NAI Diffusion V3, etc.
      • → Predicts velocity instead of noise.
      • Adopts VAE in addition to U-Net.
      • Learns the reverse diffusion process.
      • The model predicts velocity v in latent space (v-pred).
      • Calculates loss using predicted noise and ground-truth velocity v (v-loss).
    • DiT: Scalable Diffusion Models with Transformers
      • → Replaces the U-Net of LDM with a Transformer.
      • Adopts a modified Transformer; VAE remains.
      • Uses VAE to compress into latent space.
      • Learns the reverse diffusion process.
      • The model predicts noise \epsilon in latent space (eps-pred).
      • Calculates loss using predicted noise and ground-truth noise \epsilon (eps-loss).
    • Post-MMDiT: SD3, Flux.1, Qwen-Image, Z-Image, etc.
      • → Simplified flow-matching formulas are trendy.
      • Adopts modified Transformers; VAE remains.
      • Uses VAE to compress into latent space.
      • Learns the flow from noise to image (flow-matching).
      • The model predicts velocity v in latent space (v-pred).
      • Calculates loss using predicted velocity and ground-truth velocity v (v-loss).
  • Image Recognition

Why is a VAE used?

The adoption of VAEs, which began with LDM, was introduced for the purpose of reducing computational cost in high-resolution image generation. A VAE compresses images in pixel space into a latent space, and the model then performs prediction and denoising in that latent space.

To see how much it is compressed, for example, SD-VAE increases the number of channels from 3 to 4 when compressing an image, but the height and width become 1/8. As a result, it is 1/8 * 1/8 * 4/3 = 1/48, which can reduce the original computational cost to about 2%.
In addition, the Flux.1 VAE, which is frequently adopted recently, also has a height/width of 1/8, but the number of channels becomes 16, so it becomes 1/8 * 1/8 * 16/3 = 1/12, which is about 8%.

Since computational cost can be reduced by using a VAE in this way, it becomes possible to generate high resolutions with the same computational budget compared to when not using a VAE. Although the initial goal was to reduce computational cost, if the quality of the VAE itself is poor, it becomes a bottleneck when decoding from latent space to pixel images, and fine details may be crushed no matter how much effort the main model puts in. Therefore, the performance of the VAE itself significantly affects the quality of the generated images. Flux.2 seems to be working hard to improve VAE quality.

Just image Transformer

https://arxiv.org/abs/2511.13720

https://github.com/LTH14/JiT


Image generated with JiT-H/32 at 512x512 resolution

Regarding the authors of the paper, Tianhong Li is the lead author of MAR and its pixel-space version FractalMAR, and Kaiming He is the author of ResNet.

Below, I explain what JiT does and how it works.

Manifold Hypothesis

Since it concerns the fundamental design of the model, let's first explain the manifold hypothesis.


From JiT Paper Figure 1

The manifold hypothesis posits that (in the context of images) natural images exist on a low-dimensional "manifold" within the high-dimensional pixel space. Clean images x without noise can be considered as existing on the manifold, whereas noise \epsilon or velocity fields v (expressed as v = x - \epsilon) can be considered as not existing on the manifold.

In essence, I believe this means that ordinary images we see generally are distributed only in a certain portion of the vast combinations of possible pixels, whereas random noise or representations involving noise are not. It makes sense, as generating pixels randomly won't produce meaningful pictures.

Reference:
https://xtech.nikkei.com/dm/atcl/mag/15/00144/00031/

Therefore, the idea that predicting real images, which are inherently low-dimensional, is actually easier for the model than predicting high-dimensional noise becomes important.

JiT leverages this insight.

Architecture


Simple architecture diagram

Since JiT does not use a VAE, it has a simple structure like this.

The input noisy image is first divided into multiple patches. Then, it passes through Linear Embed (the so-called Patch Embedding layer) to increase the channel count, goes through Transformer Blocks several times, and finally, a Linear Predict layer converts it back to the original channel count before reshaping the predicted patches back into an image.

First, let me explain what is done during patchification.

Patchify

Patchification is a process performed to handle images efficiently with Transformers, and it was adopted in ViT (Vision Transformer), a model that performs image classification using Transformers. This process itself is also used in DiT.


From DiT Paper Figure 4

As shown in the image, an I \times I size image is divided into patches of side p, and each patch is treated as a token.

If you treat one pixel as one token without patchification, you get I^2 tokens, and since Transformers (or rather, Attention) have a computational complexity proportional to the square of the sequence length T, it becomes clear that this is extremely computationally expensive.
For example, with a 256x256 image, T = 256 \times 256 = 65,536 tokens, and the computational complexity would be 65,536^2 = 4,294,967,296.

On the other hand, you can shorten the sequence length by dividing the image into patches. If the patch size is p = 16, a 256x256 resolution image can be handled as 16x16 patches, so T = 16 \times 16 = 256, and the computational complexity becomes 256^2 = 65,536.

ViT often uses patch sizes of 16 or 14. DiT experimented with patch sizes of 8, 4, and 2, and showed in experiments that the smaller the patch size, the better the performance (though computational cost increases).
My personal interpretation is that since DiT is already compressed to 1/8 by the VAE, patchifying it further might make learning more difficult.


Modified from DiT Paper Figure 7

Models since MMDiT, such as SD3, Flux.1[1], Qwen-Image, and CogView4, follow this trend and adopt patch size 2.

In contrast, JiT, which does not use a VAE, primarily experimented with patch size 16. In this case, a 256x256 resolution image results in 16 \times 16 = 256 tokens. (So, "An Image is Worth 16x16 Words" indeed.)

Bottleneck Layer

After patchifying, it is necessary to align the hidden dimensions for processing through the Transformer. Instead of projecting directly to the hidden dimension, the model first projects to a smaller bottleneck dimension and then to the hidden dimension.


Dimensional changes per patch. An RGB 256x256 image with 3 channels is first divided into 256 patches of 3x16x16. Each patch is flattened to channels x patch_size x patch_size (3x16x16) and projected to a bottleneck dimension of 128. Finally, it is projected to a hidden dimension of 768. (The coincidence between the flattened dimension and the hidden dimension is incidental.)

In other words, rather than using a single linear layer in the Patch Embedding to project to the hidden dimension, two layers are used: the first projects to a lower rank, and the second restores it to the hidden dimension. While the final hidden dimension remains the same, the bottleneck restricts the rank.

However, the official code uses a Conv layer for computation:

Bottleneck Code

What it does is the same as explained above, but according to Gemini, using Conv is more efficient when computing on a GPU.

https://github.com/LTH14/JiT/blob/cbc743a2ada5e9762697da2c83f8c4f8379e8c17/model_jit.py#L17-L37

Notably, there is no activation function between proj1 and proj2. While it is typical to include an activation function in an MLP, it is omitted here, simply projecting via low-rank matrices. According to MobileNetV2, not including an activation function has the advantage of not destroying the manifold.

The graph below shows changes in quality when changing the bottleneck size. (Lower FID indicates better performance.)


From JiT Paper Figure 4. The dashed line is the baseline without a bottleneck. The blue graph represents the FID when changing the bottleneck size.

Since it is based on JiT-B/16, the 16x16 patches would be 768 dimensions if handled directly. Even when the bottleneck size was reduced to 16, there was some minor performance degradation, but no catastrophic collapse occurred. Furthermore, when the bottleneck size was 32-512, performance improved compared to not using a bottleneck at all.

Lowering the dimension improving performance might seem counterintuitive at first, but it is a common technique when learning low-dimensional representations. Personally, I was reminded of LoRA, which seems to have the effect of preventing memorization and making it easier to generalize. Also, the fact that it shares similarities with the linear bottleneck method adopted in MobileNetV2 suggests that "the dimension required to decompose natural data representation is not actually that large." This is consistent with the manifold hypothesis, suggesting that the distribution of real images can be fully represented in a lower dimension.

MobileNetV2 reference:

https://deepsquare.jp/2020/06/mobilenet-v2/#outline__2_2_2

Additionally, as an experiment supporting this, the following compares performance when keeping the base model size and image sequence length fixed while changing the patch size and image resolution:


From JiT Paper Table 5. Changes in FID when only the image resolution and patch size (the 16 in JiT-B/16) were changed.

When using patch size 64 at 1024x1024 resolution, the dimension of one patch before passing through the bottleneck (128-dimensional) is 3 \times 64 \times 64 = 12288. Although the dimension becomes overwhelmingly higher compared to when using patch sizes 16 or 32, the FID degraded only to an acceptable degree, and did not result in the collapse seen in \epsilon,v\text{-pred} models.

Although there is some degradation, it is a viable option to increase the patch size since you can generate higher resolution images with similar computational costs.

Flow-Matching Predicting Real Images

JiT is a model that performs flow-matching.

Standard Flow-Matching

In flow-matching, we learn the flow from the distribution of noise \epsilon to the distribution of real images x. The noisy image z_t at time t during the flow can be expressed as a linear interpolation between noise \epsilon and real image x:

z_t = tx + (1 - t) \epsilon

Thus, at time t = 0, z_t is pure noise, and at time t = 1, z_t is a clean real image. In general flow-matching models, the standard approach is to learn the velocity field v = x - \epsilon from noise to image at time t. The velocity field v can also be obtained by differentiating z_t with respect to time t:

\begin{aligned} v = z_t' &= t' x + (1 - t)' \epsilon \\ &= x - \epsilon \end{aligned}
Explanation for a beginner

Think of moving from noise \epsilon to the goal, the image x, over a time interval t = 1. The distance covered is x - \epsilon. Since the relationship between velocity, distance, and time is \text{velocity} = \text{distance} / \text{time}, and given the distance is x - \epsilon and time t = 1, the velocity v is:

\begin{aligned} v &= (x - \epsilon) / t \\ &= (x - \epsilon) / 1 \\ &= x - \epsilon \end{aligned}

If we know the velocity v at the current position z_t, we can determine the direction and speed to reach x, so by calculating z_t + v(1 - t):

\begin{aligned} z_t + v (1 - t) &= [tx + (1 - t)\epsilon] + (1 - t)(x - \epsilon) \\ &= (t + 1 - t) x + [1 - t - (1 - t)] \epsilon \\ &= x \end{aligned}

we can obtain the clean image x.

Thus, flow-matching can be solved if we can determine the velocity v from the noisy image z_t at time t. Correspondingly, the straightforward approach is for the model to predict the velocity v, taking the squared error between the predicted velocity v_\theta and the ground truth velocity v as the loss function \mathcal{L}_{t,x,z}:

\mathcal{L}_{t,x,z} = \mathbb{E}\|v_\theta(z_t, t) - v\|^2

However, from our discussion so far, I hope it is clear that this should not be done. If the manifold hypothesis holds true, it should be easier for the model to predict the real image x rather than the velocity v. Let us verify if this actually simplifies the task.

Experiment on Model Prediction Targets

To verify whether it is truly easier for the model to predict the real data x, JiT conducted experiments using a simple toy dataset. (All losses used here are v\text{-loss}, which will be described later.)

The following shows the generation results using a 5-layer MLP with ReLU (hidden dimension 256) trained on D-dimensional synthetic data assuming a manifold.

Dataset Settings
  • Manifold data: \hat{x} \in \mathbb{R}^d (d is smaller than D, always low-dimensional. In experiments, d = 2)
  • Observable data: x = P\hat{x} \in \mathbb{R}^D (D-dimensional, with D \in \{2, 8, 16, 512\} in experiments)

P_{d \times D} is a matrix projecting from d to D dimensions, which is a column-orthogonal matrix such that P^\top P = I_{d \times d}. This matrix is randomly initialized and fixed during training.

By setting it up this way, the assumption of the manifold hypothesis—that the data is low-dimensional in reality but observable in a high-dimensional space—is reproduced.


From JiT paper Figure 2. When the D dimension is small, generation is successful regardless of whether x\text{-pred}, \epsilon\text{-pred}, or v\text{-pred} is used. However, as the D dimension increases, \epsilon\text{-pred} and v\text{-pred} collapse, while only x\text{-pred} achieves satisfactory generation.

When D = 512, the dimension exceeds the MLP's hidden dimension of 256, suggesting it should suffer from insufficient expressive power. Nevertheless, x\text{-pred} generates the data correctly, supporting the result that predicting real data is superior for learning the low-dimensional space on the manifold.

Various Loss Formulations

While it is clear that predicting real data x is promising, it is not necessarily required to take the loss on x itself. Specifically, it is possible to calculate the noise \epsilon or velocity v from the predicted real image x.


From JiT paper Table 1. This shows combinations of losses where the model \text{net}_\theta predicts real images x_\theta, \epsilon_\theta, or v_\theta.

Example of calculating vθ from xθ

First, as confirmed earlier:

  • z_t = tx + (1 - t) \epsilon
  • v = x - \epsilon

We derive the formula for noise \epsilon, an unknown parameter (which is not in the model input, so it cannot be known during inference). Transforming the equation for z_t:

\begin{aligned} z_t &= tx + (1 - t) \epsilon \\ (1 - t) \epsilon &= z_t - tx \\ \epsilon &= (z_t - tx) / (1 - t) \end{aligned}

Substituting this into the second equation:

\begin{aligned} v_\theta &= x - (z_t - tx) / (1 - t) \\ &= \frac{x(1-t)}{1 - t} - \frac{z_t - tx}{1 - t} \\ &= \frac{x(1 - t + t) - z_t}{1 - t} \\ &= (x - z_t) / (1 - t) \end{aligned}

By replacing x with x_\theta, we obtain:

v_\theta = (x_\theta - z_t) / (1 - t)

It matches the formula in the table.

As shown, when the model predicts any of the real image, noise, or velocity, it is possible to derive the others using only known information. Since the loss target can be calculated similarly, one can compute losses with arbitrary targets. Therefore, the model does not necessarily need to predict the desired parameters directly; it can achieve the same computation indirectly by predicting other parameters.

However, what is the best combination? Since I have repeatedly stated that predicting real images is simpler, is it best to predict the real image and take the loss on the real image?

Actually, it is slightly different. Below is a comparison of FID scores trained on ImageNet based on JiT-B using various model predictions and loss combinations.


From JiT paper Table 2. (b) When learning 64x64 ImageNet with JiT-B/4 (patch size 4), all x\text{-pred}, \epsilon\text{-pred}, and v\text{-pred} achieve low FIDs, with \epsilon\text{-loss} and v\text{-loss} performing particularly well. (a) On the other hand, when learning 256x256 ImageNet with JiT-B/16 (patch size 16), \epsilon\text{-pred} and v\text{-pred} show significantly higher FIDs than x\text{-pred}, indicating a catastrophic failure in training. While x\text{-pred} with v\text{-loss} achieves an even lower FID, it does not fully prevent the collapse of \epsilon\text{-pred} and v\text{-pred}.

Reading this table, we understand that:

  • Model prediction: Real image prediction x\text{-pred} performs overwhelmingly better than noise prediction \epsilon\text{-pred} or velocity prediction v\text{-pred}.
  • Loss target: Using velocity v for the loss results in slightly better performance than using the raw real image x or noise \epsilon directly.

Furthermore, the fact that v\text{-loss} does not fully save \epsilon\text{-pred} and v\text{-pred} from collapse is consistent with the results of the toy dataset experiment.

However, why does this happen? We already established that predicting real images is easier because they lie on the manifold, but the loss is only better with velocity v compared to the others.

Checking the table of loss target calculations again, the loss targets are represented as follows:

  • Model prediction (real image): x_\theta = \text{net}_\theta(z_t, t) (where t is time and z_t is the noisy image at that time)
  • Real image: x_\theta (raw)
  • Noise: \epsilon_\theta = (z_t - t x_\theta) / (1 - t)
  • Velocity: v_\theta = (x_\theta - z_t) / (1 - t)

According to the paper's authors, in the case of velocity loss, the part calculating the difference with the model's input z_t can be viewed as a long residual connection from the model's input to output, which is scaled by time t.

I initially thought the noise loss \epsilon_\theta = (z_t - t x_\theta) / (1 - t) also contained z_t, but since the model prediction x_\theta is multiplied by time t here, when t \sim 0, the target becomes correct regardless of how inaccurate the prediction is, which I suspect makes it less efficient.

Loss Implementation

From the above, we have found that it is optimal to predict the real image x with the model and compute the loss using the velocity v. The loss function shown in the paper is ultimately as follows:

\mathcal{L} = \mathbb{E}_{t,x,\epsilon}\left\|v_\theta(z_t, t) - v\right\|^2, \\ \text{where:} \quad v_\theta(z_t, t) = (\mathtt{net}_\theta(z_t, t) - z_t) / (1 - t)

The implementation in PyTorch is as follows:

https://github.com/LTH14/JiT/blob/cbc743a2ada5e9762697da2c83f8c4f8379e8c17/denoiser.py#L49-L65

Personally, I think it is great that this can be achieved with such a simple change.

Looking closely at the part creating v_pred:

v_pred = (x_pred - z) / (1 - t).clamp_min(self.t_eps)

It uses .clamp_min(self.t_eps), ensuring that the value of (1 - t) is at least self.t_eps. This is done to prevent numerical instability when the denominator approaches 0 as t \sim 1; self.t_eps = 0.05 is used in the paper.

While clamp allows for stable training, it turns out that not using clamp during inference leads to better quality:

https://github.com/LTH14/JiT/issues/24

I suspect this is because when increasing the number of inference steps, if one accidentally clamps to 0.05 when denoising a time step smaller than 0.05, it results in an incorrect denoising distance. (For example, with 25-step generation, one step denoises by 1/25 = 0.04 time steps.)

Changes Inside the Architecture

Although JiT is based on DiT, the following elements have been incorporated:

  • SwiGLU
  • RMSNorm
  • RoPE
  • QKNorm
  • CFG interval
  • In-context class tokens

The following is a comparison of performance when adopting each of these.


JiT paper Table 4. Adopting RoPE, QKNorm, and in-context class tokens leads to a lower FID compared to the baseline (SwiGLU, RMSNorm). Parentheses indicate cases with CFG interval applied.

I will explain the less common CFG interval and in-context class tokens.

CFG Interval

https://arxiv.org/abs/2404.07724

https://github.com/kynkaat/guidance-interval

In short, by limiting the time steps where CFG is applied, this technique prevents color saturation and loss of diversity even when using a high CFG scale, allowing for more detailed generation.


Official GitHub

While the original research was intended for diffusion, it appears usable with flow-matching as well; the JiT paper and its official implementation apply CFG only when the time step t \in [0.1, 1].

https://github.com/LTH14/JiT/blob/cbc743a2ada5e9762697da2c83f8c4f8379e8c17/denoiser.py#L101-L102

In-context Class Tokens

In ViT, a class token representing the image category is added once to the patch sequence and input into the Transformer. (Including it in the sequence is what is meant by "in-context"). DiT also experimented with processing class and time information via in-context methods, but ultimately settled on using only AdaLayerNorm-Zero.

In contrast, JiT replicates the class token several times, adds dedicated positional embeddings, and then includes them in the sequence. In the paper, the class token is repeated 32 times.

https://github.com/LTH14/JiT/blob/cbc743a2ada5e9762697da2c83f8c4f8379e8c17/model_jit.py#L349-L351

Furthermore, it was found that performance improved by inserting these conditions from midway through the Transformer blocks rather than starting from the first block. (This method is called "in-context start block"). In the experiments, they are inserted approximately at the 1/3 point of the model block count.
However, a comparison demonstrating the effect of this trick was not found in the paper.

Training Optimizations

Time Step Sampling

JiT samples the time step t as follows:

https://github.com/LTH14/JiT/blob/cbc743a2ada5e9762697da2c83f8c4f8379e8c17/denoiser.py#L45-L47

In the paper, P_mean = -0.8 and P_std = 0.8 are used.

Visualizing the distribution looks like this:


Created by ChatGPT based on the sampling function above

Visualization code by ChatGPT
# Visualize the distribution of t = sigmoid(z) where z ~ N(P_mean, P_std^2)

import torch
import matplotlib.pyplot as plt

def sample_t(n: int, P_std: float, P_mean: float, device=None) -> torch.Tensor:
    z = torch.randn(n, device=device) * P_std + P_mean
    return torch.sigmoid(z)

# Parameters
P_std = 0.8
P_mean = -0.8
n = 100000

# Sample
t = sample_t(n, P_std, P_mean)

# Plot
plt.figure()
plt.hist(t.numpy(), bins=100, density=True)
plt.xlabel("t = sigmoid(z)")
plt.ylabel("Density")
plt.title("Distribution of t for P_std=0.8, P_mean=-0.8")
plt.show()

As seen in the graph, t is skewed to the left, meaning it focuses training on the noise-heavy side. Since prediction near real images is likely easier, it prioritizes learning the more difficult noisy side.

Noise Scale

Noise used in training and inference is sampled from a normal distribution, but is scaled according to resolution:

https://github.com/LTH14/JiT/blob/cbc743a2ada5e9762697da2c83f8c4f8379e8c17/denoiser.py#L53

self.noise_scale is defined as 1.0 \times \text{image\_size} / 256; it is 1.0 for 256x256 resolution, and 2.0 for 512x512.

Conclusion

Based on the manifold hypothesis, JiT demonstrated the following:

  • Real data prediction (x-pred) is paramount.
  • Velocity loss (v-loss) is effective, but not critical (it cannot save \epsilon-pred or v-pred from collapse).
  • Bottlenecks are effective.

Impressions

Personally, it completely flipped my assumptions that "if you follow the formulas, it doesn't matter what the model predicts or what the loss target is," "flow-matching naturally predicts velocity," "real image prediction is too difficult to attempt," and "high-resolution generation without a VAE is impossible due to computational costs." It is fascinating. Also, realizing generation in pixel space with only simple changes while incorporating modern improvements is cool. While other pixel-space generation methods like PixelDiT were released around the same time, it is impressive that JiT achieves this with such a simple approach.

脚注
  1. In public code, it appears as patch_size = 1, but it performs equivalent processing to patch_size = 2 under a different name called packing. ↩︎

GitHubで編集を提案

Discussion