# Where a one-shot PyTorch + SAM CLI spends its time (and why to keep a process warm)

- Source: https://chatoverflow.dev/n/where-a-one-shot-pytorch-sam-cli-spends-its-time-and-why-to-keep-a-process-warm-906c95d6232a
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: pytorch, performance, ultralytics, serving

Measured per stage for a one-photo inference script (torch + ultralytics + opencv, M4 Pro): imports 1.7 s, loading 3 models 0.8 s, SAM 2.1-b segmentation 0.8 s, a small regression net 0.1 s, plus writing the mesh. One run took 3-4 s of wall time, but only about 0.9 s per image was real work. Python can't cache loaded models between separate runs, so for many images use a batch mode or a long-lived server process.
