Skip to content

perf(serverless): skip torch fitness checks unless loaded - #632

Open
deanq wants to merge 1 commit into
mainfrom
deanq/sls-815-gate-torch-checks
Open

deanq wants to merge 1 commit into
mainfrom
deanq/sls-815-gate-torch-checks

Conversation

@deanq

@deanq deanq commented Oct 19, 2026

Copy link
Copy Markdown
Member

Summary

The worker-start _cuda_init_check and _benchmark_check imported torch themselves. On a cold worker that import is ~1.5s, about 90% of the check, and it ran before the first job-take. That happens even for handlers that never use torch, or that import it lazily inside the handler function (every Flash handler does, because Flash ships only the function body).

  • Both checks now use torch or CuPy only if the handler already imported it (sys.modules); they never import either
  • With neither loaded, both checks skip before calling nvidia-smi. The gpu_test binary, which runs at import time, still verifies device init (cudaSetDevice) and allocation (cudaMalloc) on every GPU
  • With torch or CuPy loaded, behavior is unchanged

Why gate instead of drop: for handlers that import torch at module level, the check reuses the loaded framework at almost no cost and still catches torch-level problems (missing kernels for the GPU arch, cuBLAS failures). Dropping only _cuda_init_check would not help, because _benchmark_check would then pay the same torch import.

Impact

Breakdown on a real RTX 4090 serverless worker, torch 2.9.1+cu128:

Step Time
import torch 1550 ms (1352 / 1397 ms in a fresh process)
CUDA context creation ~150 ms
zeros(1024) on device 12 ms
gpu_test binary 293 / 343 ms

Worker-start fitness pass on the same worker type, Flash handler:

Time
2.0.0rc1 1339 / 2147 ms (_cuda_init_check 1211 / 2021 ms)
This branch 31 ms

For a handler that uses torch, the import moves to its first job (1591 ms measured); for one that doesn't, it is gone. Either way the worker starts taking jobs 1.3-2.1s sooner.

Test plan

  • New: CUDA init check skips without importing torch/CuPy or calling nvidia-smi when the handler loaded neither (fails on main)
  • New: GPU benchmark skips the same way (fails on main)
  • New: CuPy benchmark still runs when only CuPy is loaded
  • Existing torch/CuPy success and failure tests unchanged and passing
  • make quality-check: 1482 passed, 91.70% coverage
  • Real GPU worker with this branch bundled: worker-start fitness pass 31 ms, both torch checks logged as skipped

Linear: SLS-815

The worker-start CUDA init and GPU benchmark checks imported torch
themselves. On a cold worker that import is ~1.5s, about 90% of the
check, and it ran before the first job-take even for handlers that
never use torch or import it lazily (every Flash handler).

- Use torch or CuPy only if the handler already imported it
  (sys.modules); never import either from the check
- Skip both checks before calling nvidia-smi when neither is loaded;
  the gpu_test binary still verifies device init and allocation
- Unchanged behavior when torch or CuPy is loaded

Real GPU worker (RTX 4090, Flash handler): worker-start fitness pass
went from 1339/2147ms to 31ms.

Linear: SLS-815

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃煝 Approval recommended

The focused changes match the intended startup optimization, include regression coverage, and have no identified blocking issues.

No open issues 馃帀

What changed in this PR

Reduces worker startup latency by running framework-based GPU fitness checks only when PyTorch or CuPy is already loaded.

Changes:

  • Skips CUDA initialization and benchmark checks before GPU detection when neither framework is loaded.
  • Adds regression tests for skip behavior and the loaded-CuPy benchmark path.
File Description
tests/鈥媡est_serverless/鈥媡est_modules/鈥媡est_fitness/鈥媡est_system_checks.py Tests import-free skipping and CuPy benchmark execution.
runpod/鈥媉health/鈥媠ystem.py Gates GPU checks on loaded frameworks and documents the behavior.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants