lab

Image editing with Qwen-Image 2.1 on an RTX 5090: architecture, profiling, and Blackwell kernels

Pencil study of octagonal room plans with a drawing folded out of each wall: fractals, a dial, a film strip, a network and a pencil
Pencil study of octagonal room plans with a drawing folded out of each wall: fractals, a dial, a film strip, a network and a pencil

magpie is a lean PyTorch runtime and custom CUDA/Triton kernel stack for Qwen-Image 2.1 Turbo on Blackwell (sm_120) GPUs. On a single 32 GB RTX 5090, it edits a 1024² image in 1.26 s and a 2048² image in 5.00 s end-to-end (request to PNG reply, text encoder included) using its fast mode, or 1.49 s and 6.19 s at the full eight steps—both passing a 16-image perceptual quality gate against the bf16 baseline. The next-fastest engine measured on the same card (sglang FP8 + SageAttention) takes 2.54 s and 12.07 s; the official diffusers pipeline with CPU offload takes 28.0 s at 1024² and runs out of memory at 2048².

Contents. 1. The problem and model architecture · 2. Baseline profile and roofline · 3. Quality gating · 4. The optimisation ladder · 5. Core engineering decisions · 6. Discarded experiments · 7. RTX 5090 and cross-GPU results · 8. Showcase · 9. Using it and serving lessons · 10. Predictions, lessons, and what is left


1. The problem and model architecture

Out of the box, Qwen-Image 2.1 does not fit on a 32 GB consumer GPU. Its three networks total 30.2 GiB in bf16 weights alone, and the official diffusers pipeline peaks at 38.9 GiB for a 1024² edit and 64.6 GiB for a 2048² edit:

component role parameters weights on disk (bf16)
Qwen3-VL encodes prompt + reference images 8.77 B 16.3 GiB
DiT single-stream denoising transformer (32 blocks) 7.12 B 13.3 GiB
VAE 2D image ↔︎ latent codec (16× spatial, 64 ch) 0.34 B 0.6 GiB

Single-stream sequence and prefix caching

