Z-Image-Turbo text-to-image support#24
Merged
Merged
Conversation
…R gc The torch allocated/reserved ratio gate (0.95) is chronically exceeded under backend:native (measured 0.957 steady state), firing the R gc callback on nearly every CUDA allocation: ~2,200 gcs x 62 ms per Z-Image generation. start_torch() reads the gate options only once at torch init, so the loaders now push thresholds into the live allocator directly: ratio gate off, absolute allocated_rate 0.65 as the garbage-accumulation gate, footprint-based reserved_rate as the net. Measured 1024x1024 on the RTX 5060 Ti 16 GB: Z-Image-Turbo 143 -> 24 s, klein 48 -> 13 s, FLUX.1 121 -> 55 s
This was referenced Jul 8, 2026
TroyHernandez
added a commit
that referenced
this pull request
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds Z-Image-Turbo (Tongyi-MAI, Apache-2.0) text-to-image: a 6B
guidance-distilled single-stream DiT that renders legible text in
images (English and Chinese), 8 steps, no CFG.
Architecture (ported from the diffusers reference, Apache-2.0)
30 trunk blocks + 2 modulated noise-refiner + 2 unmodulated
context-refiner blocks; sandwich RMSNorms (learned norm before AND
after attention/FF); scale/gate-only modulation with tanh-squashed
gates (no shift); SwiGLU with separate gate weights; 3-axis RoPE
theta 256; sub-sequences padded to multiples of 32 with learned pad
tokens.
flux_attentionreused as-is (bias = FALSE).(tokenizer files are byte-identical between the checkpoints); only
the chat template differs (
enable_thinking = TRUE, no think block)and the pipeline takes the penultimate hidden state, mask-sliced to
the caption length.
VAE config is the flux-dev autoencoder).
linspace(1, 1/N, N); the model consumes the reversed normalized
timestep (1000 - t)/1000 and its output is negated before the Euler
step.
family-hook machinery; cast set is the 7 core linears x 34 blocks =
238 weights, adaLN/embedders stay bf16. The fp32-shipped checkpoint's
pass-through residents are stored bf16.
Allocator gc-gate fix (cross-model)
Generation initially ran at ~142 s regardless of resolution; profiling
showed 89% of wall time in R gc (~2,200 gcs x 62 ms). torch's
allocated/reserved ratio gate (0.95) is chronically exceeded under
backend:native (steady state 0.957), firing the R-gc callback on
nearly every CUDA allocation — and
start_torch()reads the gateoptions only once at init, so mid-session option changes are inert.
.flux_gc_gates()now pushes thresholds into the live allocator:ratio gate off, absolute allocated_rate 0.65 as the
garbage-accumulation gate, footprint-based reserved_rate as the net.
Measured 1024x1024 on the RTX 5060 Ti 16 GB:
Verification
ids bit-exact, full tiny-model forward < 1e-4, strict bidirectional
key censuses, chat-template token ids exact against the shipped
tokenizer (CJK/emoji included), quantized round trips (NF4 + streamed
and resident fp8). Full suite: 692/692.
call names per paired scope): clean; only dead defaults and
omni-only constants differ.
reproduced identically before/after the gate fix.
Sample outputs in ~/Sync (zimage_sign_1024.png shows the text
rendering).