Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A torch model in a page that cannot import torch

The paper’s headline capability, live: a notebook trains a PyTorch model, exports it to ONNX, and slices a prediction sweep into numpy arrays. marimo export html-wasm --execute runs the notebook once at export time and bundles the cache into the static artifact. In your browser — where import torch is impossible — the arrays restore through the .npy codec, the ONNX bytes rebind to onnxruntime-web through a custom stub, and the slider drives live in-browser inference against the restored session.

The torch-typed values restore as named tripwire stubs: never read, they cost nothing; dereferenced, they raise with the variable’s name and original error instead of corrupting downstream state.

The frame embeds the static export from demo/dist in this paper’s artifact, deployed alongside the book at demo/. If it is empty on a local build, serve the export separately (cd demo && uv run serve.py 8642 and browse there) or rebuild it with ./build_e2e.sh. The demo notebook is demo/cache_demo.py; everything it needs ships in its PEP 723 header.