Commit Graph
26 Commits
Author SHA1 Message Date
RainbowBird b5b6e4fb23 chore(server): forbidden vi.mock and vi.hoist 2026-05-30 20:18:50 +08:00
RainbowBirdandLiet Blue 172e4ce59c feat(auth): email login & profile (#1745)
Co-authored-by: Liet Blue <127093491+lietblue@users.noreply.github.com>
2026-04-28 00:07:38 +08:00
147d077aa7 feat(inference): unify and optimize WebGPU inference pipeline (#1622)
## Problem

The WebGPU inference pipeline had several structural issues:

1. **No unified protocol** — Kokoro TTS, Whisper ASR, and Background
Removal workers each used their own ad-hoc message formats. Adding a new
model meant reinventing worker communication from scratch.
2. **Infrastructure existed but was disconnected** —
`GPUResourceCoordinator`, `LoadQueue`, `InferenceWorkerManager`, and
`protocol.ts` were all implemented but had zero consumers. The adapters
duplicated the same lifecycle/timeout/mutex patterns independently.
3. **Performance gaps** — Kokoro only offered fp32 on WebGPU (no fp16),
Whisper warm-up compiled shaders for 187.5s of dummy audio, audio
transfer went through unnecessary WAV blob encode/decode, and
`listVoices` reloaded the model every time.
4. **Silent failures** — Whisper worker's `generate()` had no try-catch;
errors were swallowed and the main thread waited until timeout.
5. **No graceful degradation** — Whisper and Background Removal workers
hardcoded `device: 'webgpu'` with no WASM fallback.
6. **No observability** — Only Kokoro had performance tracing. No
adapter reported status to `useInferenceStatus`. No cache management UI
existed.
7. **Dead code accumulation** — Old `KokoroWorkerManager` (232 lines),
legacy Whisper message types, and scattered duplicate constants.

## Changes

### Phase 0 — Critical Performance & Bugs
- Add `fp16-webgpu` dtype for Kokoro TTS (~2x inference speed on
supported GPUs)
- Fix Whisper warm-up tensor from `[1, 128, 3000]` → `[1, 128, 1]`
(minimal shader compilation)
- Fix Whisper worker silent error bug (add try-catch to `generate()` and
`load()`)

### Phase 1 — Data Transfer & Caching
- Switch Kokoro audio to Float32Array transferable (skip WAV blob encode
in worker, lightweight WAV encode on main thread)
- Cache `listVoices` results (skip redundant model reload when adapter
state is `ready`)
- Normalize progress reporting to 0-100 across all adapters,
differentiate `warmup` phase

### Phase 2 — Protocol Unification & Infrastructure
- Migrate all 3 workers + 3 adapters to unified `protocol.ts` message
types (`load-model`, `run-inference`, `model-ready`, `inference-result`,
`progress`, `error`)
- Wire `GPUResourceCoordinator` into all adapters (VRAM allocation
tracking, LRU ordering, memory pressure events)
- Wire `LoadQueue` into all adapters (priority-based sequential model
loading: TTS=10 > ASR=5 > BG_REMOVAL=1)
- Add `coordinator.ts` global singleton for GPU coordinator + load queue
- Add WebGPU detection + WASM fallback in Whisper and Background Removal
workers

### Phase 3 — Error Recovery & Observability
- Add restart logic with exponential backoff to Whisper adapter
(matching Kokoro's existing pattern)
- Integrate `classifyError()` (OOM / DEVICE_LOST / TIMEOUT
classification) in Whisper adapter
- Extend `defaultPerfTracer` to Whisper `transcribe()` and Background
Removal `processImage()`
- Wire `useInferenceStatus` into all 3 adapters (downloading → ready →
terminated lifecycle)

### Phase 4 — Tests
- Add unit tests for `AsyncMutex` (4 tests), `LoadQueue` (4 tests),
`GPUResourceCoordinator` (7 tests) — all 15 passing

### Phase 5 — Cleanup & Features
- Delete old `KokoroWorkerManager` (232 lines, zero consumers)
- Delete orphaned `libs/workers/types.ts` (old Whisper message types)
- Clean up `workers/kokoro/types.ts` (remove legacy message types, keep
domain types)
- Create centralized `constants.ts` (MODEL_IDS, MODEL_NAMES, TIMEOUTS,
MAX_RESTARTS)
- Remove hardcoded WebGPU check from background-removal devtools pages
(worker auto-detects)
- Add `useModelPreload` composable for generic idle-time preloading
- Add `useInferencePreload` composable that reads provider config and
preloads configured local models
- Wire preloading into both `stage-web` and `stage-tamagotchi` App.vue
(Kokoro TTS preloads 3s after init)
- Add `ModelCacheManager.vue` settings component (cache size display,
per-model status, clear cache)
- Document GPU Device isolation architecture in protocol.ts

## After This PR

- All inference workers speak the same protocol → adding a new model
adapter is straightforward
- GPU memory is tracked across all models with automatic pressure
warnings at 80%/95% of VRAM budget
- Models load sequentially via priority queue → no bandwidth/VRAM
contention
- Workers auto-detect WebGPU and fall back to WASM → works on browsers
without WebGPU
- Kokoro TTS preloads during idle time → "instant" first use for
configured users
- All adapters auto-restart on worker crashes (max 3 attempts,
exponential backoff)
- 15 unit tests cover core infrastructure (mutex, queue, coordinator)
- Zero dead code remains in the inference pipeline

## Test Plan

- [x] `pnpm exec vitest run packages/stage-ui/src/libs/inference/` — 15
tests pass
- [x] `pnpm -F @proj-airi/stage-ui exec tsc --noEmit` — no TypeScript
errors
- [x] `pnpm lint:fix` — no lint errors in changed files
- [ ] Manual: verify Kokoro TTS works with fp16-webgpu on a supported
browser
- [ ] Manual: verify Whisper ASR loads and transcribes correctly
- [ ] Manual: verify Background Removal works in devtools page
- [ ] Manual: verify preloading triggers in console (`[Preload] Loading
kokoro-...`)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-04-13 23:19:27 +08:00
Neko 8991b541a3 chore(tauri-*,crates): now maintaining tauri and rust packages in another repo (#1533) 2026-03-31 23:56:32 +08:00
Neko Ayaka bdd9098e3d Revert "chore(ci): enable ts/no-deprecated eslint rule to warn"
This reverts commit bd0908b8b1.

This requires TypeScript config for eslint, which we don't have it right now.
2026-03-26 19:05:54 +08:00
Neko Ayaka bd0908b8b1 chore(ci): enable ts/no-deprecated eslint rule to warn 2026-03-26 18:15:10 +08:00
Neko Ayakaandtext_blue 0690408ccc chore(eslint): ignore .agents/**
Co-authored-by: text_blue <248586752+aibijiaop-commits@users.noreply.github.com>
2026-03-19 03:25:36 +08:00
Makito c464676714 fix(eslint): skip the symbolic link CLAUDE.md 2026-03-17 02:36:57 +09:00
Neko Ayaka 3605548973 chore: lint & lock 2026-03-06 16:49:31 +08:00
Neko Ayaka d051a07da9 chore(deps): bump dependencies 2026-01-21 05:42:01 +08:00
LemonNeko 61cf0aa88a refactor(stage-pocket): rename stage-capacitor to stage-pocket 2025-12-31 17:38:45 +08:00
LemonNeko 18a7658846 refactor(stage-*): extract shared layouts (#852) 2025-12-30 14:21:39 +08:00
Neko Ayaka a342594b9a chore(deps): migrate for vue macros 2025-12-14 20:58:45 +08:00
Neko Ayaka 7f5234de74 fix(stage-*): redundant template ref & ref for elmenets 2025-12-11 15:39:28 +08:00
Neko Ayaka fafba1cdf8 chore(deps): bump dependencies 2025-12-11 02:22:43 +08:00
藍+85CD ee42ab85b1 chore(eslint): use moeru config (#664) 2025-10-18 19:02:01 +08:00
RainbowBird a67885748d chore: rename 2025-04-27 17:55:18 +08:00
LemonNeko 240129359f fix: tamagotchi path (#27) 2025-02-20 17:37:33 +08:00
Neko Ayaka 3b3a068c6b style: lint 2025-02-10 01:16:41 +07:00
Neko Ayaka 609173cdbe fix(memory-driver-duckdb): map rows, un-exported bundles for CDN uses vector (vss) check 2025-02-10 01:07:00 +07:00
Neko Ayaka a48624ef1e feat: memory driver with @duckdb/duckdb-wasm 2025-02-08 23:12:46 +07:00
Neko Ayaka 7b7fb2dd5c feat(server-sdk): authentication 2025-01-17 01:23:48 +08:00
Neko Ayaka 2030113ffc chore: adjust assets 2024-12-03 15:06:37 +08:00
Neko Ayaka 5b263caf87 chore: init 2024-12-03 13:09:37 +08:00
Neko Ayaka cf1f1fe038 chore: cleanup
Signed-off-by: Neko Ayaka <neko@ayaka.moe>
2024-12-03 13:06:39 +08:00
Anthony Fu ff2c537a76 init: init 2024-12-02 20:49:31 +08:00