Commit graph

40 commits

Author SHA1 Message Date
NJX
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 Ayaka
2ba82b5ff6
fix(workspace): incorrect font configured 2026-04-03 16:04:32 +08:00
Neko Ayaka
3b76bab2fc
feat(stage-*,workspace): added Nunito for default English font, ChillRoundM for CJK font
Close #1317, #1393
2026-04-02 18:31:53 +08:00
LemonNeko
41405b24de
fix(styles|stage-*): remove font subset property, migrate about content 2026-01-29 17:44:14 +08:00
Neko Ayaka
51b91b8e3d
feat(stage-tamagotchi): improved weather widget 2026-01-07 02:40:45 +08:00
Neko Ayaka
63a12d3b9e
fix(workspace/unocss,stage-tamagotchi): missing comfortaa font, missing import 2025-12-18 15:02:53 +08:00
Neko Ayaka
58530dae23
style: lint 2025-10-31 02:02:41 +08:00
Neko Ayaka
4c26365035
feat(workspace): added drag-region as part of unocss rule 2025-10-07 23:04:34 +08:00
Makito
697d680417
fix(uno): exclude node_modules from scan (#588) 2025-09-14 01:59:00 +09:00
Ilya Bogdanov
5c1eb33ad8
feat: Refactor Font Configuration for Consistency and Correctness (#409)
* feat(unocss): centralize font configuration and fix cyrillic font handling (#389)

This commit refactors the UnoCSS font configuration to establish a single source of truth and resolve issues with Cyrillic character rendering.

- Centralizes all font definitions within the root uno.config.ts.
- Updates the theme.fontFamily to use a correct fallback chain, ensuring "Comfortaa" is used for Cyrillic characters.
- Restricts the "Kiwi Maru" font to Latin and Japanese character subsets to prevent incorrect application.
- Simplifies application-specific uno.config.ts files by removing redundant local font overrides.

* fix(ui): ensure provider models reload reactively (#407)

This commit resolves a persistent reactivity issue where the model list would not update automatically after changing provider credentials. This was a recurring problem reported by users on Discord.

Previously, the model list was only fetched when the consciousness settings page was first mounted. This meant that if a user updated an API key and navigated back, the page would still display the old, stale model list until the application was fully restarted.

The fix introduces two key changes:

1.  A `watch` effect has been added to the `providers.ts` store. It now monitors `providerCredentials` and automatically refetches the model list for a specific provider whenever its credentials change.
2.  The `consciousness.vue` component now uses the `onActivated` lifecycle hook in addition to `onMounted`. This ensures that the model list is refreshed every time the component becomes active, such as when navigating back to it. A `watch` on the `activeProvider` was also added to handle provider switching within the page.

These changes ensure that the model list is always synchronized with the current provider configuration, providing a much smoother and more intuitive user experience.

Closes #407

---------

Co-authored-by: Neko <neko@ayaka.moe>
2025-08-25 11:44:10 +08:00
Neko Ayaka
21b3307e9e
feat(stage-*): new Model Selector to select models for Live2D, VRM, and future MMD
Close #426
Close #414
Close #375
2025-08-24 23:38:32 +08:00
Neko Ayaka
c27d11e907
fix(stage-*): font fallback issue 2025-07-28 11:24:38 +08:00
Neko Ayaka
fff4598c5e
feat(stage-ui): new Combobox component 2025-07-24 03:10:02 +08:00
Neko Ayaka
db99af7a59
feat(stage-web): info action 2025-07-22 03:37:17 +08:00
Neko
77832da756
debug(workspace): unocss fonts split shared testing (#282) 2025-07-21 14:36:06 +08:00
Neko
5e8b2b8412
feat(docs): migrate to vitepress with @unovue/reka-ui's theme (#224) 2025-07-15 10:25:44 +08:00
Neko
7e0035c7ac
fix(workspace): missing fonts (#269) 2025-07-14 21:53:56 +08:00
Neko
aca3c589f6
fix(ci): ETIMEDOUT for ipv4 & ENETUNREACH for ipv6 when fetching fonts from @unocss/preset-web-fonts (#268)
Co-authored-by: XYenon <20698483+xyenon@users.noreply.github.com>
2025-07-14 20:38:44 +08:00
Neko Ayaka
c283d19b7f
fix(workspace): update UnoCSS config to load fonts from fontsource
Co-authored-by: Menci <11341955+Menci@users.noreply.github.com>
2025-07-14 01:40:24 +08:00
Neko Ayaka
c52eb447e9
feat(workspace): serve fonts fron local for all apps 2025-07-12 14:06:10 +08:00
Neko Ayaka
34b547047f
chore(deps): bump dependencies 2025-07-06 19:06:59 +08:00
Neko
bd497051fe
refactor(ui,stage-ui,stage-app,stage-tamagotchi): migrate to use @proj-airi/unocss-preset-chromatic (#219) 2025-06-19 17:16:00 +08:00
Neko Ayaka
4fda484704
fix(playground-prompt-engineering): build 2025-06-16 02:12:21 +08:00
Menci
32f50c6def
fix(unocss): add %alpha placeholder for complex color expressions (#198) 2025-06-08 13:19:39 +08:00
Neko Ayaka
a99ba7f50a
style(stage-ui): new font
Co-authored-by: Rynco Maekawa <10259119+lynzrand@users.noreply.github.com>
2025-05-30 13:32:19 +08:00
Neko Ayaka
e819834e42
fix(stage-ui|workspace): lobe-icons not resolved, metadata not accessed correctly 2025-05-01 00:05:14 +08:00
Neko Ayaka
1eb62e912f
feat(font-xiaolai|font-cjfonts-allseto): new package, fixed story not visible on mobile devices 2025-04-30 22:44:42 +08:00
Makito
d3cdeca126
refactor: share unocss config across multiple packages (#143)
Co-authored-by: Neko Ayaka <neko@ayaka.moe>
Co-authored-by: Makito <5277268+sumimakito@users.noreply.github.com>
2025-04-27 10:46:34 +08:00
LemonNeko
97d829df7a
fix: pnpm filter on windows (#26) 2025-02-20 16:16:47 +08:00
Neko Ayaka
40a1dd4970
style: refactoring ui 2025-02-16 20:10:01 +08:00
Neko Ayaka
8492d660c7
fix: font 2024-12-20 15:00:24 +08:00
Neko Ayaka
31534814d5
chore: new UI 2024-12-20 01:29:13 +08:00
Neko Ayaka
b7f218bdcb
chore: new UI 2024-12-16 19:27:37 +08:00
Neko Ayaka
e2f1f7bd37
chore: improved UI 2024-12-07 02:42:07 +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
Neko Ayaka
be4cbce93e
chore: migrate with new structure 2024-12-02 20:49:31 +08:00
Anthony Fu
ff2c537a76
init: init 2024-12-02 20:49:31 +08:00
Neko Ayaka
a282115d78
chore: configure rules for static assets 2024-12-02 20:49:24 +08:00
Neko Ayaka
d9ae0aae38
init: init
Signed-off-by: Neko Ayaka <neko@ayaka.moe>
2024-12-02 00:31:36 +08:00