概要
SemIfは、ブラウザで試せるデモがあるが、GPUを扱えるPCでなければ動かない。
今回は、GPUなしでも動くように、デモのPGを一部修正して、動作を確かめる。
webgpu-demo
ブラウザのデモは以下のフォルダに入っている。
SemIf-OpenJev\webgpu-demo
worker.js
モデルのロード設定の修正が必要。
n_gpu_layers を0にしてCPUを指定する。
await engine.loadModelFromUrl(modelUrl, {
n_ctx: 2048,
n_batch: 512,
// 変更
// n_gpu_layers: 999,
n_gpu_layers: 0,
cache_prompt: false,
progressCallback: ({ loaded, total }) => send("progress", { event: {
status: "progress", file: modelUrl, loaded, total,
text: total ? `${(loaded / total * 100).toFixed(0)}% of model downloaded or read from cache` : "loading model",
} }),
});
app.js
GPUが使えなければダウンロードボタンが有効にならないので修正が必要
checkWebGPU を以下のようにする。
async function checkWebGPU() {
if (!navigator.gpu) {
// 変更
// setSupport("WebGPU is unavailable. Use a current WebGPU-capable browser over HTTPS or localhost.", "error");
// loadButton.disabled = true;
setSupport("WebGPU is unavailable. CPU/WASM mode will be used.", "OK");
return;
}
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
// 変更
// setSupport("WebGPU exists, but no GPU adapter is available in this browser.", "error");
// loadButton.disabled = true;
setSupport("WebGPU is unavailable. CPU/WASM mode will be used.", "OK");
return;
}
setSupport("WebGPU is ready. The model does not download until you click load.", "ok");
}
起動
SemIf-OpenJev\webgpu-demoでもコマンドプロンプトを開いて以下を実行。
py -m http.server 8080
動作
準備
推論
Give it real choice で文章を好きに変更してみてRUN BOTH METHODS をクリック。(今回、文章は初期のまま)




