Instructions to use cgb/wan21-self-forcing-onnx-webgpu with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- SelfForcing
How to use cgb/wan21-self-forcing-onnx-webgpu with SelfForcing:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Wan 2.1 T2V-1.3B with Self-Forcing, ONNX for the browser
Text to video that runs entirely inside a web browser on WebGPU, through ONNX Runtime Web. The weights download once, the browser keeps them, and every frame is drawn on the visitor's own GPU. Nothing is sent to a server.
Try it without installing anything
Make a video at freegen.ai/video
That page runs this exact pack. On an RTX 5090, once the models are loaded:
| Clip | Time | Peak GPU memory |
|---|---|---|
| 2 s (33 frames), 416 x 240 | about 11 s | 7.5 GiB |
| 5 s (81 frames), 832 x 480 | about 55 s | 12.4 GiB |
The first visit downloads 4.6 GB. After that it works offline.
"A red fox sitting in fresh snow at dawn, soft golden light". First, one-third,
two-thirds and last frame of an 81-frame 832 x 480 clip, generated in Chrome.
What's in here
Three models, converted and quantized:
- Wan 2.1 T2V-1.3B by the Wan team at Alibaba, Apache-2.0. Its umT5 text encoder and its diffusion transformer architecture.
- Self-Forcing by Xun Huang et al., Apache-2.0. Distilled weights for the same transformer that generate a clip causally, three latent frames at a time in four steps each, attending to a cache of everything already drawn. That is what makes this practical in a browser: no 50-step sampling over the whole clip at once.
- TAEHV by Ollin Boer Bohan, MIT.
A tiny decoder for Wan's latents, about 20 MB instead of the full VAE.
Its licence is in
LICENSE-TAEHV.
This is a modified derivative and not an official release of any of them.
| File | What it is | Size |
|---|---|---|
text_encoder_q4.onnx + 3 shards |
umT5-XXL encoder, int4 weights, int8 token table | 3.47 GB |
transformer_q8-00000.data |
Self-Forcing weights, int8 (block 128) | 1.47 GB |
transformer_q8_v3.onnx |
chunk denoiser graph, attention as chunked MatMuls | 3 MB |
transformer_q8_v5.onnx |
same weights, fused self-attention | 3 MB |
transformer_seg-00 to -30 (.onnx + .data), transformer_seg.json |
the v5 graph cut at its 30 self-attention nodes, for a custom attention kernel between the pieces | 1.47 GB |
taehv_decoder.onnx |
TAEHV decoder, fp16 | 20 MB |
tokenizer/ |
umT5 tokenizer | |
wan-pack.json |
pack marker the site probes for |
Both denoiser graphs read the same weights file. v3 is faster when there is little to attend to (short, small clips); v5 is much faster and lighter once the cache grows, because it never builds the full attention score matrix. At the last chunk of a 5-second 480p clip a pass takes 3.75 s and 4 GiB with v5 against 6.0 s and 15 GiB with v3. The site picks one per clip.
The segmented build is what freegen.ai runs. ONNX Runtime Web cannot run a
custom kernel inside a graph, so the denoiser is cut where self-attention
happens: segment i outputs layer i's queries and the chunk's new keys and
values, FreeGen's WebGPU flash-attention kernel attends over the cache, and its
output feeds segment i + 1. transformer_seg.json lists each segment's inputs
and outputs. On an RTX 5090 that kernel runs the largest call at about 26
TFLOPS against about 10 for ONNX Runtime's fused attention, and a 5-second
480p clip takes about 55 s instead of 73.
Weight files are split below 2 GiB because a browser cannot hold a single
larger buffer. Each graph's *.manifest.json lists its shards; pass them to
InferenceSession.create as externalData.
How a clip is drawn
prompt -> umT5 (512 tokens, zero-padded) -> text [1, 512, 4096]
for each chunk of 3 latent frames:
x = noise
for sigma in the 4 Self-Forcing steps (timesteps 1000, 750, 500, 250, shift 5):
flow = denoiser(patchify(x), sigma * 1000, text, rope(chunk), past keys/values)
x0 = x - sigma * flow
x = (1 - next_sigma) * x0 + next_sigma * fresh_noise
denoiser(patchify(x0), t = 0, ...) # its keys and values join the cache
decode with TAEHV, 3 latent frames at a time with 3 before them as context
The denoiser's inputs are patches [1, S, 64] fp16, timestep [1] fp32,
text [1, 512, 4096] fp16, rope_cos and rope_sin [1, S, 1, 64] fp32, and
past_k_N / past_v_N [1, L, 12, 128] fp16 for each of the 30 layers. It
returns flow [1, S, 64] and present_k_N / present_v_N, which are the
chunk's own keys and values, [1, S, 12, 128]. Keep the cache on the GPU
(preferredOutputLocation: "gpu-buffer") and append each chunk's presents to
it yourself; copying gigabytes to the CPU and back between calls costs more
than the model.
FreeGen's own driver for this pack is not public yet; the steps above are everything it does. The story of the build, with the numbers: Text to video in a browser tab, on your own GPU.
Things that went wrong on the way
Each of these produced either an error or, worse, a plausible-looking wrong video.
- Current transformers loads umT5 without its token embeddings. The
checkpoint stores them once as
shared.weight, andencoder.embed_tokenscame up randomly initialised. Every prompt produced a coherent clip of something nobody asked for. The tie is restored before export. - umT5 checks its fp16 hidden states with IsInf, which ONNX Runtime's
WebGPU backend has no kernel for, so the session would not even load. Each
one is rewritten as
abs(x) > 65504. - Buffers you create yourself get destroyed. ORT unregisters an input GPU
buffer after each run, and for a buffer the page made, the last unregister
destroys it. A cache allocated with
device.createBufferwas gone by the second chunk. Buffers ORT allocated as outputs are never released that way, so the cache comes from a tinyExpand(0, shape)graph instead. - Returning past-plus-new from the graph does not scale. Every chunk then needs new, larger buffers, and the runtime pools the old ones. A 5-second 480p clip reached 28.7 GiB and started spilling into system RAM. Returning only the new chunk and copying it into a cache allocated once, at the clip's full length, keeps memory flat.
- TAEHV over a whole 480p clip passes the 2 GB buffer limit. It decodes three latent frames at a time with three earlier frames as context, which matches decoding the clip whole at 51 dB. Above 256 x 448 each window is also decoded in overlapping spatial tiles, which match whole frames at 53 dB.
More models that run in your browser
FreeGen runs open models entirely on your own machine. Nothing is uploaded, there is no account, and there is no per-use cost.
| Video | Text to video with Wan 2.1 and Self-Forcing (this pack) |
| Imagine | Images from text with FLUX.2 Klein or Z-Image Turbo |
| Shape | A photo to a 3D model with TripoSR or TripoSG, auto-rigged |
| Chat | A private assistant that streams on your GPU |
| Transcribe | Whisper, up to large-v3-turbo |
| Speak | Text to speech with 28 Kokoro voices |
| Look | Captions, object detection, OCR and questions about a picture |
| Edit | Cut out, remove objects, upscale and depth maps |
Model tree for cgb/wan21-self-forcing-onnx-webgpu
Base model
Wan-AI/Wan2.1-T2V-1.3B