Skip to main content
torch.js has not been released yet.
torch.js logotorch.js logotorch.js
PlaygroundContact
Login
Documentation
IntroductionType SafetyTensor ExpressionsTensor IndexingEinsumEinopsAutogradTraining a ModelProfiling & MemoryPyTorch MigrationBest PracticesRuntimesPerformancePyTorch CompatibilityBenchmarksDType Coverage
torch.js· 2026
LegalTerms of UsePrivacy Policy
/
/
  1. docs
  2. Spark
  3. spark
  4. saveLocal

spark.saveLocal

function saveLocal(key: string, data: ArrayBuffer): Promise<void>

Save data to local browser storage (IndexedDB) for offline access.

Stores data in the browser's IndexedDB, which provides:

  • Persistent offline storage
  • Large capacity (typically 50MB+ per origin)
  • Fast access without network
  • Automatic cleanup on browser clear data

Use this for:

  • Caching trained model checkpoints
  • Storing intermediate training states
  • Offline-first application data
  • Temporary computation results
Data is stored with a timestamp and can be retrieved later. Keys are unique per origin (domain).

Parameters

keystring
Unique identifier for this data (any string)
dataArrayBuffer
Data to store as ArrayBuffer (e.g., serialized model weights)

Returns

Promise<void>– Promise that resolves when data is stored

Examples

// Save model checkpoint locally
const weights = torch.serialize(model.state_dict());
await spark.saveLocal('model-v1-best', weights);

// Save multiple checkpoints
await spark.saveLocal(`checkpoint-epoch-${epoch}`, stateBuffer);

See Also

  • loadLocal - Load from local storage
  • saveLocal - Save to server
Previous
saveJSON
Next
setBaseUrl