FLUX.2 [klein] 4B Trim17

An unofficial, depth-pruned version of black-forest-labs/FLUX.2-klein-4B. The denoiser keeps 17 of its 25 transformer blocks. Two small linear "bridges" stand in for the removed blocks, and the kept blocks were fine-tuned (healed) against the original model. On an AMD Ryzen AI NPU it makes a 512 Γ— 512 image 1.32Γ— faster than the full model, at a clear but moderate loss of fidelity.

This is a research result, kept here so it is not lost. It is not a drop-in replacement for FLUX.2 [klein]: it needs a forward pass that skips the removed blocks and applies the bridges (see How it runs). The text encoder, VAE, and every other part of the pipeline are the stock FLUX.2 [klein] 4B ones and are not included here.

FLUX.2 [klein] 4B Trim17
Transformer blocks 5 double-stream + 20 single-stream 5 double-stream + 12 single-stream
Extra parameters – 2 bridges Γ— 4 steps Γ— 3072 Γ— 3072
NPU time, 512Β², 4 steps (HX 370) 3.836 s 2.904 s
Image difference from the original (mean abs. pixel error, 0–255) 0 26.8 (GPU bf16), 27.0 (NPU Q8_0)

Overhead view: original, skip only, ridge bridge, healed A middle aged man: original, skip only, ridge bridge, healed

Columns: the original 25-block model; 17 blocks with the removed blocks simply skipped; 17 blocks with the untrained (ridge-fitted) bridges; 17 blocks healed (this model). All on the NPU, same seed.

Files

File What it is
trim17_blocks.safetensors The 17 kept, healed blocks (bf16), with diffusers names (transformer_blocks.{0-4}.*, single_transformer_blocks.{j}.*). Load them over the stock transformer.
trim17_bridges.safetensors Bridge matrices 13_15_s{0-3} and 17_21_s{0-3} (fp32, 3072 Γ— 3072, one per gap and denoising step), plus gate_s{0-3}, used only by the NPU kernel layout.
trim17_config.json Kept and removed blocks, gaps, the 4 timesteps, the bridge formula.
flux-2-klein-4b-trim17-Q8_0.gguf The whole transformer as Q8_0 GGUF, with the healed blocks written in. The removed blocks are still in the file (stock weights) but are not run. Used by the NPU runtime.

How it runs

Blocks are numbered 0–24: 0–4 double-stream, 5–24 single-stream (block i β‰₯ 5 is single_transformer_blocks[i - 5]). Removed: 13, 14, 15 and 17, 18, 19, 20, 21. Kept: 0–12, 16, 22, 23, 24.

Each gap is replaced by one bridge, applied just before the first block after the gap (before block 16 and before block 22):

zn = LN(x) * (1 + scale) + shift        # LN = single_transformer_blocks[0].norm,
                                        # (shift, scale) = the step's single-stream modulation
x  = x + zn @ W[gap][step]              # W: 3072 x 3072, a different matrix per step

The bridges are tied to the four fixed timesteps of FLUX.2 [klein]'s 4-step schedule at 512 Γ— 512 (t = 1.0, 0.9609375, 0.8828125, 0.71484375). Other step counts were only spot-checked (see below).

A sketch of the forward pass with diffusers' Flux2Transformer2DModel, adapted from the training code (the training code is tested; this standalone sketch is not):

KEEP = [*range(13), 16, 22, 23, 24]
BRIDGE_BEFORE = {16: "13_15", 22: "17_21"}

