Skip to content

qwen_image: Qwen-Image-2.1 text to image on MLX (draft proposal, non-lane family, stacked on #384) - #393

Closed
drowzeys wants to merge 4 commits into
ashhart:mainfrom
drowzeys:qwen-image
Closed

drowzeys wants to merge 4 commits into
ashhart:mainfrom
drowzeys:qwen-image

Conversation

@drowzeys

@drowzeys drowzeys commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Draft, as a proposal, stacked on #384. Like the H3 draft, this is a model family outside the lane rules, and CONTRIBUTING asks for an issue first. I am opening it as a draft so the code and measurements sit beside #384 for the same conversation; close it if image generation does not belong in TensorFold. Only the last two commits are new here; the first two are #384's, because this family runs on the int8 kernels that one adds.

Thank you first: this stands on your family and kernel structure. The model code is adapted from mflux (Filip Strand and contributors), whose qwen21 model follows Qwen and Hugging Face's diffusers pipeline. THIRD_PARTY_NOTICES.md records both.

What it is

Qwen-Image-2.1 is a text-to-image model: a 7B single-stream transformer (32 blocks, hidden 4,096, 32 heads of 128, SwiGLU width 12,288) denoises 64-channel latents, and a convolutional decoder turns them into pixels. This adds families/qwen_image:

  • the transformer on the released bfloat16 checkpoint, with the text prefix run once per prompt and its keys and values reused on every step;
  • the resolution-shifted schedule and Euler loop, with fixed nodes for a distilled adapter;
  • adapters in the diffusers LoRA layout, merged in float32;
  • the image decoder;
  • the H3 int8 SwiGLU, fused QKV and attention-output kernels from h3: MiniMax H3 video and audio generation on MLX (draft proposal, non-lane family) #384, reused unchanged;
  • docs/recipes/qwen-image-2.1.md with the measurements, and rows in the family and recipe tables.

No new kernel. The fused QKV kernel rotates channel c with c + 64 and this model rotates neighbours, so the q and k rows are reordered within each head to [even, odd] before quantizing; the dot product between them does not see a shared channel order. A test checks that.

Where it does not fit the rules

  1. Lanes. The model does not decode tokens. The family exports no load, sets LANES = False, and tensorfold serve does not route it. Nothing in the lane engine, the server or any existing family is touched.
  2. Exact output. There is no drafted-against-serial contract. What I can state: on random inputs the bfloat16 transformer output has cosine 0.9995 to 0.9999 with mflux's and the decoder 0.99996; the schedule equals mflux's to 1e-7. That is close, not equal: I did not find where the bfloat16 difference comes from, and I think it is operation order, but I have not shown it.
  3. No precision traded for speed. The int8 kernels trade precision, on purpose, and the tool turns them on by default (--no-int8 keeps bfloat16). Same seed and prompt against mflux: 32.7 dB in bfloat16, 30.4 dB in int8.

It is not complete

  • The prompt encoder (Qwen3-VL language model and tokenizer) is not ported. tools/qwen_image_generate_dev.py borrows mflux's, so the tool needs mflux on the path.
  • Text to image only: no editing, reference images, RGBA output, guidance with a negative prompt, or VAE encoder. mflux has all of these.
  • No tensorfold generate, no checkpoint detection through families.detect, no resident engine.

Receipt

  • Environment. TensorFold 0.6.5 + h3: MiniMax H3 video and audio generation on MLX (draft proposal, non-lane family) #384 + these commits, MLX 0.32.3, Mac Studio M5 Ultra 256 GB, macOS 27.0.1. Checkpoint Qwen/Qwen-Image-2.1. Reference: mflux add5164. Adapter: Viggle/Qwen-Image-2.1-viggle-turbo v0.3, rank 256.

  • Exactness. bench_concurrent.py and token_sha do not apply. tools/qwen_image_parity_dev.py prints the figures in point 2.

  • Speed, one prompt (94 text tokens), 1344x768 (4,032 image tokens), seed 42, one run each:

    Steps Per step Denoise Whole run
    mflux add5164, bfloat16 40 0.73 s 29 s 40.7 s
    this family, bfloat16 40 0.78 s 31.0 s 34.3 s
    this family, int8 MLP, QKV, attention output 40 0.48 s 19.2 s 24.3 s
    this family, int8, turbo adapter on its six nodes 6 0.50 s 3.0 s 9.2 s

    In bfloat16 this is slower per step than mflux, which compiles its step. The gain is the int8 kernels and the adapter.

  • Prompt speed. Not applicable; no prefill, kernel, engine or server path of an existing family is changed.

  • Tests. Host suite on the M5 Ultra: 4997 passed, 609 skipped, 14 failed. The same 14 fail on untouched 0.6.5 in this environment (listed in h3: MiniMax H3 video and audio generation on MLX (draft proposal, non-lane family) #384). New: tests/test_qwen_image_family.py, 15 tests on small random models, including that the stored text prefix equals a joint block-causal pass.

  • What I did not run. Any Mac other than an M5 Ultra. Other image sizes, more than one prompt and seed, text rendering. CUDA: the family has no CUDA engine.

Notes for landing

  • This depends on h3: MiniMax H3 video and audio generation on MLX (draft proposal, non-lane family) #384. If that one is not wanted, this one has no kernels to run on in int8, though the bfloat16 path stands alone.
  • Files are under 400 lines each.
  • The first commit of this pair carries a tool co-author trailer; I know you remove those when you land a commit.
  • Qwen-Image-2.1 is under the Qwen Research License Agreement, non-commercial. No weights are included.

A packaged install that chains this into MiniMax H3 (text to image to video) is at https://github.com/drowzeys/keys-Mac-TensorFold-Studio.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PrUiTH1dGwnVKrpFLkoGHj

drowzeys and others added 4 commits October 4, 2026 09:16
A non-lane family: the 33B diffusion transformer, packed sequence, schedules
and joint denoise loop, adapter merging in float32, int8 MLP / QKV / attention
output kernels on the M5 tensor units, and the video decoder. The transformer
and the float32 video decode equal minimax-h3-mlx's on real inputs.

The text encoder, audio decoder and MP4 writer are not ported;
tools/h3_generate_dev.py borrows minimax-h3-mlx's. docs/recipes/minimax-h3.md
has the measurements.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PrUiTH1dGwnVKrpFLkoGHj
The sampler takes encoded keyframe rows, noises them to 0.999 from the request
generator before the video and audio noise (the reference's draw order), holds
them for every step and steps only the generated rows. The tool's --first-frame
encodes the image with minimax-h3-mlx's VAE encoder and vision tower.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PrUiTH1dGwnVKrpFLkoGHj
… int8 projections

Text to image on the H3 int8 tensor-unit kernels. The text prefix is run once per prompt. The prompt encoder is
borrowed from mflux by the development tool.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PrUiTH1dGwnVKrpFLkoGHj
@ashhart

ashhart commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Thank you, @drowzeys. Keeping the text prefix's keys and values across every denoising step, with a test that the stored prefix equals a joint block-causal pass, is a nice touch, and you were candid about the bf16 gap to mflux.

We're closing it for the same reasons as #384. Qwen-Image denoises rather than decodes, so there is no lane round for it, its int8 kernels are on by default and trade precision, and it is an MLX family, while the Python engine is frozen (#286) and the Zig engine drives Metal directly. It also stands on #384, which we're closing too.

Thanks for proposing it in the open. Your GLM-5.3 work in #159 is the kind we want, and it waits for GLM on the Zig engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants