Skip to content

Add weightlift — in-browser ML model load progress library - #55

Merged
wassgha merged 11 commits into
mainfrom
cursor/weightlift-package-d4b2
Aug 1, 2026
Merged

Add weightlift — in-browser ML model load progress library#55
wassgha merged 11 commits into
mainfrom
cursor/weightlift-package-d4b2

Conversation

@wassgha

@wassgha wassgha commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Wires Rescript to published weightlift@^0.2.1 with a registry-first API and optional Transformers.js load plumbing.

Rescript

import { transformersModel, fallbackDevicePolicy } from "weightlift/transformers";

const asrModels = new ModelManager({
  models: {
    [id]: transformersModel({
      pipeline,
      task: "automatic-speech-recognition",
      modelId: id,
      dtype,
      cacheKey: env.cacheKey ?? "transformers-cache",
      onDevice: (d) => { asrDevice = d; },
    }),
  },
});

await asrModels.load(MODELS[choice].id);
// WebGPU loss → fallbackDevicePolicy.preferWasm(); asrModels.unloadAll();

No per-app device policy setup — transformersModel uses shared fallbackDevicePolicy by default. UI status strings stay local in the worker. No monorepo / workspaces.

Open in Web Open in Cursor 

cursoragent and others added 11 commits July 31, 2026 09:57
Extract the multi-file download progress aggregation used by the Whisper
worker into a publishable zero-dep TypeScript package (weightlift) with
Transformers.js / WebLLM adapters, a worker postMessage bridge, and a
thin React useSyncExternalStore hook. Wire the transcription worker to
consume it and cover the core with unit tests.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
Reshape the package around define/load/get/unload with cache-aware
messaging, per-model progress, dispose, and preload — progress aggregation
stays as the engine underneath. Add useModel/useModelManager React hooks
and wire Rescript's ASR singleton through ModelManager.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
UI copy and Transformers.js/WebLLM adapters are implementer concerns —
keep ModelManager focused on lifecycle, bytes, and fromCache. Map
progress callbacks at the call site; works the same for Whisper, CLIP,
SigLIP, or any other T.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
packages/weightlift is now self-contained (own gitignore, lockfile, CI,
npmignore) so it can be copied into its own repo and published. Drop npm
workspaces / local build glue from Rescript and consume weightlift@^0.1.0
as a normal dependency.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
Point the lockfile at the registry package and drop the local
packages/weightlift copy now that it lives in its own repo.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
A lost GPU device invalidates every WebGPU session, so unload all
cached ASR models (equivalent to asrPromises.clear()), not only the
current choice.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
Switch the transcription worker to weightlift's registry-first API
(seed ModelManager with all Whisper sizes, then load(id)). Depends on
weightlift@^0.2.0.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
Drop the local transformers.js progress/cache helpers from the worker
in favor of the optional weightlift/transformers entry.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
Register ASR models with weightlift/transformers helpers that own
device pick, progress, cache checks, and WebGPU→WASM retry.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
Drop per-worker device policy construction; preferWasm goes through
the shared fallbackDevicePolicy export.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
Resolve the lockfile against the registry now that the registry-first
API and transformersModel helpers are published.

Co-authored-by: Wassim Gharbi <wassgha@gmail.com>
@wassgha
wassgha marked this pull request as ready for review August 1, 2026 03:01
@wassgha
wassgha merged commit b175c82 into main Aug 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants