翻篇收录说明
翻篇网页快照

Serving sub-second Ideogram v4 without quality loss

https://blog.fal.ai/serving-sub-second-ideogram-v4-without-quality-loss/

最近抓取:2026-12-03 17:24:53(北京时间)

最近内容变化:2026-12-03 17:24:53(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

At @fal we serve Ideogram V4 at high speed. At 1K resolution, a generation that used to take 2.75 s now renders in 0.44 s, a 6x speedup with no visible quality loss. We got there by pushing the cost of a generated image down on every axis

正文摘录

At @fal we serve Ideogram V4 at high speed. At 1K resolution, a generation that used to take 2.75 s now renders in 0.44 s, a 6x speedup with no visible quality loss. We got there by pushing the cost of a generated image down on every axis we could find, and it helps to see those axes as one equation: the cost of an image is how many forward passes the diffusion transformer runs, times how expensive each pass is. Two fronts. Make each forward pass cheap: run the transformer in FP4, and fuse the small ops around each matmul so they don't pay a memory round-trip. Make the passes fewer: distill classifier-free guidance from two branches into one, and distill the many denoising steps into a handful. Stack all of it and you land on the same image as the full bf16 model at a fraction of the compute. This post walks the whole path, roughly in the order we built it. We start with the FP4 forward pass and the kernel fusion that makes it fast, then the quality problem 4-bit caused and the quantization-aware distillation that fixed it, and finally the timestep distillation that collapsed the step count. FP4 is fast, but naive FP4 looked visibly worse than bf16, and even then it still ran many steps times two guidance branches. Here is how we closed all of that. Running the transformer in FP4 The fastest inference path runs the diffusion transformer in NVFP4. FP4 is a 4-bit floating point format: one sign bit, two exponent bits, one mantissa bit, so each value can only take one of a handful of levels. In exchange you get a meaningful speedup and a much smaller memory footprint, which lets us push more concurrency and lower latency per image. On Blackwell the format is supported in hardware, so the matmuls run natively in 4-bit. But a 4-bit matmul only pays off if the matmul is where the time actually goes, and in a diffusion transformer it often isn't the whole story. Every big GEMM is chased by a small op: RMSNorm on the attention path, gated-SiLU in the FFN. Unfused, that small op forces the GEMM's entire output out to HBM and back. The matmul got cheaper, and then a memory round-trip you didn't remove eats the win. So the first thing a fast FP4 path needs is to fuse those ops into the GEMM itself. Fusing the epilogue so FP4 pays off Epilogue fusion, briefly A GEMM produces A @ B in tiles. Inside each tile, Tensor Cores stream multiply-adds into an accumulator that lives in the SM's own storage: registers on Hopper, TMEM on Blackwell. While that mainloop runs, nothing has touched HBM for the output yet; the answer is being accumulated on-chip. But A @ B is almost never the end of the layer. In a diffusion transformer the FFN is typically a GEMM followed by a gated-SiLU (SwiGLU), and the attention path by a GEMM followed by RMSNorm. The pattern repeats across LLMs and DiTs: a big GEMM, then a small post-op. The op itself is cheap; the problem is that unfused, the GEMM writes the whole tile to HBM, a second kernel loads it back, applies the op, and writes again. A few FLOPs become a full memory round-trip plus a second kernel launch. Epilogue fusion is applying operations after the GEMM just before the result is saved to HBM. The output goes to global memory once, already transformed no second kernel, no round-trip. On Hopper and Blackwell the epilogue can overlap with the next tile's mainloop, so for small ops the extra compute is often nearly hidden. CUTLASS exposes this through Epilogue Visitor Trees (EVT). You write a visit() that runs on each accumulator fragment, and the collective epilogue handles the loads and stores. The mechanics are explained well in the Colfax EVT writeup. The short version: pointwise fusions (bias, ReLU, cast) fall out cleanly: every output element is independent, there's nothing to reduce across, and CUTLASS ships prebuilt visitors for them. In this post we focus on fusing RMSNorm. It normalizes a vector by its own RMS: y = x · rsqrt(mean(x²) + eps) · weight. Unlike a pointwise op, it needs rstd over the whole head, a reduction. That reduction is what makes fusion hard, and to see why we need to look at how the epilogue actually sees its data. Tiles and fragments on Blackwell The GEMM works in CTA tiles: on Blackwell (SM100), our NVFP4 GEMM uses a 256×256 CTA tile. The epilogue doesn't process that whole tile at once; it walks it in smaller epilogue tiles of 128×128, giving 4 epilogue subtiles per CTA: Each epilogue subtile is partitioned across 128 threads, so each thread holds a fragment of 128 elements (FragmentSize = 128). The visit() callback receives one fragment at a time, 128 values that this thread is responsible for. This is the unit of work the epilogue sees, and it matters for what you can fuse. This makes head_dim=128 RMSNorm fusion trivial: a head of 128 elements is exactly one thread's fragment. When visit() is called, the thread is already holding all 128 values of one head in its own registers. To compute RMSNorm it sums the squares across those 128 values (no cross-thread shuffle, no second fragment, no extra pass), scales, and stores. The reduction fits in a single visit() call. Ideogram v4 is not so convenient. Its attention uses head_dim=256, so a single head no longer fits in one fragment; it straddles two, and the clean single-visit() reduction breaks down. Why head_dim=256 is hard To see why that's a problem, look at how the epilogue runs. After the mainloop, CUTLASS's collective epilogue loops over the 4 subtiles of the CTA tile in a fixed order: Tile 0 → Tile 1 → Tile 2 → Tile 3, and for each subtile it calls visit() once per fragment, stores the result, and moves on. It is a single forward pass; there is no going back to an earlier subtile. RMSNorm needs rstd over the whole head, a reduction: rstd = rsqrt(mean(x²) + eps), then y = x * rstd * weight. To compute it we need the sum of squares across both halves, but they arrive in separate visit() calls: the first half in Tile 0, the second in Tile 1. By the time we see Tile 1 and can compute rstd, Tile 0 has already been visited and stored. There's no way to go back and fix it up. The rest of this section is how we fused it anyway: a two-pass revisit schedule that keeps the first half in registers. The revisit fusion CUTLASS's epilogue collective works with a fixed, single-pass loop order: visit each subtile once, store, move on. That doesn't solve our problem: we need to see Tile 1 before we can normalize Tile 0, which means going back. So we wrote an epilogue that lets the visitor walk subtiles in the order the reduction needs (including coming back to a tile it already saw) instead of the stock single forward pass. The schedule, per row-group, is three touches: Tile 0, pass 0: this is the first half of the head. We compute its sum-of-squares and move on; we can't normalize yet without the second half. Tile 1, pass 1: the second half of the head arrives. Now we have both halves: we compute this half's sum-of-squares, add it to the first half's, and finally get rstd. We normalize and store this half. Tile 0, pass 2 (revisit): we go back to Tile 0 and scale it with the now-known rstd. This is the extra touch the single-pass epilogue can't do. Everything stays on-chip: no global memory round-trip, no second kernel. A custom epilogue walks the three-touch schedule; a visitor carries the reduction state across those touches and applies the scale when rstd is ready. Together they fuse the norm before anything hits HBM. Gated-SiLU (SwiGLU) fusion A different common pattern in diffusion transformers (and LLMs like LLaMA) is gated-SiLU. One GEMM produces an output C, then the layer finishes by splitting it in half and multiplying: C = A @ B output = SiLU(C[:, :N//2]) * C[:, N//2:] That cuts the output width in half; two halves become one. Same story as RMSNorm: the math is cheap, but an unfused second kernel pays a full HBM round-trip. CUTLASS has no built-in epilogue for this "pair + reduce N/2" pattern, so fusing it means a custom visitor. The catch is layout. For output column n, the pair is gate = C[:, n] and up = C[:, n + N/2], separated by half of N. Those two values can easily land in different fragments, different subtiles, or even different CTAs. Synchronizing across tiles would kill the epilogue's parallel model. Instead we permute the columns of B once during weight packing. The GEMM then produces interleaved pairs [gate0, up0, gate1, up1, ...] instead of two separated halves. With adjacency guaranteed, a custom EVT visitor applies SiLU and the multiply on adjacent elements in the same fragment, and stores the reduced result: one kernel, no cross-tile communication. The full walkthrough (weight packing, the visitor hooks, and the EVT wiring) is in Crafting Efficient Kernels with Epilogue Fusion. OG weights fail to deliver high quality image with FP4 quantizationThe catch: FP4 costs image quality Fusing the epilogue gets us a fast FP4 forward pass. On its own, it also gets us a worse-looking one. Stock FP4 inference looked visibly worse than bf16, specifically on color. Reds washed out, chroma dropped, and color-heavy prompts (logos, products, plants) looked desaturated next to the bf16 reference. Those handful of levels per value are fine for a large language model, where every token is a small contribution to a big average. A diffusion transformer is less forgiving, because it iteratively denoises a latent over many steps and each step feeds its output into the next. A slightly wrong velocity at one step becomes a wrong latent at the next, which feeds a wrong input at the step after that. The error snowballs. With FP4, this compounding showed up as desaturation: the model still produced the right composition, but colors came out flatter and less vivid than the bf16 model. Post-processing tricks (luma correction, color rebalancing) did not materially help, because the error was baked into the latents before decoding, not just a display-space issue. We needed to fix this inside the model, not after it. What did no