File size: 12,631 Bytes
6d40ed4
 
6fbf132
6d40ed4
 
 
 
6fbf132
6d40ed4
 
 
 
6fbf132
 
 
 
 
 
8b07139
 
 
b0e1116
8b07139
 
b0e1116
 
 
 
 
 
 
 
 
 
 
2f43f14
6fbf132
 
 
 
2f43f14
6fbf132
 
 
 
2f43f14
6fbf132
2f43f14
2068cdf
6fbf132
b8da4d0
6fbf132
7237e0c
6fbf132
7237e0c
 
 
 
 
 
6fbf132
 
02d9211
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3836ca
2f43f14
8dbaad1
 
 
 
 
 
 
 
 
 
 
 
 
068891c
 
 
61977d0
 
068891c
2f43f14
1e63182
2f43f14
1e63182
 
 
 
f51fe79
 
1e63182
f51fe79
 
1e63182
f51fe79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e63182
6d40ed4
 
 
 
f58d369
7552666
f58d369
c31fd28
 
6d40ed4
fd5e763
 
 
6d40ed4
 
 
 
 
7552666
6fbf132
 
 
6d40ed4
 
 
6fbf132
 
 
 
462ac47
7237e0c
6d40ed4
 
 
 
 
 
 
6fbf132
 
 
 
 
 
 
 
6d40ed4
 
6fbf132
02d9211
2f43f14
6fbf132
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
---
base_model: Tongyi-MAI/Z-Image-Turbo
license: apache-2.0
tags:
- orbitquant
- quantized
- diffusers
- diffusion-transformer
---

# Tongyi-MAI/Z-Image-Turbo OrbitQuant W4A4

This repository contains a compact OrbitQuant transformer-component artifact for the source Diffusers model listed above. It is intended to be loaded into the original pipeline, not used as a standalone Diffusers pipeline repository.

OrbitQuant is a calibration-free post-training quantization method for image and video diffusion transformers. This artifact keeps the text encoders, VAE, embeddings, timestep MLP, and final heads in the source precision by default and replaces the transformer linear projections with OrbitQuant modules.

## Usage

Install OrbitQuant and the Hugging Face runtime dependencies:

```bash
pip install "orbitquant[hf,kernels]>=0.6.0"
```

