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.

Interact with a native torch session, restored in the browser

We train a 1D-MNIST torch classifier, export it to ONNX, and cache the result. The cache lets an expensive notebook run in the browser, where PyTorch has no emscripten target. The training cell wraps a moutils.onnx.OnnxRuntime in mo.persistent_cache, and moutils’ cache stub serializes that runtime as its ONNX bytes. On this page it is a cache hit, so torch, pymde, and mnist1d never import, yet runtime restores as a working session.

Lasso a region of the PyMDE embedding. Then step through the selected samples. Each sample runs through the restored runtime via onnxruntime-web in the browser. The confusion matrix summarizes the model’s predictions for the region.

The frame embeds a static marimo export html-wasm --execute build. The notebook is embeds/onnx_mnist1d.py, and the export bundles moutils as a wheel.