|
Download README.md from WeReCooking/DFlow2-4step-ONNX-WebGPU: direct link, hf CLI and curl.
- Browser
- Download file 6.83 kB
-
https://huggingface.co/WeReCooking/DFlow2-4step-ONNX-WebGPU/resolve/main/README.md
- Command line
-
hf download hf://WeReCooking/DFlow2-4step-ONNX-WebGPU/README.md
-
curl -L -o README.md https://huggingface.co/WeReCooking/DFlow2-4step-ONNX-WebGPU/resolve/main/README.md
6.83 kB
| license: other | |
| license_name: mg-by-nc-2.0 | |
| license_link: LICENSE | |
| base_model: | |
| - data-archetype/dflow_2b | |
| - lvladikov/DFlow2-Distill-4steps-eDMD-LADD-LoRA | |
| base_model_relation: quantized | |
| pipeline_tag: text-to-image | |
| library_name: onnxruntime | |
| tags: | |
| - onnx | |
| - webgpu | |
| - onnxruntime-web | |
| - text-to-image | |
| - dflow | |
| - few-step | |
| # DFlow2 4-step, ONNX for WebGPU | |
| [dflow_2b](https://huggingface.co/data-archetype/dflow_2b) (v0.215) with the 4-step | |
| [eDMD + LADD LoRA](https://huggingface.co/lvladikov/DFlow2-Distill-4steps-eDMD-LADD-LoRA) (`chk00003000`) | |
| merged in, converted to ONNX so it runs in a web browser on the visitor's own GPU with | |
| [ONNX Runtime Web](https://onnxruntime.ai/docs/tutorials/web/). No server, no Python. | |
| **Try it:** [WeReCooking/DFlow2-WebGPU](https://huggingface.co/spaces/WeReCooking/DFlow2-WebGPU) | |
| ## Files | |
| | part | runs on | weights | what it does | | |
| |---|---|---|---| | |
| | `text/` | WASM (CPU) | 8-bit | T5Gemma 2 encoder layers 1 to 12, the three tap projections, the learned suffix tokens and the 2 text-refiner blocks | | |
| | `q8/dit_a/` … `q8/dit_d/` | WebGPU | **8-bit (default)** | the 2B denoiser in four parts: embed + 6 prefix blocks, 9 + 9 middle blocks, tail join + 6 suffix blocks + velocity head | | |
| | `q4/dit_a/` … `q4/dit_d/` | WebGPU | 4-bit, AdaLN 8-bit | the same, smaller and visibly softer, for devices short on memory | | |
| | `vae_trunk/` | WebGPU | 8-bit | [dinac3_96](https://huggingface.co/data-archetype/dinac3_96) decoder: de-whitening and the 4-block transformer trunk (global) | | |
| | `vae_head/` | WebGPU | fp32 | the decoder's convolutional up-path (local), run tile by tile, output in [0, 1] | | |
| | `embed_bf16.bin` | | bf16, raw | token embeddings `[262144, 640]`, read row by row with HTTP Range (a prompt needs a few KB of it) | | |
| | `tokenizer.json` | | | the T5Gemma 2 tokenizer | | |
| | `manifest.json` | | | part sizes and the total per variant, for download progress | | |
| Download: about **2.7 GB** with the 8-bit denoiser, 1.7 GB with the 4-bit one. The page stores it in the | |
| browser after the first visit. | |
| Weights are `MatMulNBits` (block 32, asymmetric) with fp32 activations, so they run on any WebGPU device, | |
| including ones without `shader-f16`; both bit widths run natively on the WebGPU backend. The text graph | |
| stays on WASM because Gemma's hidden states have channels far outside fp16 range. | |
| Two things keep GPU memory bounded so the trained ~1 MP sizes fit on more devices: | |
| - **Attention runs one head at a time** inside the graphs (same math as SDPA). The largest score | |
| tensor is `[1, 1, S, S]` instead of `[1, 18, S, S]`: 214 MB instead of 3.9 GB at 1824×1024. | |
| - **The decoder is split** into its global trunk and its local up-path. The up-path runs in tiles that | |
| overlap by 8 latent cells, wider than its receptive field (about 6.6 cells), so the tiled result is | |
| identical to one pass (measured maximum difference 0.0). The page sizes the tiles from the GPU's | |
| largest allowed buffer. | |
| All RoPE tables are graph inputs computed by the page, so every graph takes any image size (multiple | |
| of 16) and any prompt length up to 256 tokens. | |
| ## Sampling | |
| 4 Euler steps, CFG and path-drop guidance off, the `beta_1_25` schedule with the training resolution | |
| shift `s = min(0, -0.25 - ln(W·H / 256²))`, self-attention gain -0.03 up to about 1 MP (closer to 0 | |
| above), as the LoRA was trained. The JS schedule reproduces the LoRA's recorded grids exactly | |
| (`[1.0, 0.920527, 0.816588, 0.631176, 0.0]` at 832×1216, `[1.0, 0.940256, 0.858143, 0.699269, 0.0]` at 1824×1024). | |
| The page draws its starting noise exactly as dflow does (`torch.randn` on a CPU generator: mt19937, | |
| then Box-Muller in blocks of 16; the JS port matches PyTorch to about 2e-6), so a seed gives the same | |
| picture as in dflow or ComfyUI. Seed 4242 at 1824×1024 with a card prompt reproduces that LoRA card image. | |
| The model and the LoRA were trained at about 1 MP and above. Detail scales with the token count | |
| (one token per 16×16 pixels), so 512×512 is a quick preview, not a fair look at the model. | |
| ## How it was checked | |
| 1. **The recipe reproduces the LoRA card.** A float32 PyTorch run of the release code on CPU, with the | |
| card's prompt, seed 4242 and size 1824×1024, gives the card's snow leopard: same pose, spots and | |
| snowflakes, 32.0 dB from the card image (the card was rendered in bf16 on a GPU and saved as JPEG). | |
| 2. **The ONNX graphs against that run, same noise, 1824×1024:** | |
| | | velocity cosine, steps 1 to 4 | final image vs fp32 | | |
| |---|---|---| | |
| | fp32 ONNX | 1.000000 at every step | 125 dB (512×512) | | |
| | **8-bit denoiser** | 0.99999, 0.99996, 0.99980, 0.99886 | **37.4 dB**, indistinguishable | | |
| | 4-bit denoiser | 0.99906, 0.99522, 0.98175, 0.96403 | 23.1 dB, face drifts, colour and fur contrast fade | | |
| 3. **The browser matches ONNX Runtime on CPU.** The JS tokenizer, RoPE, schedule, Euler loop and tiled | |
| decoder, run in Chromium on WebGPU, matched ONNX Runtime on CPU to a cosine of 0.99999999 on the final | |
| image, and the JS tokenizer matched dflow's Python token ids on every test prompt (quoted text included). | |
| `scripts/` holds the export, quantization, verification and comparison code. | |
| ## Licences | |
| Different parts come under different terms; all of them allow redistribution with the notices below. | |
| - **dflow_2b weights and the LoRA:** ModelGo Attribution-NonCommercial License 2.0 (MG-BY-NC-2.0), | |
| [`LICENSE`](LICENSE). Non-commercial use only. | |
| This project uses dflow_2b by Data Archetype. | |
| https://huggingface.co/data-archetype/dflow_2b | |
| The LoRA is by lvladikov, | |
| https://huggingface.co/lvladikov/DFlow2-Distill-4steps-eDMD-LADD-LoRA, under the same licence | |
| ([`licenses/LICENSE-LoRA-MG-BY-NC-2.0`](licenses/LICENSE-LoRA-MG-BY-NC-2.0)). | |
| - **Text encoder (`text/`, `embed_bf16.bin`, `tokenizer.json`):** Gemma is provided under and subject to the | |
| Gemma Terms of Use found at gemma.ai/resources/terms. A copy is in | |
| [`licenses/LICENSE-GEMMA.md`](licenses/LICENSE-GEMMA.md); use is subject to the restrictions in its | |
| Section 3.2, including the Gemma Prohibited Use Policy at gemma.ai/resources/prohibited_use_policy. | |
| Modification notice: these files derive from Data Archetype's modified copy of part of | |
| google/t5gemma-2-270m-270m (tokenizer, token embeddings, encoder layers 1 to 12). In November 2026 they | |
| were further converted to ONNX, with the encoder layers quantized to 8 bits and the embeddings stored as | |
| a raw bfloat16 table. | |
| - **Decoder (`vae_dec/`):** from data-archetype/dinac3_96, Apache-2.0 | |
| ([`licenses/LICENSE-dinac3_96-Apache-2.0`](licenses/LICENSE-dinac3_96-Apache-2.0)), with the DINOv3 | |
| License Agreement it ships ([`licenses/LICENSE-DINOV3.md`](licenses/LICENSE-DINOV3.md)). Converted to | |
| ONNX and quantized to 8 bits. | |
| Third-party material is listed in `licenses/ATTRIBUTION-*.md`. | |