akhaliq HF Staff commited on
Commit
a93e553
·
verified ·
1 Parent(s): 17dc262

Upload index.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. index.js +19 -6
index.js CHANGED
@@ -55,7 +55,20 @@ class Chatbot {
55
  }
56
 
57
  async checkWebGPUSupport() {
58
- if (!navigator.gpu) {
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = { dtype: "fp32" };
81
- if (this.useWebGPU && navigator.gpu) {
82
- options.device = 'webgpu';
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: 8192,
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
  });