RecapAnon commited on
Commit
de2014a
·
1 Parent(s): bbe5776

Switch to webgpu and add device checks.

Browse files
Files changed (1) hide show
  1. index.js +15 -2
index.js CHANGED
@@ -104,6 +104,19 @@ async function initializeVectorDB() {
104
  }
105
 
106
  async function initializeModel() {
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  try {
108
  updateStatus('loading', 'Loading Qwen3 model... This may take a minute on first load.');
109
 
@@ -112,7 +125,7 @@ async function initializeModel() {
112
  "onnx-community/Qwen3-0.6B-ONNX",
113
  {
114
  dtype: "q4f16",
115
- device: "wasm",
116
  progress_callback: (progress) => {
117
  if (progress.status === 'progress') {
118
  const percent = Math.round((progress.loaded / progress.total) * 100);
@@ -133,7 +146,7 @@ async function initializeModel() {
133
  } catch (error) {
134
  console.error('Error initializing model:', error);
135
  updateStatus('error', 'Failed to load model. Please refresh the page.');
136
- addMessage('assistant', `Error: ${error.message}. Please refresh the page to try again.`);
137
  }
138
  }
139
 
 
104
  }
105
 
106
  async function initializeModel() {
107
+ if (!navigator.gpu) {
108
+ updateStatus('error', 'WebGPU not supported.');
109
+ addMessage('assistant', `oh no`);
110
+ return;
111
+ }
112
+
113
+ const adapter = await navigator.gpu.requestAdapter();
114
+ if (!adapter) {
115
+ updateStatus('error', 'WebGPU device not found.');
116
+ addMessage('assistant', `oh no`);
117
+ return;
118
+ }
119
+
120
  try {
121
  updateStatus('loading', 'Loading Qwen3 model... This may take a minute on first load.');
122
 
 
125
  "onnx-community/Qwen3-0.6B-ONNX",
126
  {
127
  dtype: "q4f16",
128
+ device: "webgpu",
129
  progress_callback: (progress) => {
130
  if (progress.status === 'progress') {
131
  const percent = Math.round((progress.loaded / progress.total) * 100);
 
146
  } catch (error) {
147
  console.error('Error initializing model:', error);
148
  updateStatus('error', 'Failed to load model. Please refresh the page.');
149
+ // addMessage('assistant', `Error: ${error.message}. Please refresh the page to try again.`);
150
  }
151
  }
152