-
Notifications
You must be signed in to change notification settings - Fork 137
fix: WebGPU CPU fallback, Gemma 3 1B registry, HTML mobile dedup (#97 #165 #170) #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,22 @@ import { ModelConfig } from '../config/models/types'; | |
| import { TTSEngine, SAMPLE_RATE as TTS_SAMPLE_RATE } from './tts-engine'; | ||
| import { AutoProcessor, MultiModalityCausalLM } from '../libs/transformers/transformers'; | ||
|
|
||
| /** | ||
| * Detect whether a usable WebGPU adapter is available. | ||
| * Falls back to CPU (ONNX WASM backend) when WebGPU is absent or fails. | ||
| */ | ||
| async function detectBestDevice(): Promise<'webgpu' | 'cpu'> { | ||
| if (typeof navigator === 'undefined' || !('gpu' in navigator)) return 'cpu'; | ||
| try { | ||
| const adapter = await ( | ||
| navigator as unknown as { gpu: { requestAdapter(): Promise<unknown> } } | ||
| ).gpu.requestAdapter(); | ||
| return adapter ? 'webgpu' : 'cpu'; | ||
| } catch { | ||
| return 'cpu'; | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| export class TransformersEngineWrapper { | ||
| private transformersPipeline: | ||
| | TextGenerationPipeline | ||
|
|
@@ -48,7 +64,15 @@ export class TransformersEngineWrapper { | |
|
|
||
| this.modelType = modelConfig.modelType; | ||
|
|
||
| options.device = 'webgpu'; | ||
| // Detect the best available compute device; fall back to CPU/WASM when | ||
| // WebGPU is unavailable (e.g. Firefox, older Chromium, Node.js). | ||
| // Callers may still override by passing `options.device` explicitly. | ||
| if (!options.device) { | ||
| options.device = await detectBestDevice(); | ||
| if (options.device === 'cpu') { | ||
| console.info('[Transformers] WebGPU unavailable — falling back to CPU/WASM inference'); | ||
| } | ||
| } | ||
|
Comment on lines
+70
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify default call sites that hard-code WebGPU and bypass auto-fallback.
rg -n -C3 "textToSpeech\(" src/core/llm/index.ts
rg -n -C3 "device:\s*'webgpu'" src/core/llm/index.ts src/engines/transformer-engine-wrapper.ts
rg -n -C3 "if \(!options\.device\)" src/engines/transformer-engine-wrapper.tsRepository: sauravpanda/BrowserAI Length of output: 1139 Remove hardcoded At Line 68 of Suggested fix- await this.engine.loadModel(MODEL_CONFIG['kokoro-tts'], {
- quantized: true,
- device: 'webgpu',
- ...options,
- });
+ await this.engine.loadModel(MODEL_CONFIG['kokoro-tts'], {
+ quantized: true,
+ ...options,
+ });🤖 Prompt for AI Agents |
||
|
|
||
| // Configure pipeline options with proper worker settings | ||
| const pipelineOptions = { | ||
|
|
@@ -67,7 +91,6 @@ export class TransformersEngineWrapper { | |
|
|
||
| // Initialize image processor for multimodal models | ||
| if (modelConfig.modelType === 'multimodal') { | ||
| options.device = 'webgpu'; | ||
| // console.log('Loading multimodal model...'); | ||
| this.imageProcessor = await AutoProcessor.from_pretrained(modelConfig.repo, pipelineOptions); | ||
| // console.log('Image processor loaded'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not prune
show/visibleresponsive classes as duplicates.Line [67] removes elements matching
show/visibleresponsive classes (e.g.,show-on-tablet,visible-desktop). That can delete the only intended content variant and cause downstream content loss.Proposed fix
Also applies to: 67-90
🤖 Prompt for AI Agents