Skip to main content
This example demonstrates deploying a multi-GPU video generation model using Dedicated Containers. You’ll build a Sprocket worker that uses torchrun for distributed inference across multiple GPUs and deploy it to Together’s managed infrastructure.

What you’ll learn

  • Deploying multi-GPU models with Sprocket and Jig
  • Using use_torchrun=True for distributed inference
  • Automatic file upload with FileOutput
  • Submitting jobs via the Queue API and polling for results

Prerequisites

  • Together API key: Get one from together.ai
  • Dedicated Containers access: Contact [email protected] to enable for your organization
  • Docker: For building container images. Install Docker
  • Together CLI: Install with pip install "together[cli]" --upgrade or uv tool install "together[cli]"
Set your API key:
Install Together library:

Overview

This example deploys a Wan 2.1 text-to-video model as a Dedicated Container with multi-GPU support. The Sprocket worker handles distributed inference across 2 GPUs, and Together manages provisioning, autoscaling, and observability. Output specs:
  • Resolution: 480×832
  • Frames: 81 (5.4 seconds at 15fps)
  • Format: MP4
Why multi-GPU?
  • Video generation requires significant VRAM for temporal attention
  • Context parallelism splits the sequence dimension across GPUs
  • 2x H100 allows comfortable generation without memory pressure

How It Works

  1. Build – Jig builds a Docker image from your pyproject.toml configuration
  2. Push – The image is pushed to Together’s private container registry
  3. Deploy – Together provisions 2x H100 GPUs and starts your container
  4. Torchrun – Sprocket’s use_torchrun=True launches child processes (one per GPU)
  5. Queue – Jobs are submitted to the managed queue, broadcast to all GPU ranks, and processed in parallel

Project Structure

Implementation

Sprocket Worker Code

Configuration

Key Concepts

How use_torchrun=True Works

When you call sprocket.run(..., use_torchrun=True), Sprocket handles multi-GPU orchestration automatically. Flow:
  1. Parent process receives a job from Together’s queue
  2. Job payload is broadcast to all child processes via Unix socket
  3. Each rank executes setup() once at startup, then predict() for each job
  4. Ranks synchronize via NCCL during forward pass
  5. Only rank 0 saves output and returns result
  6. Parent uploads FileOutput and reports job completion

Distributed Process Initialization

Each worker process must initialize its distributed context before loading the model:
When use_torchrun=True is passed to sprocket.run(), Sprocket launches torchrun internally, which sets RANK, LOCAL_RANK, WORLD_SIZE, and other environment variables.

Rank 0 Output Pattern

In distributed inference, only rank 0 should handle I/O and return results:
Why this pattern?
  • Avoids duplicate file writes
  • Reduces memory on non-rank-0 GPUs (tensor output vs PIL)
  • Sprocket collects output from rank 0 only

Automatic File Upload with FileOutput

Wrapping a path in FileOutput triggers automatic upload:
What happens:
  1. Sprocket detects the FileOutput in the response
  2. Uploads the file to Together’s storage
  3. Replaces FileOutput with the access URL in the final response
The client receives (when polling job status):

Multi-GPU Configuration

For multi-GPU deployments, configure gpu_count in your deployment settings and pass use_torchrun=True to sprocket.run():
Sprocket handles launching torchrun internally — you don’t need to include it in your cmd. It coordinates the parent process and GPU workers automatically.

Deployment

Deploy

Check Deployment Status

Wait until the deployment shows running and replicas are ready before submitting jobs.

Submit Jobs

Jobs are submitted to the managed queue and processed asynchronously. Video generation typically takes 30-75 seconds depending on settings.

Input Parameters

Output

When the job completes, the status response contains:
  • url: URL to the generated MP4 video file (480×832, 81 frames, 15fps). Authenticated with your API key.

Scaling to More GPUs

To scale for higher throughput, increase max_replicas to add more workers:
To scale to zero when idle, specify min_replicas = 0 (saves costs but adds cold start latency).

Cleanup

When you’re done, delete the deployment:

Next Steps