Nekochu's picture
Add the audio encoder (wav2vec2 + projection, variable length) fp16/fp32; update card
f11143e verified
|
Raw History Blame Contribute Delete
5.07 kB
metadata
license: cc-by-nc-4.0
library_name: onnxruntime
base_model: TaekyungKi/AvatarForcing
tags:
  - webgpu
  - onnx
  - onnxruntime-web
  - talking-head
  - avatar
  - avatar-forcing

Avatar Forcing, portrait encoder and renderer, ONNX for the browser (WebGPU)

The two image-side networks of Avatar Forcing (Ki et al., KAIST, CVPR 2026, arXiv 2601.00664), converted to ONNX from the authors' motion_autoencoder.pth for onnxruntime-web on WebGPU. Demo: WeReCooking/AvatarForcing-WebGPU.

Licence: CC BY-NC 4.0, inherited from the original weights. Non-commercial use, with attribution to the authors.

File What Size
encoder_fp16.onnx / encoder_fp32.onnx portrait (1×3×512×512, values in [-1,1]) → identity style x_r (512) + 7 feature maps; run once per portrait 44 / 87 MB
decoder_fp16.onnx / decoder_fp32.onnx style wa (512) + the 7 feature maps → one 512×512 frame; run per frame (batch 1) 49 / 94 MB
flow_step_fp16.onnx / flow_step_fp32.onnx one pass of the 8-layer speech-to-motion transformer with KV cache (2 guidance branches × 12 tokens); inputs x, c, wr, freqs, ada, fada + per-layer caches sk/sv/ck/cv, output y. For timing now; the sampler around it is not published yet 272 / 544 MB
audio_encoder_fp16.onnx / audio_encoder_fp32.onnx raw 16 kHz PCM wav [1, n·640] (no normalisation, whole video frames) → audio features wa [1, n, 512] at 25 fps: wav2vec2-base-960h with its CNN features interpolated to 25 fps before the transformer, all 12 layers' outputs stacked and projected (the original AudioEncoder.inference). Variable length 198 / 397 MB
motion_basis_512x20.f32 the 512×20 orthonormal motion basis (float32, row-major): wa = x_r + basis @ lambda for a 20-number motion vector lambda 41 KB

Not included: the sampler/timestep/audio-conditioning pieces around the flow step, and the voice/chat parts of the original pipeline.

Conversion notes (what mattered)

  • The decoder's per-sample modulated convolution is rewritten as conv(x · style) · demod (the same algebra as mlx_port/decoder_fast_torch.py in AvatarVoice); the original grouped form does not export cleanly.
  • fp16 keeps the image warp (grid_sample) in fp32. A fully fp16 decoder breaks the picture (about 4 dB PSNR); with the warp in fp32 it is visually lossless.
  • Float→float Cast nodes on constants are folded away (convert/fold_casts.py): ONNX Runtime Web's WebGPU backend otherwise refuses to build the session ("Provider type for Cast node is not set").
  • The flow step uses the legacy exporter (the dynamo one silently gets 3 of 12 frames wrong), with attention written as explicit softmax plus a mask and a "row has any visible key" factor to match torch's zeros for fully masked rows (this also removes IsNaN, which WebGPU lacks).
  • Encoder/decoder were exported with the dynamo exporter, opset 19 (GridSample is available for opset 16–19), single-file (no external data).

Verification (CPU/software reference, real weights, one portrait)

Check Result
decoder fp32 ONNX (ORT CPU) vs original PyTorch max abs error 1.3e-5 (pixels in [-1,1])
decoder fp32 through ORT-Web WebGPU (software adapter) max abs 5.5e-5, 124.8 dB PSNR
decoder fp16 ONNX (ORT CPU) vs fp32 original max abs 0.007, mean abs 0.0003
fp16 encoder → fp16 decoder chain (PyTorch) vs fp32 66.2 dB PSNR (8-bit display rounding alone is 58.6 dB)
encoder fp32 ONNX vs original max abs 1e-5
flow step fp32 ONNX (ORT CPU) vs original PyTorch, real weights, 8 layers max abs 2e-4 on outputs up to 12
flow step fp32 on ORT-Web WebGPU (software adapter) vs ORT-Web CPU max abs 7e-5, no CPU fallbacks
audio encoder fp32 ONNX (ORT CPU) vs PyTorch, two clip lengths max abs 1.4e-5; the explicit layer loop equals the repo's own Wav2VecModel exactly
audio encoder fp32 on ORT-Web WebGPU (software adapter) vs PyTorch max abs 7e-5, a second clip length on the same session matches CPU to 1e-4
audio encoder fp16 ONNX vs fp32 0.1% mean relative error; finite for quiet (×0.05), normal and loud (×3) input
flow step fp16 ONNX (ORT CPU) vs fp32 original mean relative error 0.46%, max abs 0.19 (single pass, random inputs). Not yet checked through the full 9-pass sampler, where rounding can compound

Not verified here: speed or fp16 behaviour on a physical GPU (no GPU was available). The demo page measures that on the visitor's machine and falls back to fp32 automatically if fp16 is rejected.

Credits

Original model and weights: Taekyung Ki, Sangwon Jang, Jaehyeong Jo, Jaehong Yoon, Sung Ju Hwang (KAIST / NTU / DeepAuto.ai). Streaming and engineering ideas: johnrobinsn/AvatarVoice.