← All articles

Infrastructure · June 29, 2026 · 4 min read

Spot vs on-demand GPUs: saving money safely

Learn how to leverage Spot GPUs without risking data loss by implementing aggressive checkpointing, stateless architecture, and automated job orchestration.

Training modern machine learning models or running large-scale inference is an exercise in resource management. For most ML engineers, the primary constraint isn't just algorithmic—it's the cloud bill. When looking at GPU availability, you generally face two options: On-Demand instances, which offer guaranteed availability at a premium, and Spot instances, which offer deep discounts in exchange for the risk of being reclaimed by the provider.

The price difference is often staggering, with Spot instances sometimes costing 60-80% less than their On-Demand counterparts. However, saving money "safely" requires a shift in how you architect your workflows. Here is how to navigate the trade-off.

Understanding the "Spot Risk"

The fundamental challenge with Spot GPUs is volatility. If a higher-paying user requests On-Demand resources and the capacity is full, your Spot job will be pre-empted (terminated) with very little notice—usually between 30 seconds and two minutes.

To save money safely, you must assume your hardware will disappear at any moment. If your training script isn't prepared for this, you don't just lose time; you lose the literal dollars spent on the compute hours leading up to the crash.

Strategy 1: The Checkpoint Pattern

The most critical step in utilizing Spot GPUs is aggressive checkpointing. In a standard training loop, you might save your model weights at the end of every epoch. On Spot instances, you should save based on time intervals or smaller step counts.

Most modern frameworks like PyTorch Lightning or Hugging Face transformers have built-in support for resuming from a directory. Your code should always check for an existing checkpoint before starting.

import os
import torch
from podstack import Client

# Initialize Podstack client if using managed storage
client = Client(api_key=os.getenv("PODSTACK_API_KEY"))

def train():
    model = MyModel()
    optimizer = torch.optim.Adam(model.parameters())
    checkpoint_path = "/persistent/storage/checkpoint.pt"

    # The Safety Net: Always check for previous state
    if os.path.exists(checkpoint_path):
        print("Resuming from checkpoint...")
        checkpoint = torch.load(checkpoint_path)
        model.load_state_dict(checkpoint['model_state_dict'])
        optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
        start_epoch = checkpoint['epoch']
    else:
        start_epoch = 0

    for epoch in range(start_epoch, total_epochs):
        # ... training logic ...
        
        # Save frequently to minimize loss during pre-emption
        torch.save({
            'epoch': epoch,
            'model_state_dict': model.state_dict(),
            'optimizer_state_dict': optimizer.state_dict(),
        }, checkpoint_path)
        
        # Sync to persistent cloud volume
        client.volumes.sync("/persistent/storage")

Strategy 2: Stateless Inference via Serverless

If you are running inference rather than training, you shouldn't be using long-running persistent instances at all. Serverless GPU functions are the ultimate evolution of the Spot vs. On-Demand debate.

By wrapping your inference code in a function that triggers on-demand and scales to zero, you effectively get the pricing benefits of Spot with the reliability of On-Demand. Since inference is typically stateless, if a request fails due to a node being reclaimed, the load balancer simply retries the request on a different node.

Strategy 3: Job Orchestration

Instead of manually spinning up an instance, SSHing in, and running a script, use a Job orchestrator. A dedicated Job runner knows how to handle pre-emption signals. When a Spot instance is reclaimed, a smart orchestrator will automatically re-queue your job and wait for the next available slot, picking up exactly where your last checkpoint left off.

Practical Tips for Spot Stability

  1. Decouple Storage and Compute: Never store your data or model weights on the local disk of a Spot instance. Always use attached network volumes or object storage. When the instance dies, your local disk dies with it.
  2. Monitor via the API: Use automated tools to check the status of your workloads. If a job stays in "Pending" for too long because Spot capacity is low, you might need to temporarily switch that specific high-priority job to On-Demand.
  3. Dockerize Everything: To make your jobs truly "disposable" and portable across Spot nodes, ensure your environment is fully encapsulated in a Docker container. This eliminates "it worked on the last machine" syndrome.

Saving Safely with Podstack

Podstack is designed to take the manual labor out of this decision. We provide a developer-first interface where you can choose between guaranteed On-Demand performance or cost-optimized Job execution.

Using the Podstack API, you can deploy your GPU functions or training jobs without worrying about the underlying hardware lifecycle. Because we bill per second, you never pay for "downtime" or the minutes it takes to spin a machine down after a crash.

To launch a persistent training job that can handle the Spot lifecycle, you can simply point the API to your script:

Podstack does not ship a command-line interface. Use the console, the Python package `podstack-sdk`, or the API at https://podstack.ai/api/v1 with a `ps_live_` key.

By combining persistent volumes with our per-second billing, you can aggressively use Spot-tier pricing for 90% of your development cycle, switching to On-Demand only when hitting critical production deadlines. This hybrid approach ensures your budget goes toward training better models, not just keeping the lights on in a data center.

Try it on Podstack

Per-second GPUs and pay-per-token models. Add $5, get $10 on your first top-up.

Start building