The optimized native kernel package is provisioned automatically at first
model load: OrbitQuant derives the runtime variant (torch minor and CUDA
version for CUDA, the torch stable ABI for CPU, plus OS and architecture),
downloads the matching prebuilt wheel from the
[OrbitQuant kernels release](https://github.com/iamwavecut/OrbitQuant/releases/tag/kernels-v1)
with checksum verification, and caches it under `~/.cache/orbitquant/kernels`.
Without a matching variant, CUDA inference falls back to the Triton packed
path. Run `orbitquant kernels-install` to provision explicitly. For ComfyUI,
the [ComfyUI-OrbitQuant](https://github.com/iamwavecut/ComfyUI-OrbitQuant)
node pack provisions the same kernels from its install hook.

Download this model repository as an OrbitQuant artifact, then load the source Diffusers pipeline with the quantized component patched in:

```python
import torch
from huggingface_hub import snapshot_download
from orbitquant import load_quantized_pipeline_from_artifact

artifact_id = "WaveCut/Z-Image-Turbo-OrbitQuant-W4A4"

artifact_dir = snapshot_download(artifact_id, repo_type="model")
pipe = load_quantized_pipeline_from_artifact(
    artifact_dir,
    torch_dtype=torch.bfloat16,
    runtime_mode="auto_fused",
)
pipe.enable_model_cpu_offload(device="cuda")

image = pipe(
    prompt="A precise product photo of a red ceramic mug on a wooden desk",
    height=1024,
    width=1024,
    num_inference_steps=10,
    guidance_scale=0.0,
).images[0]
image.save("z-image-orbitquant.png")
```

### Convert the source checkpoint on load

For a safetensors source checkpoint, OrbitQuant can row-stream the denoiser into packed weights through the normal Diffusers loader. Use sequential offload by replacing the final call with `pipe.enable_sequential_cpu_offload()`.

```python
import torch
import orbitquant
from diffusers import DiffusionPipeline
from orbitquant import (
    OrbitQuantConfig,
    build_diffusers_pipeline_quantization_config,
)

qconfig = build_diffusers_pipeline_quantization_config(
    OrbitQuantConfig(target_policy="auto"),
    components="transformer",
)
pipe = DiffusionPipeline.from_pretrained(
    "Tongyi-MAI/Z-Image-Turbo",
    quantization_config=qconfig,
    torch_dtype=torch.bfloat16,
)
pipe.enable_model_cpu_offload()
```

`runtime_mode="auto_fused"` is the default optimized runtime. On CUDA, the `kernels` extra provides the Triton packed fallback; a locally built native CUDA package is preferred automatically when installed. On MPS, build and install the native Metal package from the OrbitQuant source tree. See the [OrbitQuant runtime instructions](https://github.com/iamwavecut/OrbitQuant/blob/main/docs/kernel-audit.md#local-native-package). Use `runtime_mode="dequant_bf16"` only as an explicit compatibility/debug reference path.

## Native Settings

Use these settings when comparing this artifact against the BF16 source model or the visual assets below:

| Setting | Value |
| --- | --- |
| Pipeline | `ZImagePipeline` |
| Resolution | `1024x1024` |
| Inference steps | `10` |
| Guidance scale | `0.0` |
| Output | image |
| Scope | paper image target |

## Validation Status

- Native BF16-vs-OrbitQuant comparison: included when the visual matrix below is present.
- Release-grade GenEval metrics: not included in this artifact.
- The model card reports artifact-level validation status only.

## Native Validation Evidence

The compact benchmark summary records native BF16-vs-OrbitQuant evidence for the comparison matrix below. Detailed per-sample generation records are retained outside this compact artifact.

| Evidence | Value |
| --- | --- |
| Comparison matrix | `assets/image_generation_comparison_matrix.webp` |
| Paired prompt/seed count | `10` |
| BF16 source generated samples | `10` |
| BF16 source generated frames | `0` |
| BF16 source nonempty outputs | `10` |
| OrbitQuant generated samples | `10` |
| OrbitQuant generated frames | `0` |
| OrbitQuant nonempty outputs | `10` |

## Comparison Prompt Set

The matrix uses all ten prompts from `image_visual_v2` at `1024x1024`. BF16 and OrbitQuant use the same seed for each row.

| # | Stress case | Exact required text |
| ---: | --- | --- |
| 1 | 01 Fine-detail astrolabe | - |
| 2 | 02 Layered character composition | - |
| 3 | 03 Exact counting and choreography | - |
| 4 | 04 Dense color and object binding | - |
| 5 | 05 Nested spatial relationships | - |
| 6 | 06 Cinematic night-market panorama | - |
| 7 | 07 Editorial Latin typography | ORBIT QUANT; DATA WITHOUT CALIBRATION |
| 8 | 08 Russian Constructivist typography | КВАНТОВАЯ ОРБИТА; МОСКВА 2049; КВАНТОВАНИЕ |
| 9 | 09 Japanese typography and mixed style | 量子の軌道; 東京の未来 |
| 10 | 10 Chinese typography, reflection, occlusion | 量子轨道; 未来之城 |

<details>
<summary>Exact comparison prompts</summary>

1. **01 Fine-detail astrolabe**: A museum-grade macro photograph of a single ornate brass astronomical clock, covered with interlocking gears, engraved constellations, enamel moon phases, hair-thin hands, tiny screws, worn gilt edges, and dust caught in the mechanisms; dramatic Rembrandt lighting, black velvet background, extreme material detail, large-format photography, every cog mechanically coherent
2. **02 Layered character composition**: A lacquered white android and an elderly watchmaker facing each other across a crowded Art Nouveau workshop, jointly repairing a mechanical hummingbird; the android is on the left, the watchmaker on the right, the bird centered between them, hundreds of tools and clock parts in the midground, rain and a tram visible through the window, coherent mirror reflections, cinematic tungsten and cyan light, intricate faces and hands, editorial realism
3. **03 Exact counting and choreography**: Exactly seven masked dancers performing on seven separate illuminated platforms inside a vast flooded opera house, no extra dancers; alternating crimson and ivory costumes from left to right, each dancer in a distinct pose, balconies reflected in the water, floating candles, volumetric stage haze, baroque theatrical photography, sharp foreground and readable background architecture
4. **04 Dense color and object binding**: An elaborate surreal fashion tableau with three models: the left model wears a cobalt-blue coat and holds a yellow glass sphere, the center model wears a saffron dress and holds a green ceramic pyramid, the right model wears an emerald suit and holds a red velvet cube; rococo greenhouse, rare orchids, patterned tile floor, prismatic sunlight, magazine-cover precision, preserve every color-object pairing
5. **05 Nested spatial relationships**: A meticulous cutaway diorama of a vertical city: a glass greenhouse sits directly above a silver subway car, a red fox stands inside the greenhouse beneath a hanging moon lamp, a violinist waits below the subway platform, and a yellow airship passes behind the entire structure; isometric perspective, architectural-section drawing mixed with photoreal materials, dozens of tiny rooms, stairs and people, clean depth
6. **06 Cinematic night-market panorama**: A sweeping cinematic panorama of a rain-soaked floating night market at blue hour: in the foreground a chef plates translucent dumplings under a red silk canopy; in the midground children chase paper lanterns across narrow bridges while merchants unload exotic fruit from wooden boats; in the background a terraced megacity rises through mist beneath a storm, with hundreds of warm windows, wet reflections, steam, umbrellas, ropes and signage; deep focus, anamorphic highlights, realistic faces, coherent perspective, painterly color grading with documentary-level detail
7. **07 Editorial Latin typography**: A sophisticated Swiss International Style exhibition poster photographed behind slightly reflective museum glass, with the exact large headline "ORBIT QUANT" and the exact smaller subtitle "DATA WITHOUT CALIBRATION"; strict modular grid, red, black and white screenprint, tiny registration marks, embossed paper fibers, sharp letterforms, dramatic gallery shadows, no other text
8. **08 Russian Constructivist typography**: A richly detailed Russian Constructivist science-fiction poster with the exact Cyrillic headline "КВАНТОВАЯ ОРБИТА", the exact subtitle "МОСКВА 2049", and a small exact stamp "КВАНТОВАНИЕ"; diagonal red and black geometry, cream paper, cosmonaut portrait, orbital diagrams, halftone grain, folded corners, layered ink, museum archival photograph, all letters crisp and correctly ordered
9. **09 Japanese typography and mixed style**: An elaborate Japanese art magazine cover combining Edo woodblock printing with a futuristic Tokyo skyline, with the exact vertical title "量子の軌道" and the exact subtitle "東京の未来"; giant indigo waves curl around glass towers, red-crowned cranes cross a gold moon, tiny pedestrians and trains fill the lower streets, visible washi fibers, layered spot colors, precise Japanese glyphs, balanced editorial layout
10. **10 Chinese typography, reflection, occlusion**: A luxurious Chinese retro-futurist department-store window at night with the exact gold title "量子轨道" and the exact red subtitle "未来之城"; a curved chrome robot is partly occluded by peonies and blue-and-white porcelain, the calligraphy and neon street must appear coherently reflected across its body, multiple glass layers, silk textures, passing bicycles, cinematic rain, fine product-photography detail

</details>

## Quantization

- Method: `orbitquant`
- Bits: `W4A4`
- Runtime mode: `auto_fused`
- Activation kernel backend: `auto`
- Activation normalization epsilon: `1e-10`
- Quantization device: `cuda`
- Weight quantization backend: `triton_cuda`
- Target policy: `z_image`
- AdaLN policy: `int4_rtn_group64_bf16_activation`
- AdaLN group size: `64`
- AdaLN group-size note: paper default.
- Rotation: `rpbh`
- Rotation seed: `0`
- Block size: `paper`
- Block size policy: `largest_power_of_two_dividing_dim`
- Codebook: `lloyd_max`
- Codebook version: `2`
- Quantized transformer modules: `238`
- AdaLN INT4 modules: `32`
- Skipped modules: `6`
- Calibration data: none
- Text encoders and VAE: left in source precision by default

## Visual Comparison

The following assets are stored in this artifact and compare the BF16 base generation against the OrbitQuant generation with the same prompt and seed.

![assets/image_generation_comparison_matrix.webp](assets/image_generation_comparison_matrix.webp)

## Source

- Model: `Tongyi-MAI/Z-Image-Turbo`
- Revision: `f332072aa78be7aecdf3ee76d5c247082da564a6`
- Source license: `apache-2.0`
- OrbitQuant paper: https://arxiv.org/abs/2607.02461

## Artifact Files

- `model.safetensors`: packed OrbitQuant/INT4 module tensors.
- `quantization_config.json`: serialized OrbitQuant runtime settings.
- `orbitquant_manifest.json`: source provenance, policies, module lists, and checksums.
- `orbitquant_codebooks.safetensors`: Lloyd-Max codebooks.
- `orbitquant_rotations.safetensors`: deterministic RPBH rotation metadata.

## Limitations

- This is a transformer-component artifact; load it into the source pipeline as shown above.
- Guaranteed on-the-fly bounded-memory conversion requires a safetensors source checkpoint. Unknown architectures have structural coverage only and require policy inspection plus quality validation.
- CUDA and MPS `auto_fused` inference requires a packed matmul kernel and fails loudly when the required kernel is unavailable. The explicit `dequant_bf16` reference mode materializes dequantized weights before BF16 matmul.
- Quality depends on the source model and bit setting. Very low-bit settings can degrade prompt following or visual detail.