Update index.js
Browse files
index.js
CHANGED
@@ -12,6 +12,17 @@ const BASE_MODEL = "Qwen/Qwen2-VL-2B-Instruct";
|
|
12 |
const ONNX_MODEL = "pdufour/Qwen2-VL-2B-Instruct-ONNX-Q4-F16";
|
13 |
const QUANT = "q4f16";
|
14 |
const MAX_SINGLE_CHAT_LENGTH = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
// UI Elements
|
17 |
const exampleButton = document.getElementById('example');
|
@@ -35,17 +46,17 @@ async function initializeSessions() {
|
|
35 |
|
36 |
ortSessionA = await ort.InferenceSession.create(
|
37 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_A_${QUANT}.onnx`),
|
38 |
-
|
39 |
);
|
40 |
|
41 |
ortSessionB = await ort.InferenceSession.create(
|
42 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_B_${QUANT}.onnx`),
|
43 |
-
|
44 |
);
|
45 |
|
46 |
ortSessionC = await ort.InferenceSession.create(
|
47 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_C_${QUANT}.onnx`),
|
48 |
-
|
49 |
);
|
50 |
|
51 |
config = (await getModelJSON(BASE_MODEL, "config.json"));
|
@@ -243,9 +254,7 @@ export async function imageTextToText(
|
|
243 |
|
244 |
ortSessionD = await ort.InferenceSession.create(
|
245 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_D_${QUANT}.onnx`),
|
246 |
-
|
247 |
-
executionProviders: ["webgpu"],
|
248 |
-
}
|
249 |
);
|
250 |
|
251 |
({ hidden_states, position_ids } = await ortSessionD.run({
|
@@ -271,9 +280,7 @@ export async function imageTextToText(
|
|
271 |
if (!ortSessionE) {
|
272 |
ortSessionE = await ort.InferenceSession.create(
|
273 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_E_${QUANT}.onnx`),
|
274 |
-
|
275 |
-
executionProviders: ["webgpu"],
|
276 |
-
},
|
277 |
);
|
278 |
}
|
279 |
|
|
|
12 |
const ONNX_MODEL = "pdufour/Qwen2-VL-2B-Instruct-ONNX-Q4-F16";
|
13 |
const QUANT = "q4f16";
|
14 |
const MAX_SINGLE_CHAT_LENGTH = 10;
|
15 |
+
const DEFAULT_SESSION_OPTIONS = {
|
16 |
+
executionProviders: ["webgpu"],
|
17 |
+
logSeverityLevel: 0,
|
18 |
+
logVerbosityLevel: 1,
|
19 |
+
enableProfiling: true,
|
20 |
+
enableCpuMemArena: true,
|
21 |
+
graphOptimizationLevel: "all",
|
22 |
+
executionMode: "sequential",
|
23 |
+
intraOpNumThreads: 0,
|
24 |
+
interOpNumThreads: 0,
|
25 |
+
}
|
26 |
|
27 |
// UI Elements
|
28 |
const exampleButton = document.getElementById('example');
|
|
|
46 |
|
47 |
ortSessionA = await ort.InferenceSession.create(
|
48 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_A_${QUANT}.onnx`),
|
49 |
+
DEFAULT_SESSION_OPTIONS,
|
50 |
);
|
51 |
|
52 |
ortSessionB = await ort.InferenceSession.create(
|
53 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_B_${QUANT}.onnx`),
|
54 |
+
DEFAULT_SESSION_OPTIONS,
|
55 |
);
|
56 |
|
57 |
ortSessionC = await ort.InferenceSession.create(
|
58 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_C_${QUANT}.onnx`),
|
59 |
+
DEFAULT_SESSION_OPTIONS,
|
60 |
);
|
61 |
|
62 |
config = (await getModelJSON(BASE_MODEL, "config.json"));
|
|
|
254 |
|
255 |
ortSessionD = await ort.InferenceSession.create(
|
256 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_D_${QUANT}.onnx`),
|
257 |
+
DEFAULT_SESSION_OPTIONS,
|
|
|
|
|
258 |
);
|
259 |
|
260 |
({ hidden_states, position_ids } = await ortSessionD.run({
|
|
|
280 |
if (!ortSessionE) {
|
281 |
ortSessionE = await ort.InferenceSession.create(
|
282 |
await getModelFile(ONNX_MODEL, `onnx/QwenVL_E_${QUANT}.onnx`),
|
283 |
+
DEFAULT_SESSION_OPTIONS,
|
|
|
|
|
284 |
);
|
285 |
}
|
286 |
|