def forward(tr, ctx, x_img, t, rope, W, step):
    temb = tr.time_guidance_embed(t * 1000, None)
    mod_img, mod_txt = tr.double_stream_modulation_img(temb), tr.double_stream_modulation_txt(temb)
    mod_sgl = tr.single_stream_modulation(temb)
    blocks = list(tr.transformer_blocks) + list(tr.single_transformer_blocks)
    state = (ctx, tr.x_embedder(x_img))
    for k in KEEP:
        if k == 5:
            state = torch.cat(state, dim=1)
        if k in BRIDGE_BEFORE:
            shift, scale, _ = Flux2Modulation.split(mod_sgl, 1)[0]
            zn = (1 + scale) * tr.single_transformer_blocks[0].norm(state) + shift
            state = state + (zn.float() @ W[f"{BRIDGE_BEFORE[k]}_s{step}"]).to(state.dtype)
        if k < 5:
            state = blocks[k](hidden_states=state[1], encoder_hidden_states=state[0], temb_mod_img=mod_img,
                              temb_mod_txt=mod_txt, image_rotary_emb=rope, joint_attention_kwargs=None)
        else:
            state = blocks[k](hidden_states=state, encoder_hidden_states=None, temb_mod=mod_sgl,
                              image_rotary_emb=rope, joint_attention_kwargs=None)
    return tr.proj_out(tr.norm_out(state[:, ctx.shape[1]:], temb))

On the NPU, the bridge is one extra GEMM per gap per step, and its residual add reuses the existing residual + LayerNorm kernel (that is what the gate_s* vectors are for).

The plan

The question was how far the denoiser can be cut, and how cheaply the damage can be repaired. The work went in four stages, each one gating the next:

  1. Screen. Remove one block at a time and measure how much the velocity changes. This gives an order of which blocks matter least.
  2. Cut without training. Remove the top N of that order and look at full images, to find where quality falls off a cliff.
  3. Cheap repair. Replace each removed run of blocks with a linear map fitted by ridge regression (a "bridge"), and see how far that moves the cliff.
  4. Heal. Train against the original model, starting from the bridges, and see how close the pruned model can get with a few hours of rented GPU time.

The total budget was small (about $26 of rented GPU time in total), so every stage was sized to answer one question.

Sweeps and results

All image numbers are mean absolute pixel error (0–255) against the original 25-block model on the same path, seed and prompt ("MAD"; lower is closer). For scale: changing the seed gives about 51. Velocity error is relative (β€–v_student βˆ’ v_teacherβ€– / β€–v_teacherβ€–), averaged over steps.

1. One-block screen (teacher-forced, 10 prompts, 512Β², 4 steps)

Region Blocks Velocity error when removed
Double-stream, first 0 0.86
Double-stream, middle 1–3 0.43–0.47
Double-stream, last 4 0.78
Single-stream 0–7 5–12 0.33–0.47
Single-stream 8–17 13–22 0.24–0.30
Single-stream, last two 23, 24 0.68, 0.53

Least important first: 18, 15, 19, 17, 20, 21, 14, 13, 16, 22, … The middle of the single-stream stack is the cheapest to remove, and the order was stable across prompts (for 8 of 10 prompts the 8 least important blocks all fell in 13–22). The first and last blocks matter most.

2. Removing blocks without training

Blocks kept Removed MAD (CPU) MAD (NPU) Reading
24 18 16.9 17.3 near identical
23 15, 18 24.8 23.8 same content, small changes
21 15, 17–19 34.1 31.5 usable; colors and faces drift
19 15, 17–21 46.9 40.1 broken: haze, low contrast
17 13–15, 17–21 54.9 45.5 broken
15 13–22 53.7 47.5 grey-brown fog

Without training the limit is 21–23 blocks. The failure is a wash toward grey (low contrast, fog), not noise or a wrong layout, which suggested that a cheap linear correction could fix much of it.

3. Linear bridges (ridge fit, no training)

One 3072 Γ— 3072 matrix per gap and per step, fitted on 40 prompts and checked on 8 others.

Blocks kept Skip only MAD Bridge MAD
21 31.5 22.9
19 40.1 26.0
17 45.5 31.5
15 47.5 34.0

The bridge moves the cliff by 4–6 blocks: 19 blocks + bridge beats 23 blocks without one. A linear map still misses 52–75% of the gap's change, but images improve far more than that suggests, which fits the idea that the bridge fixes the systematic (grey-wash) part of the error.

4. Healing

