| name | benchmark |
| description | Profile YOLO model inference speed, FPS, and size across image sizes and export formats. |
Benchmark
Profile a YOLO model's inference performance across image sizes and devices.
Inputs
Model Path
- If the user provides a model path, use it directly.
- If not provided, look for the current best model:
- Check
experiments/summary.md for the latest best model path
- Search
experiments/*/weights/best.pt for the most recent
- Fall back to asking the user
Image Sizes
Default: [320, 640, 1280]. The user can override this list.
Device
Detect available devices. Run on GPU (0) if available, CPU (cpu) always. If both exist, benchmark both and compare.
Procedure
-
Read training-plan.md — check the "Deployment target" and "Secondary Goals" sections for latency/size constraints.
-
Locate the model using the lookup order above. Confirm the path exists before proceeding.
-
Run benchmarks — for each image size and each available device, run:
from ultralytics import YOLO
import torch
model = YOLO(path)
gpu_available = torch.cuda.is_available()
devices = ["cpu"]
if gpu_available:
devices.insert(0, 0)
for device in devices:
for imgsz in image_sizes:
results = model.benchmark(imgsz=imgsz, half=False, device=device)
model.benchmark() handles warm-up internally. Do not add manual warm-up runs.
-
Collect results — from each benchmark call, extract:
- Inference time (ms)
- FPS (frames per second)
- Model size (MB)
- Format tested
-
Report — print a summary table:
## Benchmark Results: <model_name>
### GPU (NVIDIA <name>) / CPU
| Format | imgsz | Inference (ms) | FPS | Size (MB) |
|----------|-------|----------------|--------|-----------|
| PyTorch | 320 | ... | ... | ... |
| PyTorch | 640 | ... | ... | ... |
| PyTorch | 1280 | ... | ... | ... |
-
Analyze against deployment constraints — if training-plan.md specifies:
- A latency target (e.g., "< 10ms"): flag any configuration that exceeds it
- A model size limit: flag if the model exceeds it
- A target device: highlight the relevant device results
-
Recommend optimal imgsz — based on the results:
- Identify the largest imgsz that meets latency requirements
- If no latency requirement is specified, note the speed/accuracy tradeoff (larger imgsz = better accuracy, slower inference)
- If all sizes exceed the constraint, say so and suggest smaller model variants (n < s < m)
Output Format
Print results directly to the conversation. Do not write to a file unless the user asks.
Structure:
- Model info (path, parameter count, variant)
- Results table(s) — one per device
- Deployment check — pass/fail against
training-plan.md constraints
- Recommendation — optimal imgsz and format for the stated deployment target
Important
- Do not export the model to other formats unless the user asks.
model.benchmark() tests the PyTorch format by default.
- If
training-plan.md has no deployment constraints, skip the constraint check and just report the numbers.
- Keep output factual. Report what the numbers show, suggest next steps if relevant.
- If the model file does not exist, stop and tell the user. Do not train a model.