Spaces:
Running
Running
Upload index.js with huggingface_hub
Browse files
index.js
CHANGED
|
@@ -55,7 +55,20 @@ class Chatbot {
|
|
| 55 |
}
|
| 56 |
|
| 57 |
async checkWebGPUSupport() {
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
this.deviceToggle.disabled = true;
|
| 60 |
this.deviceLabel.textContent = 'CPU (GPU not available)';
|
| 61 |
}
|
|
@@ -77,10 +90,10 @@ class Chatbot {
|
|
| 77 |
try {
|
| 78 |
this.initLoader.style.display = 'flex';
|
| 79 |
|
| 80 |
-
const options = {
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
}
|
| 84 |
|
| 85 |
this.generator = await pipeline(
|
| 86 |
"text-generation",
|
|
@@ -140,7 +153,7 @@ class Chatbot {
|
|
| 140 |
|
| 141 |
// Generate response
|
| 142 |
const output = await this.generator(this.messages, {
|
| 143 |
-
max_new_tokens:
|
| 144 |
do_sample: false,
|
| 145 |
streamer: streamer,
|
| 146 |
});
|
|
|
|
| 55 |
}
|
| 56 |
|
| 57 |
async checkWebGPUSupport() {
|
| 58 |
+
try {
|
| 59 |
+
if (!navigator.gpu) {
|
| 60 |
+
this.deviceToggle.disabled = true;
|
| 61 |
+
this.deviceLabel.textContent = 'CPU (GPU not available)';
|
| 62 |
+
return;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
const adapter = await navigator.gpu.requestAdapter();
|
| 66 |
+
if (!adapter) {
|
| 67 |
+
this.deviceToggle.disabled = true;
|
| 68 |
+
this.deviceLabel.textContent = 'CPU (GPU not available)';
|
| 69 |
+
}
|
| 70 |
+
} catch (error) {
|
| 71 |
+
console.error('WebGPU check failed:', error);
|
| 72 |
this.deviceToggle.disabled = true;
|
| 73 |
this.deviceLabel.textContent = 'CPU (GPU not available)';
|
| 74 |
}
|
|
|
|
| 90 |
try {
|
| 91 |
this.initLoader.style.display = 'flex';
|
| 92 |
|
| 93 |
+
const options = {
|
| 94 |
+
dtype: this.useWebGPU ? "q4" : "fp32",
|
| 95 |
+
device: this.useWebGPU ? 'webgpu' : 'wasm'
|
| 96 |
+
};
|
| 97 |
|
| 98 |
this.generator = await pipeline(
|
| 99 |
"text-generation",
|
|
|
|
| 153 |
|
| 154 |
// Generate response
|
| 155 |
const output = await this.generator(this.messages, {
|
| 156 |
+
max_new_tokens: 256,
|
| 157 |
do_sample: false,
|
| 158 |
streamer: streamer,
|
| 159 |
});
|