Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Modal 7 min read Deep dive mediumAdept

Host overhead is killing your inference efficiency

GPU idle time while the CPU prepares work (host overhead) shows up as low GPU kernel utilization and directly multiplies inference cost; 50% overhead means GPU spend is 2x what it could be. Gaps in CUDA streams visible in PyTorch Profiler or Nsight Systems traces reveal it. Fixes include avoiding synchronous CPU-GPU transfers by constructing tensors where they are needed (e.g. decode-time position embeddings, unit-size KV page lengths), fusing kernels with the Torch compiler (cutting ~20 launches to 3, saving ~30µs and 20% mean latency), and using CUDA Graphs to amortize remaining launch costs, as SGLang and vLLM already do.

Related posts

  • Profiling in PyTorch (Part 1): A Beginner's Guide to torch.profiler

    Hugging Face mediumAdept

    torch.profiler produces two artifacts: a statistical table showing where time goes and a Chrome/Perfetto trace showing when CPU and GPU events happen. A small 64x64 bf16 matmul+add is overhead-bound, with GPU time under 1% of CPU time, while 4096x4096 matrices shift the work to compute-bound GEMM kernels. The trace walkthrough explains a cold-start dead window of about 228 µs before aten::matmul dispatch, a CPU-GPU lane offset, gaps caused by profiler Activity Buffer Requests, and the dispatch chain from Python down to CUDA kernels. The practical advice is to warm up, use profiler schedules, and read Self versus total times carefully before turning to torch.compile.

  • Profiling TorchNeuron (Part 1): System-level profiling on AWS Trainium.

    Hugging Face mediumAdept

    A beginner-friendly walkthrough of system-level profiling for PyTorch on AWS Trainium using TorchNeuron. It covers configuring torch.profiler with NeuronConfig and NeuronProfiler, reading the key_averages() table, and tracing a single operation through framework, runtime and hardware lanes in Neuron Explorer. Three RMSNorm implementations are profiled. Naive eager ops take 2,355 µs of device time across 6 dispatches. torch.rms_norm lowers to one fused kernel at 403 µs, and torch.compile discovers the same fusion at 376 µs, roughly one-sixth of the naive cost because gaps between dispatches and intermediate tensors are eliminated.

  • 'I paid for the whole GPU, I am going to use the whole GPU': A high-level guide to GPU utilization

    Modal mediumAdept

    "GPU utilization" refers to three distinct metrics at different layers of the stack: GPU Allocation Utilization (fraction of paid GPU-seconds running application code), GPU Kernel Utilization (fraction of time actually running CUDA kernels, as reported by nvidia-smi), and Model FLOP/s Utilization (achieved FLOP/s vs. theoretical arithmetic bandwidth). Allocation utilization is limited by procurement terms and spin-up latency. Most organizations stay below 70% even at peak, while fast serverless allocation can exceed 90%. Kernel utilization suffers from non-GPU work and host overhead, which CUDA Graphs, batching and profiling traces help address. MFU is further limited by communication deadlocks, memory bandwidth and low arithmetic intensity in inference, and kernel quality, so batching and well-tuned libraries like cuBLAS and vLLM matter.

  • Boosting multimodal inference performance by >10% with a single Python dictionary

    Modal hardMaster

    SGLang's single-threaded scheduler was wasting host time on multimodal workloads by calling torch.UntypedStorage._new_shared_cuda for every tensor received over CUDA IPC, repeatedly reopening the same few memory-pool handles. Profiling with py-spy flamegraphs traced the overhead through process_input_requests and hash_feature to PyTorch's wrapper bookkeeping. A lock-on-write Python dict caching one storage per pool handle removed the hotspot. On Qwen2.5-VL-3B on an H100 it raised throughput 16%, cut mean TTFT 13% and TPOT 17%, and also improved tail latencies. Decode got faster too because any delay in the single scheduler thread stalls batch dispatch, and the change ships in SGLang v0.5.10 behind SGLANG_USE_IPC_POOL_HANDLE_CACHE=1.

  • How we achieved truly serverless GPUs

    Modal mediumAdept

    Modal cuts GPU inference replica cold starts from roughly 2,000 seconds to about 50 seconds, a 40x speedup, by attacking each stage of spin-up. A solver-managed buffer of idle, health-checked GPUs, allocated with Google's GLOP linear program, takes instance provisioning out of the hot path. ImageFS, a libfuse filesystem, serves container images lazily from a tiered content-addressed cache, and CPU and CUDA checkpoint/restore skip host- and device-side initialization. The motivation is GPU Allocation Utilization: spiky inference demand leaves fixed allocations at 10-20% use, and fast autoscaling raises utilization and quality of service together.

The quest for software engineering knowledge.

Look:
Layout: