Performance
EngineSurogate EngineThis page is a work in progress. It collects practical tuning tips and describes the main optimizations in Surogate, so you know which ones run on their own and which you switch on.
High-Level Optimizations
Section titled “High-Level Optimizations”These optimizations make training use less memory and run faster.
Kernel Fusions
Section titled “Kernel Fusions”Kernel fusion is always on; there is no config key for it. Surogate fuses every run of successive operations that contains neither a global reduction nor a matrix multiplication, so intermediate results don’t make a round trip through device memory. Non-linearities and the joint RMS-norm + residual kernel also return the abs-max of their output, so FP8 quantization needs no extra read. FP8 GEMMs on consumer GPUs accept only the TN layout, so a fused transpose+quantize kernel prepares their inputs, and the cross-entropy forward and backward run in one kernel without materializing the per-token loss tensor. Multi-GPU training describes each fusion.
LoRA Fusions
Section titled “LoRA Fusions”LoRA fusion is automatic too. Where a LoRA adapter targets a slice of a fused projection (q of qkv, or gate or up of gate_up) in BF16 at rank 8, 16, 32 or 64, Surogate accumulates the adapter’s output into that slice in place, with the LoRA scaling folded in. That reads and writes the slice once, where a separate GEMM followed by an add would move it four times, which is most of a LoRA step’s extra memory traffic on a bandwidth-bound GPU such as the DGX Spark. Ranks without a dedicated kernel, and cases the kernel rejects, fall back to the regular GEMM path. The adapter itself is set with the LoRA settings.
Fused RoPE
Section titled “Fused RoPE”Rotary Position Embedding (RoPE) rotates query and key vectors by position. The standard implementation precomputes frequency tensors (freq_cis) and keeps them in GPU memory. The fused implementation computes these frequencies on the fly inside the kernel.
Enable via config
Section titled “Enable via config”use_fused_rope: trueHow it works
Section titled “How it works”Standard RoPE:
- Precompute a
freq_cistensor of shape(T, 2*head_dim)with the cos/sin values for all positions. - Store it in GPU global memory.
- During forward/backward, load these values from global memory for each head.
Fused RoPE:
- Allocate no precomputed tensor.
- Each CUDA block computes the cos/sin values on the fly with
sincosf(). - The results are cached in shared memory and reused across all heads in the block.
When to use
Section titled “When to use”Fused RoPE helps when:
- you train with long sequences, where the
freq_cisallocation gets large - memory is tight and every MB counts
- the model has many attention layers, so the savings add up
Multi-threaded multi-GPU
Section titled “Multi-threaded multi-GPU”On one node, Surogate drives all GPUs from threads in a single process, so GPUs can copy memory to each other directly without IPC handles. See Multi-threading vs multiprocessing.
Chunked Attention
Section titled “Chunked Attention”attn_bwd_chunks splits the attention backward pass into N chunks to save workspace memory. For sequences too long to fit at all, sequence_chunks runs the whole layer stack in chunks and carries attention KV between them (see Chunked-Sequence Training).
Chunked LM
Section titled “Chunked LM”lmhead_chunks splits the LM-head computation into N chunks, which makes the logit tensor N times smaller. See Memory Optimization Settings.
See also
Section titled “See also”- Multi-GPU: fused kernels and communication overlap across GPUs
- Precision & recipes: FP8 and FP4 training for higher throughput
- Back to docs index