Skip to main content
torch.jstorch.jstorch.js
Getting StartedPlaygroundContact
Login
torch.jstorch.jstorch.js
Documentation
IntroductionType SafetyTensor IndexingEinsumEinopsAutogradTraining a ModelProfiling & MemoryPyTorch MigrationBest PracticesRuntimesPerformance
IntroductionQuickstartClient APIWorker APIFile I/OBackends
torch.js· 2026
LegalTerms of UsePrivacy Policy
  1. docs
  2. Spark
  3. File I/O

File I/O

Spark provides a unified filesystem API for moving data between your local browser, the cloud storage at torchjs.org, and your background workers.

Diagram of data moving between Cloud, IndexedDB, and Worker memory

Remote Storage (torchjs.org)

Load model weights and datasets directly from the community hub.

spark.load()

Loads a file as an ArrayBuffer. Works with .pt, .safetensors, and raw binary data.

const weights = await spark.load('username/model/checkpoint.pt');
model.load_state_dict(torch.load(weights));

spark.save()

Saves local data to your account on torchjs.org.

const buffer = torch.save(model.state_dict());
await spark.save('my-user/my-model/latest.pt', buffer);

Datasets

The spark.dataset() method is optimized for loading large training sets with a torch.json manifest.

const mnist = await spark.dataset('torchjs/mnist');
// Access images and labels via mnist.train and mnist.test

Local Storage (IndexedDB)

For persistent storage that doesn't require an internet connection, use the Local family of methods.

MethodStorage Target
saveLocal(key, data)Browser IndexedDB
loadLocal(key)Browser IndexedDB
clearLocal()Wipe all local torch data

Next Steps

  • Projects - Learn about the project structure and manifest files.
  • Workflows - Full examples of end-to-end training and deployment.
Previous
Worker API
Next
buildFileUrl