Developer Tools

PyTorch slashes Docker build times with shared registry cache

No more full rebuilds — Docker CI layers reused via ECR cache

Deep Dive

PyTorch's CI has long relied on `docker-builds` running on a remote BuildKit fleet (OSDC). Each build previously passed `--no-cache`, forcing a complete rebuild of every Docker layer — a slow and resource-heavy process. The ephemeral pods also couldn't share their private caches, compounding the inefficiency. Now, a new pull request (#186297) replaces that approach with a registry-based caching system. For remote builds, the CI now uses `--cache-from` and `--cache-to` with `type=registry`, writing cache layers to a per-image tag (e.g., `<image>-buildcache`) in the same ECR repository. The cache is configured with `mode=max` (stores all layers) and `image-manifest=true,oci-mediatypes=true` to ensure compatibility.

This change means unchanged stages are reused across CI runs, dramatically cutting build times and reducing the load on the shared BuildKit fleet. A companion PR sets up a lifecycle rule to delete these cache tags after 7 days to prevent storage bloat. Developers testing in CI will see faster iterations, and the PyTorch maintainers benefit from reduced infrastructure costs. This is a behind-the-scenes optimization that makes PyTorch's development pipeline more efficient.

Key Points
  • Previously used `--no-cache`, rebuilding all Docker layers every run; now uses registry cache with `--cache-from/--cache-to type=registry`
  • Cache stored in same ECR repo per image with `-buildcache` tag, `mode=max`, OCI media types
  • Accompanied by a 7-day lifecycle policy to auto-delete old cache tags, managed via PR #1198

Why It Matters

Faster CI builds mean quicker iteration for PyTorch developers and reduced cloud compute costs.

📬 Get the top 10 AI stories daily