Skip to content
SurogateSurogateDocs
↑↓ to move↵ to openesc to close

Performance

This 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.


These optimizations make training use less memory and run faster.

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 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.

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.

yaml
use_fused_rope: true

Standard RoPE:

  1. Precompute a freq_cis tensor of shape (T, 2*head_dim) with the cos/sin values for all positions.
  2. Store it in GPU global memory.
  3. During forward/backward, load these values from global memory for each head.

Fused RoPE:

  1. Allocate no precomputed tensor.
  2. Each CUDA block computes the cos/sin values on the fly with sincosf().
  3. The results are cached in shared memory and reused across all heads in the block.

Fused RoPE helps when:

  • you train with long sequences, where the freq_cis allocation gets large
  • memory is tight and every MB counts
  • the model has many attention layers, so the savings add up

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.

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).

lmhead_chunks splits the LM-head computation into N chunks, which makes the logit tensor N times smaller. See Memory Optimization Settings.