Fix cross-origin isolation to resolve TTS crash and slow ASR on HuggingFace

#4
Liquid AI org
No description provided.
Paulescu changed pull request status to open
Liquid AI org

Problem

Two bugs appear when the app runs on HuggingFace Spaces but not
locally:

  • TTS crashes with Error: input 'depth_slices_in' is missing in 'feeds'
  • ASR is ~6x slower (0.8 tok/s on HF vs 4.6 tok/s locally)

Root cause

HuggingFace's static file server does not send the
Cross-Origin-Opener-Policy: same-origin
and Cross-Origin-Embedder-Policy: require-corp headers
required for cross-origin isolation.
Without them, SharedArrayBuffer is blocked by the browser,
which breaks ONNX Runtime Web's
WebGPU backend:

  • The vocoder's depth_slices gpu-buffer tensor cannot be
    passed between session.run() calls,
    causing the TTS crash at step 1 of the vocoder loop
  • WASM falls back to single-threaded, causing the ASR slowdown

Locally, Vite's dev server injects these headers, so the issue
is invisible until deployed.

Fix

A coi-serviceworker.js service worker that intercepts all HTTP
responses and injects COOP/COEP
headers client-side. This is the standard approach used by many
HuggingFace WebGPU demos.

Files changed

  • public/coi-serviceworker.js: new service worker (dual-mode:
    registers itself, then adds headers to all responses)
  • index.html: loads the service worker before main.js
  • vite.config.js: adds COOP/COEP headers to the preview
    server block (mirrors the existing server block)
Paulescu changed pull request title from Fix cross-origin isolation to resolve TTS crash and slow ASR on HuggingFace to [WIP do not merge]Fix cross-origin isolation to resolve TTS crash and slow ASR on HuggingFace
Paulescu changed pull request title from [WIP do not merge]Fix cross-origin isolation to resolve TTS crash and slow ASR on HuggingFace to Fix cross-origin isolation to resolve TTS crash and slow ASR on HuggingFace
ykhrustalev changed pull request status to merged

Sign up or log in to comment