borch

Learn · 6

Saving and loading

Checkpoints are safetensors, not pickle. The Python borch, numpy and the Hugging Face tools all read the same bytes — a format only we could read would throw away half the point.

Save and load

save takes whatever you hand it — a state dict, or a whole nested object with the model, the optimizer and an epoch number in it — and returns bytes; load gives that structure back. Nothing touches the filesystem — in a browser there isn't one, so what you get is an ArrayBuffer you can download, put in IndexedDB, or hand straight back to load.

Saving from Python

The same checkpoint, written from the other surface. Note what did not change: torch.save(sd, path) takes a path here, the way the textbook writes it, because Pyodide gives Python a virtual filesystem inside the tab. Nothing touches your disk, and the code does not have to know that.

Everything else about that surface — how it forwards names, what it costs to load, and where it stops — is on the Python page. Lessons 1, 2 and 4 carry both languages in one block, so you can switch and compare there.

Where to go next. The playground gives you the same runtime with a bigger editor, a loss curve and the GPU counters. The API reference lists every exported name with the torch name it answers to. What is not here — CUDA, pretrained weights, mixed precision, distributed training — is listed on the home page, and the list is deliberately long.