Skip to content

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

Modal 7 min read Case study hardMaster

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

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.

Related posts

  • Host overhead is killing your inference efficiency

    Modal mediumAdept

    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.

  • Boost your throughput with dynamic batching

    Modal mediumAdept

    Modal added a `@modal.batched()` decorator that groups incoming requests into batches flushed when either `max_batch_size` is reached or `wait_ms` elapses, avoiding the unbounded waits of fixed-size batching. Batching helps GPU inference because model weights (over 6 GB for Whisper large v3) must be moved from memory to compute units per pass, and inference is usually memory-bandwidth bound. On an A10G, batching Whisper with a max batch size of 64 raised throughput from about 1.2 to 3.3 requests per second per container, cutting inference cost by roughly 65%. The function only needs to accept and return lists.

  • Run FLUX.1-dev three times faster

    Modal mediumAdept

    FLUX.1-dev image generation on Modal drops from ~6.75s to under three seconds per 1024x1024 image. About 1.5x comes from standard optimizations: torch.compile with max-autotune, fused QKV projections and channels-last memory layout. Another 2x comes from First Block Caching (via ParaAttention, based on TEACache), which skips denoising steps whose early-block residual change falls below a threshold. A threshold of 0.12 gave a good quality/speed tradeoff. The tens of minutes of compile time added to cold starts were cut roughly 30x by persisting Inductor, Triton and CUDA caches on a volume and using Modal memory snapshots.

  • ThunderAgent: 2x Faster Agentic Inference for Synthetic Data Generation at Scale

    Together AI hardMaster

    ThunderAgent is a scheduling layer between agent clients and inference backends that treats each multi-turn agentic workflow as a schedulable program instead of independent requests, preventing KV cache thrashing when agents pause for tool calls. Under memory pressure it pauses low-priority programs to raise cache hit rates, then resumes them via a global waiting queue onto the node with the most free capacity, replacing static session pinning. On one 8×H100 node with HiCache at batch 192 it reached 803 vs 390 tokens/s for SGLang, with mean latency cut from 65s to 10.6s. Across 2 to 8 nodes it scaled near-linearly and outperformed SGLang Gateway by up to 2.39×, requiring only a program_id field on OpenAI-compatible requests.

  • How to serve trillions of tokens for trillion-parameter coding agents

    Modal hardMaster

    Modal describes how it serves Moonshot AI's trillion-parameter Kimi K2.6 model for coding-agent traffic at trillions of tokens. In that workload, requests average about 100k input to 500 output tokens with heavy prefix overlap across session turns. Their approach was to optimize a single replica first, raising interactivity and then throughput, and to scale out afterward. The changes included NVFP4 quantization on B200/B300 GPUs, tensor parallelism within 8-GPU NVLink domains, DFlash speculative decoding, freeing and quantizing HBM intermediates, and extending the KV cache into CPU RAM with SGLang HiCache. Together they improved per-replica performance 2.8x per user and 5.6x across users, and the post argues that small 8-GPU replicas match larger NVL72 deployments on per-GPU throughput while being far easier to schedule.

The quest for software engineering knowledge.

Look:
Layout: