Skip to content

Releases

0.16.0

Choose a tag to compare

@decitre decitre released this 30 Nov 00:41

The demos and the apps now run on an iPad, the camera app is about three times faster on a phone, and pipeline() takes an image_size for image tasks.

New

  • pipeline(..., image_size=480) resizes the shorter side of an image to that many pixels before inference, instead of the model's own size. DETR's is 800, so a 640 x 480 camera photo was scaled up to about 1067 x 800 first. On WASM, with the same objects found: 5.6 s to 2.1 s on the two-cats photo, and 5.3 s to 1.2 s on smaller photos; 320 took about a tenth of the time with slightly lower scores. Only models whose image processor resizes by the shorter side take it (DETR does; ViT, with a fixed height and width, raises an error naming image_size). It must be a positive integer. It reaches into Transformers.js's processor object, checked against 4.3.2 only. See #126 and #131.

Fixed

  • onnxruntime-web could not start on an iPad. It asks for a shared WebAssembly memory with a 4 GB maximum. On an iPad (A16, Safari) 1 GB was accepted and 2 GB refused, so every model failed with RangeError: Out of memory, whatever its size and whichever backend. The site builds (the demo and the apps) now patch the runtime to try 4, 2, 1 GB and 512 MB, and stop if onnxruntime-web changes the line. A package install that loads onnxruntime-web from jsDelivr is not patched. See #45 and #127.
  • A model that needs more than 1 GB to create its session failed with std::bad_alloc in that heap. DistilGPT-2 q8 (85 MB) needs more than 1 GB of heap with weight packing on and about 0.8 to 1 GB with it off, at the same speed. When the browser refuses a 2 GB shared memory, pipelines, Embedder, Classifier and OnnxModel now load with weight packing off. This applies to the jsDelivr copy too. A memory error no longer moves on to the next, larger dtype, which hid the first error. See #128.
  • Changed runtime files could be served from the browser cache for a long time. A browser kept the old onnxruntime-web for about an hour after a fix. The site build writes a hash of the vendored files, and lmlite.js puts it in every file's URL (?rev=...), with one small revalidating request per page load. It covers the files a site serves itself, not the jsDelivr copy. See #130.

Changed (the camera app, on the site, not in the package)

  • camera-objects loads DETR with image_size=480. On a Galaxy S20 FE on WASM, one photo took about 25.7 s at the default and 8.9 s in Chrome (9.4 s in Firefox) with it, on different scenes, one photo each, so that ratio is approximate. See #133.

What fits on an iPad

DistilGPT-2 on an iPad (A16, Safari): q8 on WASM, and fp16 and q4f16 (165 MB each) on WebGPU, load and generate; q4 (329 MB, as large as fp32) and fp32 (330 MB) fail with std::bad_alloc. A model file of about 300 MB does not fit in a 1 GB heap on either backend, so pass a dtype chosen by file size. This is one device and one Safari version, and the limit is reported to vary between devices, versions and reloads. Details in docs/MODELS.md.

