gpus
Skill1 starsChanged 9 months agoMITView on GitHub
Detailed reference for GPU acceleration on Modal. Request multiple GPU types in priority order: Modal provides CUDA drivers by default. Many libraries work with just pip: For libraries requiring nvcc or CUDA headers: Access GPU metrics from within your function:
In this repository8 other files it gives its agents.
- code-execSkill
- data-pipelineSkill
- image-genSkill
- imagesSkill
- llm-inferenceSkill
- modalSkill
- sandboxesSkill
- web-endpointsSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 175
Right-size your GPU: Start with smaller GPUs and scale up
- Distinctive: line 176
Use container idle timeout: Keep containers warm for repeated requests
- Very specific: line 177
Batch requests: Use @modal.batched for throughput
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Modal GPU Reference
Detailed reference for GPU acceleration on Modal.
Available GPUs
| GPU | VRAM | Max Count | Best For |
T4 | 16 GB | 8 | Budget inference, light training |
L4 | 24 GB | 8 | Inference |
A10 | 24 GB | 4 | Inference, light training |
A100-40GB | 40 GB | 8 | Training, large model inference |
A100-80GB | 80 GB | 8 | Large models, distributed training |
L40S | 48 GB | 8 | Best cost/performance ratio |
H100 | 80 GB | 8 | High-performance training |
H200 | 141 GB | 8 | Very large models |
B200 | 192 GB | 8 | Largest models, cutting-edge |
GPU Selection
Single GPU
@app.function(gpu="A100")
def train():
import torch
assert torch.cuda.is_available()Multiple GPUs
# 8 H100s for large model training
@app.function(gpu="H100:8")
def train_large_model():
import torch
device_count = torch.cuda.device_count() # 8GPU Fallbacks
Request multiple GPU types in priority order:
@app.function(gpu=["H100", "A100-80GB", "A100-40GB:2"])
def flexible_function():
# Will try H100 first, then A100-80GB, then 2x A100-40GB
...Specific GPU Variants
# Specific A100 variant
@app.function(gpu="A100-40GB")
def smaller_a100():
...
@app.function(gpu="A100-80GB")
def larger_a100():
...
# Prevent H100 → H200 auto-upgrade
@app.function(gpu="H100!")
def strict_h100():
...GPU Selection Guidelines
For Inference
| Model Size | Recommended GPU |
| < 7B params | L4, T4 |
| 7B-13B params | L40S, A100-40GB |
| 13B-70B params | A100-80GB, H100 |
| > 70B params | H100:2+, H200, B200 |
For Training
| Training Type | Recommended GPU |
| Fine-tuning (LoRA) | A100-40GB, L40S |
| Full fine-tuning | A100-80GB, H100 |
| Pre-training | H100:8, H200:8 |
Multi-GPU Training
PyTorch DDP
@app.function(gpu="A100:4")
def train_ddp():
import subprocess
import sys
subprocess.run(
["torchrun", "--nproc_per_node=4", "train.py"],
check=True
)Multi-Node Clusters (Beta)
import modal.experimental
@app.function(gpu="H100:8", timeout=86400)
@modal.experimental.clustered(size=4, rdma=True) # 4 nodes × 8 GPUs = 32 GPUs
def train_distributed():
cluster_info = modal.experimental.get_cluster_info()
from torch.distributed.run import run, parse_args
run(parse_args([
f"--nnodes={4}",
f"--node-rank={cluster_info.rank}",
f"--master-addr={cluster_info.container_ips[0]}",
"--nproc-per-node=8",
"--master-port=1234",
"train.py",
]))CUDA Setup
Using Pre-installed Drivers
Modal provides CUDA drivers by default. Many libraries work with just pip:
image = modal.Image.debian_slim().pip_install("torch")
@app.function(gpu="A100", image=image)
def cuda_function():
import torch
print(torch.cuda.is_available()) # TrueFull CUDA Toolkit
For libraries requiring nvcc or CUDA headers:
image = (
modal.Image.from_registry(
"nvidia/cuda:12.8.1-devel-ubuntu24.04",
add_python="3.12"
)
.entrypoint([])
.pip_install("flash-attn", "triton")
)
@app.function(gpu="H100", image=image)
def advanced_cuda():
...GPU Metrics
Access GPU metrics from within your function:
@app.function(gpu="A100")
def check_gpu():
import subprocess
result = subprocess.run(
["nvidia-smi", "--query-gpu=utilization.gpu,memory.used,memory.total", "--format=csv"],
capture_output=True, text=True
)
print(result.stdout)Cost Optimization
- Right-size your GPU: Start with smaller GPUs and scale up
- Use container idle timeout: Keep containers warm for repeated requests
- Batch requests: Use
@modal.batchedfor throughput - Consider GPU fallbacks: Accept any available GPU type
@app.cls(
gpu="L40S",
container_idle_timeout=300, # Keep warm for 5 min
)
class InferenceService:
@modal.enter()
def load_model(self):
self.model = load_model()
@modal.batched(max_batch_size=32, wait_ms=100)
async def predict(self, inputs: list[str]) -> list[str]:
return self.model.batch_predict(inputs)Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