There is no separate text stream or cross-attention. Text hidden states (from Qwen3-VL's final decoder layer, before the final norm), reference image VAE latents, and the noisy target image sit in one concatenated sequence processed by 32 identical blocks (width 4096, 32 heads × 128, SwiGLU MLP ratio 3, no biases, and one Linear(4096 → 16384) modulation layer shared across all blocks):

[ text ... <image slots> ... text ][ target image ]
  └────────── prefix ────────────┘  └── redrawn each step ──┘

Reference images enter twice: Qwen3-VL reserves one <|image_pad|> slot per 32×32 pixel patch, and the DiT replaces each slot with four 16×16 VAE latent tokens (4,096 DiT tokens at 1024², 16,384 at 2048²). Each block applies RMS QK-norm per head and 3-axis RoPE (sequence index, centred row, centred column):

x = x + tanh(gate1) * attention( norm(x) * (1 + scale1) )
x = x + tanh(gate2) * swiglu(    norm(x) * (1 + scale2) )

Two architectural rules make the prefix invariant across denoising steps:

  1. Block-causal attention: prefix tokens attend to earlier tokens and all tokens of their own image, never to the target image.
  2. causal_condition: prefix tokens are modulated as if timestep t = 0; only target tokens receive the actual noise level σ.

Step 1 runs prefill over the full sequence and caches every layer's prefix keys and values; steps 2 onward run decode on target tokens only against [cached prefix, target] without an attention mask. Both checkpoints use flow-matching Euler steps (x ← x + (σ_next − σ) · v): base uses 40 shifted steps, while Turbo uses 8 fixed sigmas (1.0, 0.978, 0.954, 0.927, 0.895, 0.845, 0.705, 0.415 → 0).

The lean PyTorch port (src/magpie)

Before optimising anything, we reimplemented the DiT, 2D VAE, sampler, and loop in PyTorch using the checkpoint's exact parameter names so load_state_dict works directly. Replacing diffusers's video-shaped 3D VAE decoder with a pure 2D decoder (dropping unused time_conv weights) cut peak memory by 5–21 GiB immediately (port DiT + VAE peaks: 17.2 GiB at 1024² and 26.8 GiB at 2048²) and shaved 3–5 % off latency. On tiny random weights the DiT matches diffusers bit-for-bit (0.0 diff); on real bf16 weights it reaches 39.9 dB (against diffusers's own 41.4 dB cache-on/off floor).

Three subtle parity bugs surfaced only because we checked tiny random weights and free-running trajectories:

  1. Equal-dimension aliasing: slot padding used the text encoder's hidden size instead of the DiT's (both are 4096, so only a tiny-weight test with unequal dims caught it).
  2. CPU vs GPU constants: computing the 128 timestep embedding frequencies via exp on GPU vs CPU differed in the last float32 ULP, which flipped rounded bf16 values after multiplying by 1000 and cost 26 dB.
  3. Excess precision: multiplying (σ_next − σ) · v in fp32 instead of bf16 before adding to the fp32 latent drifted the free-running loop from 54 dB down to 32–47 dB.

2. Baseline profile and roofline

Profiled on a 96 GB RTX PRO 6000 Blackwell (where the unoptimised bf16 pipeline fits) to locate bottlenecks before writing kernels.

Share of request time by stage: the DiT takes 86 to 98 percent
Share of request time by stage: the DiT takes 86 to 98 percent

The DiT takes 86 to 98 percent of every edit request. Percent of each request's total time, official pipeline, bf16, batch 1. Total seconds at right. One NVIDIA RTX PRO 6000 Blackwell (95 GiB), PyTorch 2.14.1, CUDA 13.0. Warm p50 of 5 Turbo and 3 base requests. The unfilled end of each bar is other overhead, under 3 %. VAE encode and decode are summed.

official pipeline (RTX PRO 6000) text encoder VAE encode DiT VAE decode other total
Turbo, 1024² 98 ms 47 ms 2,333 ms 171 ms 71 ms 2,717 ms
Turbo, 2048² 464 ms 223 ms 16,226 ms 725 ms 247 ms 17,877 ms
base (40 steps), 1024² 98 ms 47 ms 10,688 ms 172 ms 69 ms 11,078 ms
base (40 steps), 2048² 457 ms 222 ms 69,136 ms 711 ms 261 ms 70,784 ms
Seconds per request, Turbo against base, at 1024 and 2048
Seconds per request, Turbo against base, at 1024 and 2048

Turbo is 4.0 to 4.1 x faster than base, end to end. Seconds per edit request, warm p50, official pipeline, batch 1. At 2048 an edit costs 6.4 to 6.6 times its 1024 time. Each request includes the VAE encode of the input image. One RTX PRO 6000 Blackwell, bf16.

DiT milliseconds per step with the prefix cache on and off: 523 ms to 259 ms after step 1
DiT milliseconds per step with the prefix cache on and off: 523 ms to 259 ms after step 1

After the first step, the prefix cache halves each DiT step: 523 ms to 259 ms. DiT milliseconds per denoising step, edit at 1024, Turbo (8 steps), official pipeline. Step 1 computes the prefix either way. Steps 2 to 8 are averaged. Whole request: 2.72 s with the cache, 4.57 s without.

Peak GPU memory of a Turbo edit: official pipeline 38.9 and 64.6 GiB, lean port 33.5 and 43.1, lean port with DiT and VAE only 17.2 and 26.8, against the 32 GB line
Peak GPU memory of a Turbo edit: official pipeline 38.9 and 64.6 GiB, lean port 33.5 and 43.1, lean port with DiT and VAE only 17.2 and 26.8, against the 32 GB line

Dropping the text encoder drops peak memory below 32 GB, and the lean 2D VAE saves another 5 to 21 GiB. Peak GPU memory allocated, Turbo edit, bf16, batch 1. Official pipeline is diffusers. Lean port (DiT + VAE only) takes text states pre-computed. Dashed line: 32 GB (RTX 5090).

Inside the GPU trace

Perfetto traces of the lean port (DiT + VAE) revealed four facts that set the optimisation plan:

Whole 1024 edit, 2.44 s: a short VAE encode, eight DiT steps with the first twice as long, then the VAE decode

One block of a cached step, 7.7 ms: qkv with QK-norm and RoPE, flash attention, attention output, then the three-matmul MLP

GPU time inside labelled spans (port) edit 1024² edit 2048² (profiled, +8%)
MLP (SwiGLU) 1,005 ms 4,531 ms
QKV + QK-norm + RoPE 542 ms 2,846 ms
attention 467 ms 7,341 ms
attention output 103 ms 449 ms
VAE decode 149 ms 645 ms
VAE encode 39 ms 170 ms
all kernels 2,406 ms 16,660 ms
Share of GPU kernel time by span in a Turbo edit: attention is 19 percent at 1024 and 44 percent at 2048
Share of GPU kernel time by span in a Turbo edit: attention is 19 percent at 1024 and 44 percent at 2048

At 1024², the MLP is 42 % of kernel time; at 2048², quadratic attention takes over at 44 % (16,384 queries over 32,768 keys).

Achieved TFLOP/s per DiT step against measured matmul and attention ceilings
Achieved TFLOP/s per DiT step against measured matmul and attention ceilings

DiT steps already run at 73–80 % of the card's measured model-shaped bf16 matmul (378.5 TFLOP/s; 8192³ square matmul 422 TFLOP/s; copy bandwidth 1,462 GB/s). Multiples of speedup require lower-precision tensor-core formats, not bf16 tuning.

GPU time by operation group: matmul 55 percent, elementwise 23, attention 18, convolution 4
GPU time by operation group: matmul 55 percent, elementwise 23, attention 18, convolution 4

Elementwise work (23 %: norms, RoPE, modulation, casts, copies) exceeds attention (18 %) at 1024².

QKV span, 2 ms: three matmul kernels, then about twenty small elementwise kernels

Small kernels against matmul and convolution kernels inside the QKV, MLP and VAE decode spans: 226 of 542 ms, 84 of 1005 ms, 92 of 149 ms
Small kernels against matmul and convolution kernels inside the QKV, MLP and VAE decode spans: 226 of 542 ms, 84 of 1005 ms, 92 of 149 ms

Inside QKV, three matmuls take 306 ms while 22 small elementwise/copy kernels for QK-norm + RoPE take 226 ms (9 % of the request, 98 ms plain copies). Inside VAE decode (149 ms), convolutions are only 56 ms; norms/activations take 49 ms, copies 24 ms, and NCHW↔︎NHWC conversions 19 ms.

Last VAE stage, 54 ms: convolution kernels separated by many small elementwise and layout-conversion kernels

  1. No launch-bound gap: GPU kernels cover 98.6 % of a 1024² edit and 99.6 % at 2048² across ~12,700 launches (median gap 1.4 µs on the 1,711 ms build). CUDA graphs can win < 2 %.
  2. Ampere-era stock kernels: stock matmuls/convs ran cutlass_80_tensorop_bf16 and sm80_xmma on sm_120.
  3. Roofline floor: pricing FLOPs at datasheet peaks (1 / 2 / 4 PFLOPS dense-or-sparse for bf16 / FP8 / FP4, 1,597 GB/s) gives a bf16 floor of 876 ms (FP8 linears 618 ms, FP4 linears 489 ms) at 1024²; DiT small kernels drop from 423 ms → 139 ms when fused to single read/write passes.
Kernel time per span of a 1024 edit, measured, at the fastest rates measured on the card, and at datasheet rates: MLP 1005, 904 and 411 ms; QKV 542, 308 and 143; attention 467, 356 and 150
Kernel time per span of a 1024 edit, measured, at the fastest rates measured on the card, and at datasheet rates: MLP 1005, 904 and 411 ms; QKV 542, 308 and 143; attention 467, 356 and 150

Kernel time per span of a 1024² edit: measured port, at fastest card rates (422 TFLOP/s, 1,462 GB/s), and at datasheet rates.


3. Quality gating

Early runs gated on worst-of-40 per-step relative L2 error and PSNR. Both proved noisy: a rounding-only fusion (qk_prep) moved PSNR by −3.5 dB despite 99.9997 % bit-identical intermediates, while diffusers itself only scores 41.4 dB between cache-on and cache-off. Worse, worst-of-N grows with N (5 images showed 1.83 % worst step error while 16 exposed 6.45 %).

The shipped gate evaluates 16 frozen edits (ink/pencil drawings + item 15, a letterpress poster whose edit recolours it and replaces two lines of text) at both 1024² and 2048² against the unoptimised bf16 port:


4. The optimisation ladder

Measured sequentially on the RTX PRO 6000 (DiT + VAE, Turbo, 1024² edit) against each preceding build, followed by later refinements (1,013 → 995.6 ms measured as one span) and opt-in modes:

A 1024² edit, DiT + VAE: port 2,484 ms; low-precision linear layers -803 to 1,681; fusion -396 to 1,285; attention kernels -237 to 1,048; less work per request -35 to 1,013; later work -17 to 995.6; fast, 6 of 8 steps, -183 to 812.9
A 1024² edit, DiT + VAE: port 2,484 ms; low-precision linear layers -803 to 1,681; fusion -396 to 1,285; attention kernels -237 to 1,048; less work per request -35 to 1,013; later work -17 to 995.6; fast, 6 of 8 steps, -183 to 812.9

Latency ladder on an RTX PRO 6000 (1024² edit, DiT + VAE). Four core groups take the eager port from 2,484 ms to 1,013 ms; later fusion/resize refinements reach 995.6 ms; fast reaches 812.9 ms.

# change 1024² DiT+VAE Δ (1024²) 2048² / memory / other effect
0 lean PyTorch port (2D VAE, prefix cache) 2,484 ms — peak 38.9→17.2 GiB (1024²), 64.6→26.8 GiB (2048²)
1 fused QK-norm + RoPE Triton kernel (qk_prep) 2,279 ms −205 ms 2048²: 15,298→14,032 ms (−1,266 ms)
2 max-free Triton flash attention (29/32 blocks) 2,245 ms −34 ms later replaced by SageAttention 2
3 Triton FP8 MLP (mlp_fp8) 2,023 ms −222 ms —
4 fused VAE (pixel_norm, NHWC, grow_add) + K/V buffer + DiT glue 1,832 ms −191 ms VAE decode 149→77 ms, encode 39→21 ms
5 FP8 row alignment (drop inner 128-col scaling) + FP8 K, V 1,711 ms −121 ms ~62 ms align + ~58 ms K/V
6 SageAttention 2 + FP8 on all 4 attention linears (Q, K, V, Out) 1,508 ms −203 ms 2048² stages 11.60→9.11 s
7 CUTLASS sm_120 block-scaled MXFP8 matmuls (magpie_gemm) 1,316 ms −192 ms matmuls 515→650–727 TFLOP/s
8 NVFP4 on MLP output matmul 1,218 ms −98 ms —
9 NVFP4 on both MLP matmuls + MXFP8 ping-pong schedule 1,048 ms −170 ms 2048²: 11.2→6.8 s (steps 8+9)
10 quantised KV cache kept across steps (SageKV, tile-ordered write) 1,013 ms −35 ms 2048²: −150 ms (6,689→6,538 ms)
11 native sm_120 4-bit attention (magpie_attn4, 2048-class only) — — 2048²: 6,607→5,785 ms (−822 ms, −12 %)
12 residual-in-norm (Stream), shared KV scratch tail, 8k-row MLP, magpie_attn8, GPU resize 995.6 ms −17.4 ms 5090 2048² peak 26.4→18.2 GiB (−7.75 GiB tail + −0.47 GiB MLP); resize 30→0.1 ms
13 1448² default reference + 1024² encoder copy (2048² edits) — — 5090 2048² DiT+VAE 7,247→6,106 ms; encode 471→158 ms
14 opt-in fast (skip DiT steps 3 & 6) 812.9 ms −183 ms PRO 6000 2048²: −1,162 ms (5,702→4,540); 5090: 1,158→935 / 5,474→4,306 ms
15 opt-in keep (reuse reference KV across requests) 863 ms −116 ms PRO 6000 2048²: −236 ms; 5090: 1,158→1,023 / 5,474→5,247 ms (+4.6 / +11.3 GiB)

Additional memory and serving gains (measured on RTX 5090 unless noted):

change effect
drop bf16 originals (slim=True) DiT resident 13.9 → 8.4 GiB
calibrated AutoRound NVFP4 text encoder encoder 15.2 → 5.9 GiB (101 → 72 ms; fits 11 / 6 refs resident on 5090 vs 4 / 2)
prepacked hybrid DiT checkpoint load time 10.0 → 1.6 s, load peak 19.1 → 6.1 GiB
single GPU executor thread (ThreadPoolExecutor(1)) 5090 HTTP round trip 2.7 → 1.1 s (removes ~1.6 s per-thread CUDA warm-up)
server prompt memory (MAGPIE_PROMPTS=8) repeated prompt+image skips text encode (142–175 ms → 0 ms) & encoder unpark
PNG zlib level 1 2048² CPU encode ~430 → ~90 ms (~4.7× faster, identical pixels)
startup 6-edit probe + quadratic memory planner 0 OOMs inside plan; parks encoder when needed, returns 507 otherwise

5. Core engineering decisions

1. Native Blackwell tensor-core formats (MXFP8 & NVFP4)

Plain Triton FP8 (e4m3) kept one scale per token row and one per weight column, applying them in software after the matmul; across 54 tile configs it plateaued at 515–518 TFLOP/s. Removing inner 128-column rescaling via row alignment recovered ~62 ms, but the real jump came from switching to MXFP8 via CUTLASS (native/gemm.cu): one power-of-two scale byte per 32 values, read and applied directly inside the sm_120 tensor-core instruction (640–727 TFLOP/s, ~30 % faster). Triton fused norm and SwiGLU kernels emit activations straight into CUTLASS's scale-slot layout.

NVFP4 packs two e2m1 nibbles per byte with one FP8 scale per 16 values (~13 % per-matmul rounding error vs 3.8 % for FP8). Tolerance depends on which tensor is rounded:

MLP matmuls in NVFP4 (PRO 6000) 1024² DiT+VAE DINOv2 min verdict
none (all MXFP8) 1,316 ms 0.990 pass
output matmul only 1,218 ms 0.993 pass
hidden matmul only 1,165 ms 0.956 fail
both (shipped default) 1,054 ms 0.977 16/16 pass on 5090; 2 flagged on PRO 6000

The output matmul reads spiky post-SwiGLU activations where large values carry the signal; the hidden matmul reads dense normalised tokens. Pre-scaling weights by 64 and SwiGLU outputs by 0.25 (undone via alpha) keeps scales inside FP8 range. Attention linears stay MXFP8 (emulated NVFP4 scored 0.967).

Why we stopped tuning GEMMs (native/peak.cu): microbenchmarking single sm_120 instructions on the RTX 5090 showed bf16 reaches 93 % of its instruction ceiling (240 vs 258 TFLOP/s), whereas MXFP8 (557–708 vs 1,024 TFLOP/s) and NVFP4 (1,104–1,209 vs 2,030 TFLOP/s) hit the exact same ceiling as a hand-written streaming matmul (590–624 and 1,108–1,243 TFLOP/s) once operands stream from global memory rather than staying in shared memory/registers. Only CUTLASS's ping-pong FP8 schedule yielded a further 4 % matmul gain.

Tensor-core rate on an RTX 5090 in TFLOP/s. bf16: 258 from registers, 240 in torch. Block-scaled fp8: 1,024 from registers, 1,000 from shared memory, 590 to 624 streamed, 557 to 708 in CUTLASS. NVFP4: 2,030 from registers, 2,015 from shared memory, 1,108 to 1,243 streamed, 1,104 to 1,209 in CUTLASS
Tensor-core rate on an RTX 5090 in TFLOP/s. bf16: 258 from registers, 240 in torch. Block-scaled fp8: 1,024 from registers, 1,000 from shared memory, 590 to 624 streamed, 557 to 708 in CUTLASS. NVFP4: 2,030 from registers, 2,015 from shared memory, 1,108 to 1,243 streamed, 1,104 to 1,209 in CUTLASS

Quantised GEMMs on the 5090 are bound by operand streaming from global memory, not the tensor-core instruction or shared memory.

2. Kernel fusion and memory layout

3. Attention: SageAttention 2, SageKV, and native 4-bit sm_120

4. Doing less work and fitting 32 GB


6. Discarded experiments

Every change had to pass the 16-image gate and pay for its code complexity:

experiment result why discarded
FP8 attention linears before SageAttention 1,832 → 1,723 ms failed the old step-error gate (later passed perceptual gate)
SageAttention 3 (FP4) 1.53 vs 1.20 ms/call; item 4 0.940 failed gate and slower at 1024² (0.64 ms quant overhead)
NVFP4 on MLP hidden matmul only 1,165 ms, 2 flagged failed gate (0.956)
NVFP4 on attention linears (emulated) DINOv2 0.967 failed gate
4-bit attention at 1024² or 7+ 1024² refs −15 ms; item 0 0.969; 7+ refs 0.76–0.96 lost subjects / content
merging reference keys 2×2 17 % mean step error broke edits (with or without RoPE correction)
1024² reference for 2048² output DINOv2 0.972–0.977 failed gate (1448² kept)
keep with dequantised reference rows DINOv2 0.78–0.92 resumed edits drifted; reverted to bf16 rows
fused 12,288-wide QKV matmul (fused-qkv branch) −5.5 ms (1024²), −6.8 ms (2048²) too much code for ~0.5 % gain
28 CUTLASS tile/stage configs only 2 compiled, identical operand-streaming bound
VAE torch.compile +127 ms (1024²), +494 ms & +3.4 GiB (2048²) Inductor typed our Triton pixel_norm Python-float scale as fp64, running norm+SiLU at 1/64 rate (35 → 757 ms on L4)
cudnn.benchmark −10 ms card-dependent conv algorithm flips changed VAE encode conditioning and pushed items 0 & 4 under 0.98 on 5090
round-to-nearest NVFP4 / MXFP8 text encoder DINOv2 0.956–0.971 superseded by calibrated NVFP4 (5.9 GiB)
Triton FP8 path on Blackwell / B200 / 4090 B200 2,089 ms, 4090 7,508 ms moved to ada branch (sm_89); master is sm_120 native

7. RTX 5090 and cross-GPU results

All RTX 5090 comparisons ran sequentially on one RunPod RTX 5090 (575 W, driver 580.126.09, 31.4 GiB usable, bf16 8192³ measured at 235.6 TFLOP/s) on 2026-10-15.

Milliseconds per edit request on an RTX 5090 for magpie fast, magpie 8 steps, LightX2V 4,539 ms and 20,072 ms, vLLM-Omni out of memory and out of memory, sglang fp8 + sage 2,543 ms and 12,066 ms, sglang default 4,487 ms and 23,585 ms, official diffusers, CPU offload 28,047 ms and out of memory
Milliseconds per edit request on an RTX 5090 for magpie fast, magpie 8 steps, LightX2V 4,539 ms and 20,072 ms, vLLM-Omni out of memory and out of memory, sglang fp8 + sage 2,543 ms and 12,066 ms, sglang default 4,487 ms and 23,585 ms, official diffusers, CPU offload 28,047 ms and out of memory

Next-fastest engine (sglang FP8 + SageAttention) takes 2.0× as long as magpie fast at 1024² and 2.4× at 2048². Median of 5 warm requests after 1 warm-up. magpie reports torch peak allocated; others report nvidia-smi used.

RTX 5090, edit (request → PNG) 1024² 2048² 2048² peak
magpie, fast 1,263 ms 5,000 ms 18.4 GiB
magpie, 8 steps 1,488 ms 6,189 ms 18.4 GiB
sglang 0.5.21 (FP8 + SageAttention) 2,543 ms 12,066 ms 31.1 GiB
sglang 0.5.21 (default) 4,487 ms 23,585 ms 27.8 GiB
LightX2V (encoder offloaded) 4,539 ms 20,072 ms 30.7 GiB
vLLM-Omni (encoder offloaded) out of memory out of memory –
official diffusers (CPU offload, in-process) 28,047 ms out of memory –
Animation: 1024² edits finished one after another on an RTX 5090 by each system in 16 seconds
Animation: 1024² edits finished one after another on an RTX 5090 by each system in 16 seconds

Real-time replay of 1024² completions over 16 seconds.

fast and quality gates on 5090 vs PRO 6000

DiT and VAE milliseconds at 8 steps and with fast on the RTX 5090 and RTX PRO 6000, at 1024² and 2048²
DiT and VAE milliseconds at 8 steps and with fast on the RTX 5090 and RTX PRO 6000, at 1024² and 2048²

fast cuts 19–21 % off DiT + VAE on both cards (RTX 5090: 1,158 → 935 ms at 1024², 5,474 → 4,306 ms at 2048²; PRO 6000: 979 → 787 ms, 4,679 → 3,690 ms).

DINOv2 similarity of each of 16 gate edits at 1024² and 2048² on an RTX 5090, 8 steps and fast; every point is above 0.98
DINOv2 similarity of each of 16 gate edits at 1024² and 2048² on an RTX 5090, 8 steps and fast; every point is above 0.98

On RTX 5090, all 32 edits (16 × 1024², 16 × 2048²) pass the 0.98 gate in both 8-step and fast modes (lowest 0.9861).

DINOv2 similarity of each gate edit on an RTX PRO 6000, 8 steps and fast: items 0 and 4 fall under 0.98 at 1024² in both modes
DINOv2 similarity of each gate edit on an RTX PRO 6000, 8 steps and fast: items 0 and 4 fall under 0.98 at 1024² in both modes

Same kernels on RTX PRO 6000: items 0 (0.975) and 4 (0.964) drop below 0.98 at 1024² (both 8-step and fast) because differing SM counts change CUTLASS/attention reduction order.

Memory and multi-reference scaling

Peak memory against latency for each engine on an RTX 5090, 1024² edit
Peak memory against latency for each engine on an RTX 5090, 1024² edit

1024² memory vs latency on RTX 5090 (magpie peaks at 14.9 GiB).

Peak memory against latency for each engine on an RTX 5090, 2048² edit
Peak memory against latency for each engine on an RTX 5090, 2048² edit

2048² memory vs latency on RTX 5090 (magpie is both fastest and lowest peak at 18.4 GiB).

Peak memory and DiT and VAE seconds against the number of references on an RTX 5090: 1024² edits fit 11 resident and 14 parked, 2048² edits 6 and 8
Peak memory and DiT and VAE seconds against the number of references on an RTX 5090: 1024² edits fit 11 resident and 14 parked, 2048² edits 6 and 8

Multi-reference limits on RTX 5090 (29.6 GiB probe usable). Each extra reference adds ~1.4 GiB / 0.4 s at 1024² and ~1.9 GiB / 1.2 s at 2048².

RTX 5090 resident encoder parked refused from
1024² edit, 1024² refs 11 (29.2 GiB) 15 planned; 14 measured (27.7 GiB) 16
2048² edit, 1448² refs 6 (27.9 GiB) 8 (25.8 GiB) 9

Other cards and 40-step base

DiT and VAE milliseconds per gate edit on four cards: RTX PRO 6000 996 and 5,702, RTX 5090 1,219 and 6,666, B200 on the ada branch 2,089 and 7,915, RTX 4090 on the ada branch 7,508 and out of memory
DiT and VAE milliseconds per gate edit on four cards: RTX PRO 6000 996 and 5,702, RTX 5090 1,219 and 6,666, B200 on the ada branch 2,089 and 7,915, RTX 4090 on the ada branch 7,508 and out of memory

Gate DiT + VAE latency across four GPUs. PRO 6000 round-trip PNG: 1,023 / 4,757 ms (vs LightX2V 2,512 / 13,518 ms, vLLM-Omni 2,347 / 10,340 ms). B200 (sm_100) and RTX 4090 (sm_89) run the portable Triton FP8 ada branch.

40-step base (DiT + VAE) 1024² edit 2048² edit
port, eager PyTorch, PRO 6000 10.78 s 68.97 s
magpie, PRO 6000 4.08 s (DINOv2 ≥ 0.988) 24.43 s (≥ 0.990)
magpie, RTX 5090 4.76 s (DINOv2 ≥ 0.987) 27.90 s (≥ 0.988)

8. Showcase

111 requests rendered on the RTX 5090 with default settings (8 steps, whole request including text encoder): 21 text-to-image at 1024² (median 0.93 s), 6 at 2048² (4.94 s), 58 one-reference edits at 1024²-class (1.25 s), 13 at 2048²-class (5.57 s), and 13 multi-reference edits. Tip: always use a fresh seed when editing a generated image; reusing the source seed starts from the exact same noise and yields harsh, over-sharpened output.

Michelangelo's Pietà photographed in St Peter's beside a steel engraving of it Michelangelo's Doni Tondo beside a restored version in its carved gilt frame Michelangelo's Delphic Sibyl beside the same figure carved as a white marble relief Michelangelo's Moses in San Pietro in Vincoli beside the statue recast in dark bronze The Apollo 11 lunar module Eagle in lunar orbit beside a cyanotype engineering drawing of it A Voyager spacecraft illustration beside a labelled pen cutaway of it Hubble leaving the shuttle Atlantis beside a travel poster reading THE EYE ABOVE THE AIR A generated desert-planet painting beside the same painting as a paperback cover titled THE DESERT PLANET A generated painting of a sandworm rising over a figure beside a pencil storyboard frame of it The Vitruvian Man beside the same sheet with an astronaut in his place A 1927 Amazing Stories cover beside the same cover with the title changed to MAGPIE STORIES A Barnum and Bailey circus poster beside the same poster reading MAGPIE & SPARROW Haeckel's plate of jellyfish beside a glowing blue version on black Dürer's Rhinoceros woodcut beside a hand-coloured version Hokusai's Great Wave beside the same print as a night thunderstorm with lightning Dorothea Lange's Migrant Mother beside a colourised version in muted tones

Several references (2–4 inputs)

Two references, the Creation of Adam and the ISS, beside a notebook page that draws both Three references beside a notebook page that adds Michelangelo's David Four references beside a notebook page that adds a Saturn V
RTX 5090, whole request 2 references 3 references 4 references
1024²-class output 1.45 s, 16.2 GiB 1.76 s, 17.6 GiB 2.17 s, 19.2 GiB
2048²-class output 6.54 s, 19.9 GiB 7.77 s, 21.9 GiB 8.89 s, 23.9 GiB

fast vs 8 steps

The Pietà engraving at 8 steps and with fast Girl with a Pearl Earring redrawn in pencil at 8 steps and with fast Hiroshige's bridge in snow at 8 steps and with fast A text-to-image sandworm painting at 8 steps and with fast The three-reference notebook page at 8 steps and with fast

Showcase sources

All from Wikimedia Commons. Public domain unless marked: Dorothea Lange, Lange-MigrantMother02; Johannes Vermeer, 1665 Girl with a Pearl Earring; Michelangelo, Sistine Chapel ceiling, Creation of Adam; Michelangelo, Tondo Doni 2021; Michelangelo, Michelangelo - Delphic Sibyl; Original: Ernst Haeckel. Scan: Ragesoss. Cleanup: Ilmari Karonen., Haeckel Discomedusae 8; Katsushika Hokusai, Tsunami by hokusai 19th century; The Strobridge Litho. Co., Cincinnati & New York., Barnum & Bailey clowns and geese2; Utagawa Hiroshige, Hiroshige, Sudden shower over Shin-Ōhashi bridge and Atake, 1857; Albrecht Dürer, The Rhinoceros (NGA 1964.8.697) enhanced; Frank R. Paul, Amazing Stories 1927 08; Livioandronico2013, Michelangelo's David 2015, CC BY-SA 4.0; Szilas, Michelangelo - Moses - San Pietro in Vincoli-3; Jebulon, Michelangelo's Pietà Saint Peter's Basilica Vatican City, CC0; NASA, Apollo 11 Lunar Module Eagle in landing configuration in lunar orbit from the Command and Service Module Columbia; NASA Hubble Space Telescope, View of Hubble after Being Released from the Shuttle Atlantis (28223588012); NASA, STS-97 International Space Station seen from Space Shuttle Endeavour; Cygni_18, Launch of the Saturn V with Apollo 11 (48300001196); NASA/JPL, Voyager spacecraft; Leonardo da Vinci, Da Vinci Vitruve Luc Viatour (cropped).


9. Using it and serving lessons

uv pip install -e .
bash tools/build_native.sh     # builds CUTLASS GEMM + SageAttention + attn4/8 (~404 s on 5090)
python -m magpie.server --port 8188

POST /generate accepts prompt, images, resolution (1024/2048), fast, keep, reference, and seed; server flags include --encoder nvfp4|bf16 and --max-memory.

Four operational surprises from deploying on Colab, RunPod pods, and RunPod serverless:

  1. Check the GPU before benchmarking: our first rented 5090 was power-capped at 400 W and ran bf16 at 16.5 TFLOP/s (14× slow) without raising an error.
  2. One GPU worker thread: Python's ThreadingHTTPServer spawns a thread per request, paying ~1.6 s of CUDA context warm-up each time (2.7 s → 1.1 s once pinned to a single executor thread).
  3. Reply encoding & tunnel transport: default PNG compression took 305 ms at 1024² and ~430 ms at 2048² (zlib level 1 cuts it ~4.7×); Cloudflare QUIC tunnels throttled Colab to 6–70 KB/s vs 0.8 MB/s over HTTP/2.
  4. Cold starts: with page cache dropped, the server loads in 10.0 s (11.3 GiB) and probes for 44.8 s; in serverless, 260 s went to GPU provisioning and 230 s to network-volume reads out of 545 s total.

10. Predictions, lessons, and what is left

Every optimisation started with a written prediction; the misses taught the most:

Method, limits, and open work