Build and docs

  • A Hugging Face Static Space for the camera app (pilot, #86). VOICI_APPS=camera-objects builds the apps site with only the listed apps, and scripts/make-space.sh writes a Space folder with the COOP and COEP headers, which Hugging Face sends. On the live Space, in headless Chromium on a 12-core Mac, the camera app was cross-origin isolated and took 0.6 s per photo against about 1.9 s without the headers. The speech app is left out: its voice is non-commercial. The gain on a phone is not measured. See docs/DEVELOPMENT.md.
  • docs/RUNTIME.md has a section of what was seen on real devices and browsers (an iPad, a Galaxy S20 FE in Chrome and in Firefox, a Galaxy Tab S10 Lite, a Mac with Firefox, Chrome and Safari), from one owner's hand runs and mostly single runs. The swap to WASM when WebGPU fails to run was confirmed on Firefox 161 for macOS.

Notes

  • Not measured: other models and other iPads, fp16 and q4f16 on WASM, whether more memory raises the iPad's limit, image_size on a phone beyond the one photo above, and threaded WASM on a phone.
  • Still true: in Chrome on the S20 FE the first photo of each page load also tries WebGPU, which returns nothing, before falling back to WASM (about 28 s earlier). A run-time fallback in the library, and WebGPU as the default, are #114.
  • A phone is slow on WASM for large inputs: about 9 s per photo for DETR at 480.

0.15.1

Choose a tag to compare

@decitre decitre released this 29 Nov 13:01

A fix for 0.15.0: a WASM load after a failed WebGPU run works again, and CameraCapture can switch between the cameras of a device. The two Voici apps were broken on some devices by their move to WebGPU in 0.15.0; they are fixed on the site.

Fixed

  • A failed WebGPU run no longer breaks a WASM load that comes after it. After a WebGPU run failed (for example Firefox 161 on macOS, where a shader does not compile for Metal), onnxruntime-web was left in a state where a session created afterwards, even a WASM one and even for another model, failed with the same error. After a WebGPU error in a task pipeline, the next load now imports a fresh copy of Transformers.js, whose onnxruntime-web starts clean. See #117 and #122.
    • This isolates the state only when onnxruntime-web is inside the Transformers.js file, as in the bundle a site serves itself (the lmLite apps). From jsDelivr it stays shared.
    • It covers task pipelines, not generation or OnnxModel.
    • It was tested with a simulated failure (a createComputePipeline that throws) in Pyodide and xeus-python; the real Firefox/Metal failure could not be run.
    • backend_fallback still covers only a load that fails. A run that fails, or that returns nothing, is not retried by the library: the apps do it themselves (below). A run-time fallback in the library is in #114.

New

  • CameraCapture.switch() and the device trait. switch() goes round the cameras the browser lists, one per call, opening each by its id; device names the camera in use (for example camera2 0, facing back). On a phone the list has every lens of the front and the rear camera, so it can take several calls to return to the first. A device with one camera says so in the widget and keeps it. Not meant while a request() is waiting.

Changed (the Voici apps, on the site, not in the package)

  • camera-objects and speak-french use WebGPU and swap to WASM when it fails. If a model that loaded on WebGPU fails to run, or returns nothing (no detection candidate at all, an empty transcript or translation), the app retries once on WASM and stays on WASM, and says so. The camera app showed this on a Galaxy S20 FE (Chrome, Adreno 6xx), where WebGPU returned nothing without an error. See #117, #121 and #124.
  • The apps show the backend and the inference time: (wasm after webgpu failed, 25.6 s) for the camera, and a line per model for the translator. A Debug checkbox adds the browser, the WebGPU adapter and limits, the fallback reason, the strongest scores and the photo size (camera), the heard text and the recording size (translator), and the camera in use. The camera app has a Switch camera button.

Docs

  • An ONNX Runtime badge in the README (#119), and switch() in the apps guide.

Notes

  • Slow on a phone. On a Galaxy S20 FE the camera app takes about 25 s per photo on WASM, and the first photo of a page load also pays the failed WebGPU attempt. See #126.
  • WebGPU output that is plausible but wrong is not caught. The apps check only for no output.
  • Not run: real Firefox with WebGPU (the failure was simulated), and the apps on any phone other than the Galaxy S20 FE.
  • Making WebGPU the default backend: #114. Making the apps installable and cached on a phone: #125.

0.15.0

Choose a tag to compare

@decitre decitre released this 27 Nov 09:13

Tool calling, a camera and microphone that Python can ask for, and a WebGPU that falls back to WASM instead of failing. The embedding and classification options of LLM that 0.14.0 deprecated are removed.

Upgrading

  • LLM no longer embeds or classifies. LLM.create(embedding_model=...) and LLM.create(classification_model=...) now raise a TypeError, and llm.embed(), llm.classify() and llm.similarity_search() are gone. Use Embedder.create(model) and Classifier.create(model); the 0.14.0 release notes show the one-for-one replacement. A model that was loaded together with a generator is now a second object with its own dispose().
  • Notebooks are renumbered again, to go from language models to pipelines to low-level material. Old notebook URLs (?path=ch17_streaming.ipynb and the others) no longer exist. The new order is: 01 to 05 unchanged; 06 tool calling, 07 streaming, 08 token probabilities; 09 embeddings, 10 classification, 11 orchestration; 12 tasks, 13 vision, 14 image outputs, 15 camera, 16 speech, 17 microphone; 18 tokenizers, 19 ONNX models, 20 text to image, 21 WebGPU; ch99 is unchanged.

New

  • WebGPU falls back to WASM. With backend="webgpu", a browser with no WebGPU adapter, or a failure that is specific to WebGPU (a lost device, a shader or buffer limit, an operator or float16 the adapter lacks), now loads the model on WASM once and says why. llm.backend (and Embedder, Classifier, Pipeline, OnnxModel) report the backend that ran, and backend_fallback_reason says why it changed. Out-of-memory and fetch errors are not retried, since WASM would hit them too. Pass backend_fallback=False to fail instead. The default backend is still "wasm". Failures are recognised by their wording, so a runtime message outside the pattern is raised, not retried; software adapters are not detected. See #111 and "WebGPU fallback" in the parameters reference.
  • ToolRunner: validated tool calling (ToolRunner, Tool, AgentResult, model_tool). A model replies with a JSON tool call or an answer; the tool name and arguments are checked against the registered tools and their schemas before anything runs, so an unknown tool or invalid arguments never execute. The refusal goes back to the model and uses a step. The loop stops on an answer, the step limit, a timeout or a cancel, and AgentResult.steps records every reply and its outcome. After a tool has run, a reply with no JSON object in it is the answer. See #77.
  • A tool-calling notebook, ch06_tool-calling. It runs Qwen2.5-0.5B-Instruct (q4, about 790 MB) through ToolRunner on WebGPU when the browser has a hardware adapter, on WASM otherwise, and shows with a scripted model what happens to an unknown tool, invalid arguments, non-JSON and the step limit. The model is small: in the measurements behind the notebook it chose the right tool for 5 of 8 questions, so treat that run as a demonstration.
  • CameraCapture.request() and AudioRecorder.request() show a prompt in the widget and wait for the user to tap before capturing, so Python can ask for a photo or a recording. A request resolves only with media captured for it, and raises CaptureCancelled on Cancel, TimeoutError on a timeout, and the browser's error when the camera or microphone is refused. Every ending releases the device. See #78.

Changed

  • A failed fetch is reported as a fetch. A load error of Load failed (Safari), Failed to fetch (Chrome) or NetworkError (Firefox) used to get the advice that the model may not be supported by the backend. It now says a file could not be fetched and how to find which one, and suggests the other backend only after a WebGPU failure. See #109.
  • ch20 (text to image) and ch21 (WebGPU) pass backend_fallback=False, so they cannot run on WASM without saying so.
  • The two Voici apps (camera-objects, speak-french) ask for backend="webgpu" instead of "wasm", and run on WASM where WebGPU is missing or fails to load. Only the fallback path was run, in headless Chromium without a GPU (voici-smoke); they were not run on a real GPU or a phone.

Fixed

  • A tool call that was cut off or malformed ended a ToolRunner run. After a tool ran, a reply that json.loads rejected, such as a call cut off at the token limit or with a trailing comma, became the final answer. A reply is now prose only when it has no opening brace; anything that looks like JSON but does not parse goes back to the model. See #108.

Docs

  • Running a static embedding model (POTION) with OnnxModel and tokenizer() is documented in the ONNX guide (#94).

Notes

  • Only the WebGPU fallback in the no-adapter case was run in a real browser (headless Chromium, backend-fallback-smoke), plus ch21 on an Apple GPU. A WebGPU failure after a successful adapter check is covered by tests with mocks, not a real browser.
  • ch20 and ch06 were not re-run in a browser with these changes.
  • Real Safari is still untested.
  • Making WebGPU the default backend is tracked in #114.

0.14.2

Choose a tag to compare

@decitre decitre released this 25 Nov 06:09

A fix for 0.14.0 and 0.14.1.

Fixed

  • The native onnxruntime backend works outside a browser again. In 0.14.0 and 0.14.1, creating any session in plain Python (for example Embedder.create(model, backend="native")) failed with "No Python-to-JavaScript bridge found". See #90.

0.14.1

Choose a tag to compare

@decitre decitre released this 25 Nov 05:40

Backwards-compatible additions to the camera and microphone widgets, two Voici apps, and fuller documentation.

Added

  • Two Voici apps, built into their own site: object detection with the camera (take a shot, see the objects, retry), and English speech to French speech (record, translate, hear it). See https://decitre.github.io/lmlite/guides/apps.html.
  • CameraCapture options for apps with their own buttons: controls, autostart, show_photo; the running trait; the start(), take() and stop() methods.
  • AudioRecorder options for the same: controls and the active trait; the record() and stop() methods.
  • A quiet option on LLM.create(), Embedder.create(), Classifier.create() and pipeline(): no progress bar and no loading messages.
  • An API reference generated from the docstrings (https://decitre.github.io/lmlite/reference/api.html), a credits page, an AGENTS.md for contributors and coding agents, and an llms.txt index of the docs.

Fixed

  • The camera widget keeps the camera on when the browser refuses to start the preview (Brave on Android did after the permission prompt): tap the picture to start it.

Changed

  • Fuller docstrings for the whole public API: arguments, return values, errors and examples. They show in help() and in editors.
  • A shorter README, with a chat-with-memory example, a picture generated with SD-Turbo, and four highlighted notebooks.
  • The unsupported-task error of pipeline() points to LLM, Embedder and Classifier for text generation, embeddings and classification.
  • The error of a closed Tokenizer says to load it again with tokenizer().

0.14.0

Choose a tag to compare

@decitre decitre released this 24 Nov 14:23

lmLite is now described as browser machine learning from Python, and the API follows: the LLM class is for large language models only, pipeline() is a top-level function, and embeddings and classification have their own classes. Old code keeps working in this release and warns.

Upgrading

  • LLM.create(embedding_model=...), LLM.create(classification_model=...), llm.embed(), llm.classify() and llm.similarity_search() still work and raise a DeprecationWarning. They will be removed in 0.15. Use Embedder.create(model) and Classifier.create(model) instead:

    from lmlite import Classifier, Embedder, LLM
    
    llm = await LLM.create(generator_model="distilgpt2")
    embedder = await Embedder.create("all-MiniLM-L6-v2", backend="wasm", dtype="q8")  # was embedding_model, embedding_backend, embedding_dtype
    vector = await embedder.embed("Hello")
    results = await embedder.similarity_search("a query", docs, k=2)
    classifier = await Classifier.create("distilbert-base-uncased-finetuned-sst-2-english")
    labels = await classifier.classify("I love it", top_k=2)

    A model that was loaded together with a generator is now a second object with its own dispose().

  • Notebooks are renumbered. Old notebook URLs (?path=ch08b_vision.ipynb and the others) no longer exist. The pipeline notebooks are chapters 8 to 15 (tasks, vision, image outputs, camera, speech, microphone, ONNX models, text to image) and orchestration, streaming, token probabilities, tokenizers and WebGPU are 16 to 20. Chapters 1 to 7 and ch99 keep their numbers.

  • from lmlite.llm import Pipeline (or Speech, Tokenizer, ModelInfo, clear_cache, ...) no longer works. llm.py is split into modules; import from the package: from lmlite import Pipeline. Everything public is still exported from lmlite.

  • The JavaScript runtime file is lmlite.js (it was llm.js), with BrowserRuntime and createRuntime. globalThis.lmLite still has BrowserLLM and createLLM as aliases.

New

  • Top-level functions: pipeline, tokenizer, model_info, model_task and hosted_base, for what is not about language models. LLM.pipeline(...) and the other class methods call them and keep working.
  • audio-classification task (pipeline("audio-classification", model=...)), with the same audio inputs as speech recognition, top_k and map(). Tested with onnx-community/Musical-Instrument-Classification-ONNX (nine instruments; MIT). The model is weak: on four short test clips it got three right, with best scores of 0.26 to 0.33, so show the top three. The microphone notebook has a section that names the instrument you play.
  • CameraCapture widget (pip install 'lmlite[camera]'): take a photo with the camera of a laptop, tablet or phone and pass the JPEG to any image pipeline. A new notebook, ch11_camera, detects objects in the photo. Tested with fake cameras in Chromium and Firefox, not on a real phone or tablet.

Docs

  • The README and the docs now say what lmLite is: browser machine learning from Python, with the pipeline API as a primary API. They no longer claim there is no native inference fallback: the lmlite[native] backend runs Embedder, Classifier, greedy generation, OnnxModel and the tokenizer outside a browser.
  • The documentation is published at https://decitre.github.io/lmlite/ and linked from PyPI, together with the issue tracker, the releases page and the demo.
  • The coverage badges in the README are labelled python and javascript.

Notes

  • Embedder and the other new objects are separate JavaScript runtimes: the demo and the retrieval notebook now create two objects instead of one. I did not measure whether that costs anything.
  • Real Safari is still untested.

0.13.1

Choose a tag to compare

@decitre decitre released this 23 Nov 20:09

A patch release: clearer load errors, and the documentation reorganised and published.

Changed

  • Load failures say what failed (#46). When a generator or task model fails to load, the error keeps the runtime's own message and now names the stage (load, or warm up for the one-token test after a generator loads), the backend, the dtypes tried and the Transformers.js and onnxruntime-web versions. An out-of-memory error (for example RangeError: Out of memory on WASM) gets memory advice instead of "this model may not be supported". Embedding and classification models keep their shorter messages. This does not fix the iPad report in #45; it makes that failure readable.

Documentation

  • The usage guide is split by what the reader needs (#32): guides, a reference and an explanation. docs/USAGE.md stays as a pointer to the new pages.
  • The docs are built with Sphinx, MyST and Furo and published at https://decitre.github.io/lmlite/, next to the xeus-python and Pyodide demos (#58). The build treats warnings as errors, so a broken link or anchor fails CI.
  • New: a section on choosing between xeus-python and Pyodide (#49), with a recommendation (xeus-python by default). Kernel start-up time, site size and kernel memory were not measured.

Notes

  • No API changes. The only code change is the error text in llm.js.
  • Real Safari is still untested.

0.13.0

Choose a tag to compare

@decitre decitre released this 22 Nov 19:54

The first release with image, speech and bare-ONNX support, plus a fix for loading from sites that serve a 503 for the optional model manifest.

New

  • Image tasks in LLM.pipeline(): image inputs (bytes, URL, file path, NumPy array, PIL image) for vision tasks, and pipelines that return images (background removal, depth estimation, image segmentation, image to image) as PNG bytes or, with as_array=True, NumPy arrays (#23, #42).
  • Text to speech: LLM.pipeline("text-to-speech") returns a Speech object with samples, sampling_rate, duration and to_wav(), and shows an audio player in a notebook. Tested with Xenova/mms-tts-eng (CC-BY-NC-4.0, non-commercial use only) (#34, #44).
  • OnnxModel: run a single .onnx file with NumPy in and NumPy out, with caching, hosted models, a sha256 check and float16 support. OnnxModel.map() adds progress, error handling and cancel (#28, #30, #47).
  • Pipeline.map(): batched calls with progress (#31).
  • Microphone widget: an anywidget recorder for notebooks, with a message that names the system input level when a recording is silent (#35, #38, #43). Install with the new audio extra.
  • Extras: images (NumPy, Pillow 10.1 or later) and audio (anywidget).
  • Text to image: a recipe notebook (SD-Turbo on WebGPU, with prompt widgets) and the decision to keep it out of the pipeline tasks, with measurements in docs/MODELS.md (#48). SD-Turbo is under a non-commercial research licence, so do not bundle it into a published site.

Fixed

  • A load no longer fails when the site's optional hosted-model manifest returns a 503: the request is retried, then the model loads from the Hub (#51). A 404 still means "no manifest".
  • xeus-python: the bridge imports pyjs, not pjs, and raises when there is no bridge (#22).
  • The segmentation example returned wrong masks with the quantized model; it now uses fp32 and the tests check the pixels (#50).

Notes

  • lmlite loads in xeus-python on WebAssembly and WebGPU, and the notebooks run in the real JupyterLab UI in Chromium and Firefox (#50). Real Safari is not tested.
  • The JupyterLite sites are built with jl-forge 0.8 (#41). If you self-host, rebuild with scripts/lite-build.sh.
  • macOS: the pixi environments need macOS 14 or later on arm64 (#27).

0.12.1

Choose a tag to compare

@decitre decitre released this 07 Nov 14:37

No library code changes since 0.12.0. The hosted JupyterLite sites now run a newer xeus-python kernel, which works on cross-origin isolated pages.

xeus-python sites can now be served cross-origin isolated

The 0.11.1 and 0.12.0 docs said not to serve the xeus-python site with COOP/COEP headers, because its kernel failed to start (jupyterlite/xeus#378). The sites are now built with jl-forge 0.6.0, whose xeus-python environment comes from the emscripten-forge 4x channel and includes the upstream fix (pyjs 4.1.0):

before now
xeus 5.2.8 6.0.6
xeus-python 0.17.8 0.19.0
pyjs 3.2.0 4.1.0
emscripten 3.1.73 4.0.9

On the xeus site, isolation now gives the same speedup as on the Pyodide site: all-MiniLM-L6-v2 fp16 on a long input goes from about 137 ms to 50 ms (2.5 to 2.8×) in Chromium, Firefox and WebKit. As on the Pyodide site, WebKit ignores credentialless and needs require-corp to be isolated. Measurements are in docs/NATIVE.md, "Browser latency".

  • Action: if you self-host a xeus-python site behind COOP/COEP headers, rebuild it with scripts/lite-build.sh (or jl-forge 0.6.0 or later). Sites built with an older xeus-python environment still crash when isolated.
  • GitHub Pages: the hosted demo sites cannot set response headers, so they still run single-threaded.
  • Not yet tested: the isolated xeus site in Safari itself (only Playwright's WebKit).

Development

  • scripts/lite-build.sh pins jl-forge~=0.6.0. Its first build solves a new xeus environment, because the cache key includes the channel.
  • tests/browser/test_tokenizer_xeus.py uses the emscripten-forge 4x channel, so it tests the kernel the sites ship.

v0.12.0

Choose a tag to compare

@decitre decitre released this 04 Nov 22:29

Breaking: lmlite-models fails on models without ONNX weights

lmlite-models used to exit 0 and list a model in manifest.json even when none of its .onnx files were copied. The browser then loaded that model from the site only, its weights returned 404, and LLM.create failed at run time. Now, in both --format files and --format zip, a model with no ONNX weights stops the build with exit code 2:

lmlite-models: error: no ONNX weights under models/org/m; found: config.json; skipped symlinks: onnx/model_quantized.onnx
  • Symlinks: a symlink to a file inside the same model directory is now copied as a regular file. Any other symlink is skipped and named on stderr. Before, every symlink was skipped without a word.
  • Hugging Face cache trees: snapshots/<rev>/... links point into blobs/, outside the model directory, so they are skipped. Copy the tree with its links resolved before building, for example cp -rL ~/.cache/huggingface/hub/models--org--m/snapshots/<rev> models/org/m.
  • Action: if a build that used to pass now fails, look at the found: and skipped symlinks: lists to see which weight is missing. Folders with only a config or tokenizer can no longer be hosted.