Run Blocks What was trained Loss GPU, time Velocity error MAD
ridge only 15 – – – 0.562 36.1
run1 "local" 15 bridges + LoRA r32 on 2 blocks match the state after block 23 3090, 30 min 0.548 35.8
run1 "global" 15 bridges + LoRA r32 on 2 blocks match the final velocity 3090, 30 min 0.485 30.7
run1 "global", zero start 15 same, bridges start at 0 final velocity 3090, 30 min 0.503 31.6
run2 15 run1 global, continued final velocity 4090, +120 min 0.468 29.3
run3 15 all kept blocks (full fine-tune) + bridges velocity + intermediate states, half on own path A100, ~7 h 0.445 29.4
run4 (this model) 17 all kept blocks + bridges, from the original weights same as run3 A100, ~5 h 0.392 26.8

What these sweeps showed:

  • Match the output, not the local state. Healing toward the teacher's state just after the gap fixed its own target by 18% but barely moved the image. Training on the final velocity is what helps.

  • The ridge start is a head start, not a lasting gain (0.485 vs 0.503 after 30 minutes).

  • LoRA on two blocks plateaus. Four times more training gave 3.5% less velocity error. The limit was the setup, not the length of training.

  • Full fine-tuning, half on the model's own sampling path, is the method that kept improving. run4 trains every kept block (2.70B parameters; bf16 weights with fp32 master copies, bf16 Adam states, the optimizer step fused into the backward pass to fit 80 GB). Half of the batches start from the teacher's latents, half from the student's own 4-step trajectory with the teacher's velocity as the target. Loss: velocity plus 0.1 Γ— the hidden states after blocks 12 and 24. 4,000 DiffusionDB prompts, new noise each batch, batch 4, lr 5e-6 for the blocks and 1e-5 for the bridges (at 2e-5 the loss rose).

  • run4's curve was still falling when it stopped (velocity error βˆ’0.005 to βˆ’0.01 per hour):

    Eval Iterations Velocity error, teacher-forced Velocity error, own path MAD
    start 0 0.503 0.515 32.2
    e1 2,502 0.430 0.449 31.2
    e2 5,025 0.413 0.429 29.0
    e3 7,555 0.407 0.420 30.7
    e4 10,063 0.399 0.412 27.8
    e5 12,572 0.394 0.407 26.8
    final 14,459 0.392 0.406 26.8
  • 17 blocks was the better trade than 15. 15 blocks topped out at MAD 29.3 after three runs. 17 blocks reached 26.8 in one run.

5. On the NPU

The healed blocks were written into a Q8_0 GGUF and run on the NPU kernels for FLUX.2 [klein] (AMD Ryzen AI 9 HX 370, 512 Γ— 512, 4 steps, median of 6 timed runs on a quiet machine):

  • Stock 25 blocks 3.836 s, Trim17 2.904 s: βˆ’24% time, 1.32Γ— faster. Compute alone predicted βˆ’32%. The rest is per-step cost that does not shrink with depth (embedders, modulation, the bridge GEMMs, the VAE).
  • MAD against the NPU's own 25-block images: skip only 45.5, ridge bridge 31.5, healed 27.0. Q8_0 adds almost nothing over GPU bf16 (26.8).

6. Other checks

  • Fewer text rows (128 instead of 512) add about the same drift to Trim17 as to the full model, and on the NPU they save little: the GEMM kernels work in 512-row groups.
  • Step count. 6 and 8 steps do not break Trim17 (using the nearest trained bridge for each noise level) and add some detail, mostly at 6. But 17 blocks Γ— 6 steps costs about what the full model costs at 4 steps, so 4 (maybe 5) steps is the useful range.

Limitations

  • Content drifts from the original: faces, small text ("OPEN" signs) and building layouts change. Subject, composition and color usually hold.
  • Bridges exist only for the 4-step 512 Γ— 512 schedule. Other resolutions shift the timesteps and are untested.
  • Trained against the 4B model's own outputs on DiffusionDB prompts, so it inherits the base model's behavior and adds no new capability.
  • Not affiliated with or endorsed by Black Forest Labs.

License

Apache-2.0, the license of FLUX.2 [klein] 4B. This repository contains modified weights of that model.

Downloads last month
37
GGUF
Model size
4B params
Architecture
flux
Hardware compatibility
Log In to add your hardware

8-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Cyronius/FLUX.2-klein-4B-Trim17

Quantized
(89)
this model