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. SparkController

spark.SparkController

export interface SparkController {
  /**
   * Current execution status.
   *
   * @readonly
   */
  readonly status: SparkStatus;

  /**
   * Pause execution at the next checkpoint.
   *
   * The worker will pause when `checkpoint()` is next called,
   * and remain paused until `resume()` is called.
   */
  pause(): void;

  /**
   * Resume paused execution.
   *
   * If not paused, this is a no-op.
   */
  resume(): void;

  /**
   * Stop execution.
   *
   * The next `checkpoint()` will throw `SparkStopError`.
   * The worker will terminate after the error is thrown.
   */
  stop(): void;

  /**
   * Cooperative yield point for pause/resume/stop and hot reload.
   *
   * Call this at regular intervals in your training loop.
   * It will:
   * - Throw `SparkStopError` if stopped
   * - Throw `SparkReloadError` if hot reload is pending
   * - Block until resumed if paused
   * - Yield control to allow UI updates
   *
   * @throws {SparkStopError} If execution was stopped
   * @throws {SparkReloadError} If hot reload is pending
   */
  checkpoint(): Promise<void>;
}
readonlystatus(SparkStatus)
– Current execution status.
pause(() => void)
– Pause execution at the next checkpoint. The worker will pause when checkpoint() is next called, and remain paused until resume() is called.
resume(() => void)
– Resume paused execution. If not paused, this is a no-op.
stop(() => void)
– Stop execution. The next checkpoint() will throw SparkStopError. The worker will terminate after the error is thrown.
checkpoint(() => Promise<void>)
– Cooperative yield point for pause/resume/stop and hot reload. Call this at regular intervals in your training loop. It will: - Throw SparkStopError if stopped - Throw SparkReloadError if hot reload is pending - Block until resumed if paused - Yield control to allow UI updates

Controller for managing execution in the worker.

Provides cooperative pause/resume/stop and checkpoints for hot reload. Call checkpoint() at regular intervals in your training loop.

Examples

const ctrl = spark.controller();

async function train() {
  for (const batch of data) {
    await ctrl.checkpoint();  // Allow pause/stop/reload here
    // ... training step
  }
}
Previous
SparkClientApi
Next
SparkControlMessage