0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SemIf(旧称 OpenJev)のWEBGPUデモをCPUで動くようにする

0
Posted at

概要

image.png

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

動作

準備

使用するモデルを選択してLOAD XXXで読み込む。
image.png

完了するとかかった時間などが表示される。
image.png

推論

Give it real choice で文章を好きに変更してみてRUN BOTH METHODS をクリック。(今回、文章は初期のまま)
image.png

推論結果が表示される
CPUなので80sや160sなどかなり時間がかかるが、動作する
image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?