Skip to content

Block CUDA graphs: decide before recording, release the pool, cap FSDP2 kept weights, drop unneeded copies - #15352

Merged
danielhanchen merged 19 commits into
mainfrom
dh/s7-block-cudagraphs-costs
Oct 28, 2026
Merged

danielhanchen merged 19 commits into
mainfrom
dh/s7-block-cudagraphs-costs

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

UNSLOTH_BLOCK_CUDAGRAPHS=1 (opt-in, unsloth/models/_block_compile.py) records one CUDA graph tree per compiled decoder block. A Kaggle T4x2 matrix (single GPU, DDP, native FSDP2; LoRA, QLoRA, full finetune; GC off / unsloth / hf; fixed and variable padded lengths) found it never faster on a T4, 1.3 to 2.0x slower in total with variable padded lengths, +0.5 to 1.2 GB reserved per rank, +3 to 4.75 GB reserved once graphs turned off, one OOM, and 1.64 GiB of fp32 block weights kept gathered per rank under a sharded FSDP2 full finetune. This PR removes those costs where graphs cannot help, and keeps them where they can.

With the flag unset nothing changes: every new branch sits behind the flag.

Changes

  1. Decide before recording.

    • Packed / padding-free rows (packed_seq_lengths, cu_seq_lens_q, cu_seq_lens_k, cu_seqlens in the layer kwargs) turn graphs off at the first call, before anything is recorded, with one rank-0 notice. On Unsloth's own forwards packed rows already ran the stock forward, so graphs never engaged there. On transformers forwards the total length changes every step, so each step recorded a new graph. The notice now says so.
    • The shape cap drops from 8 to 2: one fixed length plus a short last batch. On a T4 the 8 admitted lengths re-recorded at every new length, and that cost 15 to 65 s over 40 steps. UNSLOTH_BLOCK_CUDAGRAPHS_MAX_SHAPES still overrides it.
    • Past the cap, graphs go off for every block class at once, with one rank-0 notice. All classes share one cudagraph tree, and so one pool, per device. Before, the cap was per class.
  2. Release the pool. Once graphs are off, the next block call frees the tree with torch._inductor.cudagraph_trees.reset_cudagraph_trees(), then runs torch.cuda.empty_cache(). Before, the pool stayed reserved after graphs turned off: 3.08 to 4.75 GB on a T4, and one OOM in a DDP full finetune with variable lengths and GC off.

    • reset_cudagraph_trees() shuts down every device's tree. A tree function called after that fails in CUDAGraphTreeManager.run with "Running CUDAGraph after shutdown" (torch/_inductor/cudagraph_trees.py: 2.10 L2030, 2.13 L2175, 2.14 L2403). So it runs only when all of these hold:
      • every function in the tree came from a block compile. Each graphed block call records the compile ids of the tree functions it created, from manager.ids_to_funcs / manager.id_to_compile_id. The backward of the same compile shares its compile id;
      • running_forwards_with_pending_backwards is false;
      • live_cudagraph_pool_storages_in_curr_execution() is empty.
    • If another region records into the tree (a user's mode="reduce-overhead"), the pool is kept and a notice says why. A pending backward or a tensor still alive in the pool postpones the release to a later block call.
    • Source references: reset_cudagraph_trees is at 2.10 L304, 2.13 L350 and 2.14 L362; shutdown is at 2.10 L2205, 2.13 L2374 and 2.14 L2620.
  3. Native FSDP2: cap what is kept gathered. _keep_unsharded_for_block_cudagraphs now adds up the bytes it would keep per rank before keeping anything.

    • Over UNSLOTH_BLOCK_CUDAGRAPHS_FSDP2_KEEP_GB (default 0.5 GiB), nothing is kept. Those blocks are marked and run their graphs-off compile, with one rank-0 notice. Without kept weights, graphs would re-record every step.
    • LoRA keeps only the adapters (Qwen3-0.6B: 38 MiB), so it stays under the budget.
    • The sharded full finetune kept 1.64 GiB fp32 per rank for graphs that measured the same speed. It is now over the budget.
    • The byte count read orig_dtype / param_dtype, which FSDP2 sets only at lazy init (the first forward). It always printed 0.00 GiB. It now reads the mixed-precision policy, else the sharded dtype, and prints small sizes in MiB.
  4. Drop copies out of the pool outside checkpointing. Block outputs and input gradients are no longer cloned for a grad-mode call outside backward:

    • in that case CUDAGraphTreeManager.run marks a forward as pending (2.10 L2037, 2.13 L2182, 2.14 L2410);
    • can_start_new_generation then starts no new generation until a backward runs (2.10 L2377, 2.13 L2557, 2.14 L2820);
    • the next block and the backward therefore read those outputs and gradients inside the same generation.

    Checkpointed blocks still copy: their forward runs without grad, and their recompute runs inside backward (torch._C._current_graph_task_id() != -1), and both can start a generation. Frozen calls (inference graphs) also still copy, and so does the grad-mode trial that runs before a checkpointed block's first call. That trial stands in for the recompute. Parameter gradients are still copied on their first write, because they live across generations under gradient accumulation.

Tests

CPU (torch 2.10.0, 2.13.0 and 2.14.1 venvs):

  • tests/test_block_cudagraphs_clone.py 29 passed on each version. Of these, 16 fail on main.
  • The updated tests/test_fsdp2_native_block_cudagraphs_gloo.py (gloo, world 2) 11 passed on each version. The over-budget test fails on main, which keeps the weights.
  • tests/test_block_compile.py failures are the same on main and on this branch: 4 on 2.10 and 1 on 2.13 / 2.14 (test_sm_count_is_read_outside_the_trace, plus the decode-aware MoE outer-compile tests on 2.10).

GPU (tests/test_block_cudagraphs_gpu.py, real cudagraph trees; torch 2.10.0, 2.13.0 and 2.14.1, on a Colab A100-40GB and an L4):

test this branch main
fixed shape, no checkpointing, gradient accumulation 2: replays, no re-recording after warm-up, weights match eager, no copies pass fail: 36 output copies in 6 steps
reentrant checkpointing: copies, matches eager pass pass
variable lengths, cap 2: off at the third length, nothing recorded after, pool released pass fail: 172 MiB still reserved after empty_cache()

Where block graphs pay (timing)

Setup:

  • Qwen3-0.6B and Qwen3-1.7B LoRA (r 16, all linear), bf16, fixed-length rows of exactly seq tokens, 60 steps.
  • Steady ms/step is the median from step 10 on, skipping any step that recorded or recompiled.
  • Each arm is a fresh process with fresh compile caches. Arms are interleaved on one exclusive Colab card per tier. Each repeat runs main graphs off (M0), main graphs on (M1), branch graphs off (B0) and branch graphs on (B1) in a rotating ABBA order.
  • B0 against M0 is the A/A check: with the flag unset the branch is byte-identical. It stayed within 0.98 to 1.02.
  • 95% CI is a bootstrap over 3 paired repeats.
  • Software: torch 2.14.1+cu130, transformers 5.17.0, TRL 1.15.0, PEFT 0.21.2.

Tiers:

  • A100 is a Colab A100-SXM4-40GB on a 12 vCPU host;
  • G4 is an RTX PRO 6000 Blackwell;
  • L4 ran Qwen3-0.6B only;
  • H100 was not available on either account (two tries).

Graphs on / off on this branch (B1/B0, below 1 = graphs faster), and this branch / main with graphs on (B1/M1), single GPU:

model seq bs GC A100 ms/step off -> on (branch) A100 on/off [CI] A100 branch/main on [CI] G4 ms/step off -> on (branch) G4 on/off [CI] G4 branch/main on [CI] L4 ms/step off -> on (branch) L4 on/off [CI] L4 branch/main on [CI]
0.6B 256 1 off 164 -> 79 0.48 [0.48, 0.49] faster 0.95 [0.93, 0.97] faster 47 -> 24 0.52 [0.51, 0.54] faster 1.00 [0.97, 1.05] same 163 -> 83 0.51 [0.50, 0.52] faster 0.97 [0.95, 0.98] same
0.6B 256 1 unsloth 234 -> 118 0.50 [0.49, 0.50] faster 1.02 [1.02, 1.02] slower 71 -> 38 0.53 [0.52, 0.54] faster 1.05 [1.02, 1.10] same 234 -> 120 0.51 [0.51, 0.53] faster 1.01 [1.00, 1.02] same
0.6B 256 4 off 162 -> 80 0.50 [0.49, 0.50] faster 0.98 [0.97, 0.99] same 47 -> 31 0.68 [0.66, 0.70] faster 0.98 [0.98, 0.98] same 166 -> 102 0.62 [0.61, 0.62] faster 0.99 [0.99, 1.00] same
0.6B 256 4 unsloth 228 -> 118 0.51 [0.51, 0.52] faster 1.03 [1.03, 1.04] slower 68 -> 39 0.57 [0.56, 0.58] faster 1.00 [0.99, 1.00] same 237 -> 137 0.58 [0.58, 0.58] faster 1.00 [1.00, 1.01] same
0.6B 512 1 off 161 -> 77 0.48 [0.47, 0.49] faster 0.95 [0.94, 0.95] faster 47 -> 24 0.51 [0.50, 0.52] faster 0.98 [0.97, 0.99] same 166 -> 84 0.51 [0.50, 0.52] faster 0.97 [0.95, 1.01] same
0.6B 512 1 unsloth 230 -> 112 0.49 [0.49, 0.50] faster 1.02 [1.00, 1.05] same 70 -> 37 0.53 [0.52, 0.54] faster 1.05 [1.02, 1.09] slower 234 -> 121 0.52 [0.51, 0.52] faster 1.02 [1.01, 1.03] slower
0.6B 512 4 off 160 -> 79 0.50 [0.49, 0.50] faster 0.97 [0.96, 0.97] same 49 -> 43 0.89 [0.89, 0.91] faster 0.99 [0.99, 0.99] faster 192 -> 191 0.99 [0.98, 1.00] faster 1.00 [0.99, 1.01] same
0.6B 512 4 unsloth 238 -> 125 0.53 [0.53, 0.53] faster 1.01 [0.99, 1.02] same 74 -> 56 0.76 [0.75, 0.76] faster 1.00 [1.00, 1.00] same 259 -> 256 0.99 [0.99, 1.00] faster 1.00 [1.00, 1.01] same
0.6B 1024 1 off 158 -> 77 0.49 [0.48, 0.50] faster 0.96 [0.94, 0.98] faster 47 -> 33 0.71 [0.69, 0.74] faster 0.98 [0.97, 1.00] same 164 -> 111 0.67 [0.67, 0.67] faster 1.00 [1.00, 1.00] same
0.6B 1024 1 unsloth 223 -> 113 0.51 [0.51, 0.51] faster 1.02 [1.01, 1.02] same 67 -> 42 0.62 [0.60, 0.63] faster 1.00 [0.99, 1.00] same 231 -> 146 0.63 [0.63, 0.64] faster 1.00 [1.00, 1.00] same
0.6B 1024 4 off 164 -> 117 0.72 [0.71, 0.72] faster 0.99 [0.99, 0.99] same 76 -> 73 0.96 [0.96, 0.96] faster 0.99 [0.99, 0.99] faster 405 -> 409 1.01 [1.01, 1.02] same 0.99 [0.99, 1.00] same
0.6B 1024 4 unsloth 244 -> 157 0.64 [0.64, 0.64] faster 1.00 [1.00, 1.00] same 100 -> 97 0.97 [0.97, 0.98] faster 1.00 [1.00, 1.00] same 538 -> 553 1.03 [1.02, 1.03] slower 1.00 [1.00, 1.00] same
1.7B 256 1 off 162 -> 79 0.49 [0.48, 0.50] faster 0.97 [0.96, 0.99] faster 48 -> 26 0.53 [0.53, 0.54] faster 0.99 [0.99, 1.00] same - - -
1.7B 256 1 unsloth 236 -> 118 0.49 [0.49, 0.50] faster 1.03 [1.01, 1.05] same 73 -> 38 0.53 [0.50, 0.56] faster 1.00 [0.96, 1.03] same - - -
1.7B 256 4 off 166 -> 82 0.49 [0.49, 0.50] faster 0.97 [0.95, 0.98] same 50 -> 48 0.97 [0.96, 0.97] faster 0.99 [0.99, 1.00] same - - -
1.7B 256 4 unsloth 232 -> 118 0.50 [0.49, 0.52] faster 1.01 [0.98, 1.03] same 72 -> 65 0.91 [0.89, 0.93] faster 1.00 [1.00, 1.01] same - - -
1.7B 512 1 off 169 -> 82 0.48 [0.46, 0.49] faster 0.96 [0.95, 0.98] same 48 -> 34 0.71 [0.69, 0.75] faster 0.98 [0.98, 0.98] same - - -
1.7B 512 1 unsloth 234 -> 121 0.50 [0.49, 0.52] faster 1.03 [1.01, 1.03] same 69 -> 46 0.66 [0.65, 0.68] faster 1.00 [1.00, 1.00] same - - -
1.7B 512 4 off 162 -> 120 0.74 [0.73, 0.74] faster 0.99 [0.99, 0.99] same 78 -> 75 0.97 [0.97, 0.97] faster 0.99 [0.99, 0.99] faster - - -
1.7B 512 4 unsloth 239 -> 163 0.66 [0.63, 0.68] faster 1.00 [1.00, 1.00] same 106 -> 103 0.97 [0.97, 0.97] faster 1.00 [1.00, 1.00] same - - -
1.7B 1024 1 off 160 -> 81 0.50 [0.49, 0.51] faster 0.97 [0.95, 0.98] same 51 -> 50 0.97 [0.96, 0.97] faster 0.99 [0.99, 0.99] faster - - -
1.7B 1024 1 unsloth 240 -> 127 0.53 [0.52, 0.54] faster 1.02 [1.00, 1.04] same 76 -> 67 0.89 [0.88, 0.89] faster 1.00 [0.99, 1.00] same - - -
1.7B 1024 4 off 212 -> 210 0.99 [0.99, 0.99] faster 0.99 [0.99, 0.99] faster 136 -> 134 0.99 [0.99, 0.99] faster 0.99 [0.99, 0.99] faster - - -
1.7B 1024 4 unsloth 291 -> 290 1.00 [1.00, 1.00] faster 1.00 [1.00, 1.00] same 185 -> 184 0.99 [0.99, 0.99] faster 1.00 [1.00, 1.00] same - - -

Native FSDP2 at world size 1 (sharded by hand, adamw_torch; compare only within this table):

model seq bs GC A100 ms/step off -> on (branch) A100 on/off [CI] A100 branch/main on [CI] G4 ms/step off -> on (branch) G4 on/off [CI] G4 branch/main on [CI]
0.6B 256 1 off 163 -> 79 0.48 [0.48, 0.49] faster 0.95 [0.94, 0.97] faster 52 -> 31 0.58 [0.55, 0.61] faster 0.97 [0.89, 1.06] same
0.6B 256 1 unsloth 234 -> 117 0.50 [0.49, 0.50] faster 1.02 [1.01, 1.02] same 76 -> 46 0.58 [0.57, 0.60] faster 1.00 [0.95, 1.03] same
0.6B 256 4 off 161 -> 80 0.49 [0.49, 0.50] faster 0.95 [0.94, 0.95] faster 55 -> 32 0.59 [0.57, 0.61] faster 0.98 [0.97, 0.99] same
0.6B 256 4 unsloth 229 -> 118 0.51 [0.51, 0.52] faster 1.01 [1.01, 1.01] same 79 -> 47 0.60 [0.59, 0.60] faster 1.02 [1.02, 1.03] same
0.6B 512 1 off 165 -> 80 0.48 [0.47, 0.49] faster 0.97 [0.96, 0.97] faster 55 -> 31 0.57 [0.54, 0.62] faster 0.99 [0.92, 1.06] same
0.6B 512 1 unsloth 233 -> 117 0.50 [0.49, 0.51] faster 1.01 [0.99, 1.03] same 74 -> 45 0.59 [0.57, 0.61] faster 1.02 [0.96, 1.08] same
0.6B 512 4 off 163 -> 82 0.50 [0.49, 0.50] faster 0.95 [0.95, 0.96] faster 56 -> 44 0.80 [0.79, 0.83] faster 0.99 [0.99, 0.99] same
0.6B 512 4 unsloth 242 -> 130 0.54 [0.53, 0.55] faster 1.01 [0.99, 1.03] same 85 -> 57 0.67 [0.67, 0.68] faster 1.00 [0.99, 1.00] same
0.6B 1024 1 off 161 -> 79 0.49 [0.49, 0.50] faster 0.94 [0.93, 0.96] faster 55 -> 34 0.61 [0.60, 0.62] faster 1.00 [0.98, 1.03] same
0.6B 1024 1 unsloth 228 -> 117 0.51 [0.50, 0.52] faster 1.01 [1.00, 1.03] same 78 -> 48 0.60 [0.58, 0.61] faster 1.01 [0.97, 1.03] same
0.6B 1024 4 off 167 -> 117 0.70 [0.70, 0.71] faster 0.99 [0.99, 0.99] same 78 -> 74 0.94 [0.94, 0.95] faster 0.99 [0.98, 0.99] faster
0.6B 1024 4 unsloth 245 -> 157 0.64 [0.64, 0.64] faster 1.00 [1.00, 1.00] same 102 -> 98 0.96 [0.96, 0.96] faster 1.00 [1.00, 1.00] same
1.7B 512 1 off 163 -> 80 0.49 [0.49, 0.49] faster 0.96 [0.95, 0.97] faster 56 -> 36 0.64 [0.61, 0.69] faster 1.01 [0.94, 1.04] same
1.7B 512 1 unsloth 234 -> 116 0.50 [0.49, 0.50] faster 1.00 [1.00, 1.01] same 79 -> 49 0.61 [0.60, 0.62] faster 1.00 [0.95, 1.02] same

Main reproduces the earlier #15154 numbers. That PR reported Qwen3-0.6B LoRA, seq 512, fixed length, torch 2.14.1: -40.7% step on L4, -58.6% on A100, -27.6% at seq 2048 on A100, and +2.4% on L4 at seq 2048 (GPU-bound). The same config on current main (fbc905fd02), graphs on against graphs off (M1/M0, 95% CI):

GPU batch 1 batch 4 GPU-bound check
L4 -49.1% [-49.2, -48.9] (GC "unsloth"), -47.6% (GC off) -0.9% / -1.0% batch 4 x 1024 is slower: +3.0% / +1.6%
A100 -51.9% [-52.4, -51.2] (GC "unsloth"), -49.5% (GC off) -47.7% / -48.4% batch 4 x 1024: -35.2% / -27.8%
G4 -49.1% / -46.1% -25.3% / -9.5% batch 4 x 1024: -2.6% / -2.7%

Peak reserved is +0.5 to 0.8 GB, as in #15154. #15154 did not record its batch size or GC mode, so the comparison is by config, not arm for arm. This branch keeps the same gains (B1/B0 within 0.03 of M1/M0 in every cell).

Read across:

  • Launch-bound steps: graphs make the step up to 2x faster. That means batch 1, or batch 4 with short rows:
    • A100, every cell but Qwen3-1.7B at batch 4 x 1024: 0.48 to 0.53. The host CPU is slow, so the step is launch-bound there.
    • G4 and L4: 0.51 to 0.53 at batch 1 with 256 to 512 tokens.
  • The gain fades as the GPU fills:
    • G4: 0.71 at batch 1 x 1024, 0.89 at batch 4 x 512, 0.96 at batch 4 x 1024.
    • L4: 0.99 at batch 4 x 512, and 1.01 to 1.03 (slower) at batch 4 x 1024.
  • On T4 (earlier matrix) graphs were never faster.
  • Cost on fixed lengths:
    • memory: +0.49 to 0.57 GB peak reserved with GC off, and +0.07 to 0.80 GB with GC "unsloth";
    • recording: 56 graphs (GC off) or 111 (GC "unsloth") at warm-up, none after warm-up;
    • replays: 2800 (GC off) or 4200 (GC "unsloth") over the remaining 50 steps.
  • This branch against main with graphs on:
    • GC off: 3 to 6% faster on A100 and up to 2% on G4 / L4. This comes from dropping the output and input-gradient copies (1680 output and 1680 gradient copies per 60 steps on main, none here).

    • GC "unsloth": within noise on G4 / L4 for Qwen3-1.7B and at batch 4.

    • Qwen3-0.6B at batch 1 measured 1 to 3% slower on A100 and L4 with the first commit. That commit let the grad-mode trial before a checkpointed block's first call skip its copies. The last commit routes the trial back through the copy path, as on main.

    • Re-measured on A100 with 6 paired repeats of main against the final head, B1/M1 is:

      cell B1/M1 [95% CI]
      seq 256, GC "unsloth" 1.007 [0.992, 1.022], same
      seq 512, GC "unsloth" 1.001 [0.983, 1.018], same
      seq 256, GC off 0.955 [0.949, 0.961], faster

      The large tables above ran the first commit. The later commits change only this trial path, the tree-manager lookup and a notice string.

Distributed re-check (Kaggle T4x2, 2 ranks, Qwen3-0.6B, fp16, 40 steps, 2 repeats)

M0 = main graphs off, M1 = main graphs on, B1 = this branch graphs on. Variable lengths are padded FineTome chat rows; fixed rows are 1024 tokens.

cell (2 ranks, Kaggle T4x2) steady ms/step M0 / M1 / B1 train s (40 steps, per repeat) M0 ; M1 ; B1 peak reserved GB r0/r1 M0 ; M1 ; B1 records / replays M1 ; B1 kept GiB per rank M1 ; B1
full_ddp_var_off 1038 / OOM 2/2 / 1024 82.9 / 59.0 ; OOM 2/2 ; 73.4 / 64.1 12.11/12.09 ; OOM 2/2 ; 12.09/12.11 - ; 0/0 - ; 0.00
full_fsdp2_fixed_off 1307 / 1320 / 1324 76.4 / 60.3 ; 73.3 / 62.7 ; 61.0 / 61.1 9.66/9.66 ; 11.38/11.37 ; 9.66/9.66 56/2128 ; 0/0 1.64 ; 0.00
lora_ddp_fixed_off 996 / 1065 / 1138 51.9 / 56.4 ; 57.1 / 57.0 ; 63.5 / 58.2 5.76/5.76 ; 6.33/6.33 ; 6.33/6.33 56/2128 ; 56/2128 0.00 ; 0.00
lora_ddp_fixed_unsloth 1478 / 1490 / 1486 75.6 / 73.8 ; 76.7 / 72.8 ; 74.1 / 74.3 1.70/1.68 ; 2.43/2.43 ; 2.43/2.43 139/4364 ; 139/4364 0.00 ; 0.00
lora_ddp_var_off 821 / 875 / 854 44.2 / 44.3 ; 68.9 / 61.3 ; 48.8 / 50.2 5.76/5.76 ; 10.51/10.49 ; 5.90/5.78 56/112 ; 0/0 0.00 ; 0.00
lora_fsdp2_fixed_off 1139 / 1147 / 1146 55.7 / 56.2 ; 57.0 / 56.9 ; 58.3 / 58.2 5.79/5.79 ; 6.36/6.36 ; 6.36/6.36 56/2128 ; 56/2128 0.04 ; 0.04
lora_fsdp2_fixed_unsloth 1484 / 1507 / 1507 74.8 / 72.7 ; 74.8 / 72.6 ; 74.1 / 74.1 1.67/1.67 ; 2.45/2.45 ; 2.45/2.45 111/3273 ; 111/3273 0.04 ; 0.04
lora_fsdp2_var_off 877 / 905 / 873 45.3 / 44.4 ; 62.3 / 61.7 ; 49.2 / 49.6 5.79/5.79 ; 10.54/10.52 ; 5.93/5.79 56/112 ; 0/0 0.04 ; 0.04
  • Variable lengths:
    • with graphs on, main reserved +4.75 GB per rank and trained 17 to 25 s slower in 40 steps;
    • this branch turns graphs off at the third length, before anything was recorded (GC off warms up first), and stays within +0.14 GB;
    • the remaining 4.5 to 6 s is the one-off graphs-off compile;
    • steady steps are 2.4 to 3.5% faster than main with graphs on.
  • DDP full finetune, variable lengths, GC off:
    • main with graphs on runs out of memory on rank 1 in both repeats;
    • this branch trains, at 1024 against 1038 ms/step;
    • the notice reads released the block CUDA graph pool (5.17 GiB reserved freed).
  • FSDP2 sharded full finetune:
    • main keeps 1.64 GiB of fp32 block weights gathered per rank (11.38 against 9.66 GB peak reserved);
    • this branch keeps nothing and runs those blocks without graphs, at 9.66 GB, the same as graphs off;
    • speed is the same: 1324 against 1320 ms/step.
  • LoRA at fixed length (DDP and FSDP2, GC off / "unsloth"): unchanged. Same records and replays, the same peak reserved, and the same steady time within the T4's drift.
    • The one outlier is the DDP GC off cell (B1 1138 against M1 1065 ms). Its repeats were M0 863 / 1128, M1 1000 / 1128, B1 1140 / 1136. Repeat 1 agrees within 1%. Repeat 0 ran M0, M1, B1 in that order while the T4 heated up.

Not covered

  • H100: Colab gave neither account one.
  • L4 ran Qwen3-0.6B only.
  • Mac / AMD: block graphs are CUDA only, and the flag is unchanged off CUDA.
  • The release path when another reduce-overhead region shares the tree is covered only by the CPU fake-manager test, not on a GPU.
  • GRPO / DPO trainers were not timed.

…P2 kept weights, drop unneeded copies

UNSLOTH_BLOCK_CUDAGRAPHS=1 (opt-in) cost time and memory where it could not help:

- Packed / padding-free rows: graphs never engaged; now they stay off from the first call with one
  rank-0 notice saying so.
- Variable padded lengths: each new length re-recorded until 8 shapes, then a graphs-off copy
  compiled mid-run while the graph pool stayed reserved (+3 to 4.75 GB on a T4, one OOM). The cap
  is now 2 shapes (one length plus a short last batch), graphs go off for every block class at
  once (they share one cudagraph tree per device) with a notice, and the pool is released with
  reset_cudagraph_trees() once no forward is pending and every tree function came from a block
  compile (otherwise it is kept and the notice says why).
- Native FSDP2: the gathered weights kept for graphs are capped per rank
  (UNSLOTH_BLOCK_CUDAGRAPHS_FSDP2_KEEP_GB, default 0.5); over it nothing is kept and those blocks
  run without graphs (a sharded full finetune kept 1.64 GiB fp32 per rank for no speedup). The
  kept-bytes count read dtypes FSDP2 only sets at lazy init, so it always said 0.00 GiB.
- Block outputs and input gradients are no longer cloned out of the pool for grad-mode calls
  outside backward: a pending forward keeps cudagraph trees in one generation until the backward.
  Checkpointed blocks (no-grad forward, recompute inside backward) still copy.

Flag unset: unchanged.
LoRA keeps tens of MiB of adapters per rank, which printed as 0.00 GiB.
Two get_manager lookups per block call become one cached read. The manager is looked up before
the first call too, so functions another region recorded earlier are never counted as ours.
… like its recompute

The trial before a checkpointed block's first no-grad call stands in for the recompute; it now
takes the recompute's copy path, as before, so it records what the recompute replays.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T05:58:29.099206Z 34563f8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 44b26ce487

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: b203418358

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…s-costs

# Conflicts:
#	unsloth/models/_block_compile.py

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7922b15d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth/models/_block_compile.py Outdated
Comment on lines +259 to +260
stack.extend(n for n, _ in node.next_functions if n is not None)
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Copy input gradients that reach leaves through view operations

With block CUDA graphs enabled and checkpointing disabled, caller-provided inputs_embeds created as a view of an external trainable parameter (for example, embedding_param.view(batch, length, dim)) bypasses the gradient copy: this traversal visits ViewBackward and AccumulateGrad, then returns False. A view backward can pass the graph-pool gradient through without allocating new storage, so the parameter's first accumulated .grad can still alias the replay buffer and be overwritten on a subsequent backward. The new direct-leaf check fixes leaf hidden_states, but not this non-leaf path to a leaf; treat an encountered AccumulateGrad as requiring a copy unless an intervening operation guarantees independent gradient storage.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in 58c5f69. The walk now tracks, per path, whether it passed an op whose backward writes a new input gradient (mm / addmm / mul / embedding / norm / softmax and similar). Reaching an AccumulateGrad without one on the path (a view, add or clone of a leaf, like inputs_embeds = param.view(...)) counts as needing the copy. New test_input_viewing_a_trainable_param_copies_its_gradient: the view and view + add cases fail on the previous head and pass now, the embedding lookup case still takes no copy. tests/test_block_cudagraphs_clone.py 36 passed (CPU), tests/test_block_cudagraphs_gpu.py 3 passed on B200.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 58c5f690ac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth/models/_block_compile.py Outdated
"SoftmaxBackward",
"SiluBackward",
"GeluBackward",
"CatBackward",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve input-gradient copies across concatenation backward

With block CUDA graphs enabled and checkpointing disabled, concatenating a trainable prompt with embeddings can still leave the prompt's .grad aliasing the replay buffer. The new CatBackward allowlist entry marks this path as having independent gradient storage, but concatenation backward returns narrowed views of its incoming gradient rather than allocating new storage. For contiguous slices (for example, sequence concatenation with batch size one), AccumulateGrad can retain that storage, allowing a subsequent replay to overwrite the accumulated prompt gradient. Remove CatBackward from the allocating-backward allowlist so these inputs retain _CloneGrad protection.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed and fixed in f3d179d: CatBackward is out of the allocating list (its backward returns narrowed views of the incoming gradient), so a leaf reached through a concatenation keeps the copy. The other entries (slice / select / index backward and the matmul, elementwise and norm backwards) write a new tensor. New cat case in test_input_viewing_a_trainable_param_copies_its_gradient (a trainable prompt concatenated in front of other rows): fails on the previous head, passes now; the file has 37 passed.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 07d5d67ff4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

[skip ci]
@danielhanchen danielhanchen self-assigned this Oct 27, 2026
# Conflicts:
#	tests/test_block_cudagraphs_clone.py
#	unsloth/models/_block_compile.py

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits October 28, 2026 05:45
… regions

Other compiled functions (e.g. a compiled prompt preprocessor) can pass the incoming
gradient straight to a trainable leaf, so their first .grad would alias the graph pool.
Tag the autograd nodes of graphed block calls and copy conservatively for any other
compiled producer.

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 28, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 34563f81ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 2bcde87 into main Oct 28, 2026
3 of 30 checks passed
@danielhanchen
danielhanchen deleted the dh/s7-block-cudagraphs-costs branch October 28, 2026 07:03
danielhanchen added a commit that referenced this pull request Oct 28, 2026
)

## Problem

`UNSLOTH_BLOCK_CUDAGRAPHS=1` under native FSDP2 keeps the all-gathered
weights of every parameter inside a compiled decoder block allocated
(`_keep_unsharded_for_block_cudagraphs`, #15215), so the block CUDA
graphs see one address per weight and replay instead of re-recording.

Since #15553, `_block_compile` runs MoE blocks compiled without CUDA
graphs (`_graphs_unsafe_moe`: routing outputs are overwritten across
replays and the grouped GEMM copies offsets to the host during capture).
FSDP2 still kept the gathered weights of those blocks. Those graphs
never record, so nothing reads the fixed addresses. The cost is that
every rank holds every expert of every MoE block unsharded after the
first forward. For MoE models, the experts are most of the weights, so
most of what FSDP2 shards stays fully gathered on every rank.

## Fix

`_compiled_block_modules` skips blocks that
`_block_compile._graphs_unsafe_moe` marks as MoE. It uses the same check
that routes them to the graphs-off path, so the two cannot disagree.
Their gathered weights are freed at reshard as usual. Dense blocks keep
theirs, and nothing changes without `UNSLOTH_BLOCK_CUDAGRAPHS=1` or
without block compile, because the check only runs on blocks
`_block_compile` wrapped.

## Tests

`tests/test_fsdp2_native_block_cudagraphs_moe_gloo.py` (CPU, gloo, world
size 2). It uses a tiny random Qwen3-MoE whose layer 0 is dense
(`mlp_only_layers=[0]`) and layer 1 is MoE,
`UNSLOTH_BLOCK_CUDAGRAPHS=1`, full finetune, 2 steps,
`_block_compile.py` loaded by file path:

| test | main | this branch |
|---|---|---|
| `test_moe_block_weights_are_freed_under_block_cudagraphs` | FAIL (MoE
block storages kept, size > 0) | PASS (size 0) |
| `test_dense_block_weights_stay_kept_under_block_cudagraphs` | PASS |
PASS |

The existing `tests/test_fsdp2_native_block_cudagraphs_gloo.py` and
`tests/test_block_cudagraphs_clone.py` still pass (61 passed with the
new file, main at d21d016). `tests/test_fsdp2_native_units.py` passes
too (40 passed, before the rebase onto #15352). All runs used torch 2.13
and transformers 5.17 on CPU.

## Not covered

- No GPU run. The change only affects which FSDP2 parameters skip
`free_unsharded_param`, and the CPU gloo test checks that directly.
- Flex attention blocks (Gemma3, which #15553 also routes off graphs)
are detected per call from a `BlockMask` argument, so they cannot be
known when FSDP2 shards. Their gathered weights are still kept. They are
dense, so the cost is far smaller.
- Since #15352, the kept bytes are checked against
`UNSLOTH_BLOCK_CUDAGRAPHS_FSDP2_KEEP_GB` (0.5 GB by default), and over
that budget no block keeps its weights and every block runs without
graphs. MoE weights used to count toward that budget, so a MoE model
could turn graphs off for its dense blocks as well. With MoE blocks
skipped, only the blocks that can be graphed count. This follows from
the code and was not measured on a GPU.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 28, 2026
…d LoRA runs (#15768)

## Summary

Block CUDA graphs (`UNSLOTH_BLOCK_CUDAGRAPHS=1`, #15154, #15207, #15352,
#15553) cut LoRA step time by 25 to 57% when a run is launch-bound and
every batch has the same shape. Today they are opt-in, because forcing
them on costs time when the GPU is the bottleneck and when batch shapes
vary. This PR makes the choice automatically, per run, and only turns
graphs on when they are measured to help.

`UNSLOTH_BLOCK_CUDAGRAPHS` now means:

| value | behaviour |
|---|---|
| unset or `auto` (new default) | decided per run, see below |
| `1` | forced on, same as before |
| `0` or anything else | off, same as before (previously every value
other than `1` meant off) |

## How auto decides

1. Static rules, else graphs stay off for the run: CUDA, not ROCm, torch
>= 2.13 (the graphed region gets its own recompile bucket via
`isolate_recompiles`), not distributed, LoRA / QLoRA only (more than
half of a block's weights trainable counts as full finetuning).
2. Probe with graphs off (the same compiled region as before this PR):
every block call must have the batch shape of the first call, and no
call may carry packed / padding-free kwargs, run under non-reentrant
checkpointing, or be a MoE or flex attention block. Any of those turns
auto off for good.
3. Forward passes are counted at the first block's call outside backward
(checkpoint recomputes and the grad-mode trial do not count). Passes 1
and 2 warm up. In pass 3, four block calls are timed: the block's
kernels are queued behind a short `torch.cuda._sleep`, so a CUDA event
pair after the sleep measures GPU time with no launch gaps, while the
host measures how long the launches took. If launching outlasts the
sleep, the GPU time includes gaps, which can only make the ratio
smaller.
4. Graphs turn on at the next forward pass when host launch time >= 1.2
x GPU time and at least max(2 GiB, 10%) of device memory is free. One
line is printed when that happens, naming `UNSLOTH_BLOCK_CUDAGRAPHS=0`.
5. After that the existing safeguards apply unchanged: more than 2 batch
shapes turns graphs off and releases the pool, packed rows turn them
off, MoE / flex blocks run without graphs.

A newly patched model starts a new decision, so a launch-bound model
loaded first cannot turn graphs on for a GPU-bound one.

The 1.2 threshold comes from A100 runs with graphs forced on: ratios
from 0.22 to 0.97 gained nothing (-1.5% to +1.0%), 1.08 gained 5.5%,
1.33 to 1.43 gained 15.7 to 19.6%, and 1.9 or more gained 32 to 57%.

## Results

Colab, torch 2.14.1, transformers 4.57.6, TRL 0.24.0. LoRA r=16 on all
linear layers, `use_gradient_checkpointing="unsloth"`,
`transformers.Trainer`, fixed-length batches, 30 steps. Every run is a
fresh process. Arms are interleaved per config: base (merge base
63b85ca), auto (this PR, env unset), on (this PR, `=1`), base again
(A/A). Times are median step time over steps 8 to 30. Deltas are against
the mean of the two base runs.

Where auto turns graphs on:

| GPU | model | bits | seq | bs | base s | A/A % | auto % | forced on %
| ratio |
|---|---|---|---|---|---|---|---|---|---|
| A100 | Qwen3-0.6B | 16 | 512 | 1 | 0.2224 | 0.2 | -52.9 | -53.9 | 6.54
|
| A100 | Qwen3-0.6B | 16 | 512 | 8 | 0.2329 | 2.1 | -31.8 | -32.8 | 2.00
|
| A100 | Qwen3-0.6B | 16 | 2048 | 1 | 0.2276 | 0.1 | -48.7 | -48.2 |
2.76 |
| A100 | Qwen3-0.6B | 4 | 512 | 1 | 0.2589 | 1.3 | -53.5 | -56.0 | 5.54
|
| A100 | Qwen3-0.6B | 4 | 512 | 8 | 0.2685 | 0.7 | -37.2 | -38.5 | 2.09
|
| A100 | Qwen3-0.6B | 4 | 2048 | 1 | 0.2584 | 1.5 | -50.5 | -51.7 | 3.02
|
| A100 | Llama-3.2-1B | 16 | 512 | 1 | 0.1251 | 1.0 | -54.3 | -54.2 |
3.30 |
| A100 | Llama-3.2-1B | 16 | 512 | 2 | 0.1354 | 0.9 | -49.8 | -50.5 |
1.90 |
| A100 | Llama-3.2-1B | 16 | 512 | 4 | 0.1357 | 1.0 | -19.8 | -19.6 |
1.38 |
| A100 | Llama-3.2-1B | 16 | 2048 | 1 | 0.1353 | 2.0 | -15.4 | -15.7 |
1.33 |
| A100 | Llama-3.2-1B | 4 | 512 | 1 | 0.1409 | 2.4 | -55.9 | -57.5 |
2.62 |
| A100 | Llama-3.2-1B | 4 | 2048 | 1 | 0.1508 | 0.8 | -18.7 | -18.8 |
1.43 |
| L4 | Qwen3-0.6B | 16 | 512 | 1 | 0.2274 | 0.8 | -50.3 | -50.8 | 5.19 |
| L4 | Qwen3-0.6B | 4 | 512 | 1 | 0.2658 | 1.6 | -51.8 | -53.7 | 5.76 |
| L4 | Qwen3-0.6B | 4 | 2048 | 1 | 0.3076 | 0.8 | -3.1 | -3.1 | 1.71 |
| L4 | Qwen3-0.6B | 16 | 2048 | 1 | 0.2972 | 0.1 | -0.3 | -0.3 | 1.49 |
| L4 | Llama-3.2-1B | 16 | 512 | 1 | 0.1490 | 2.5 | -30.0 | -30.3 | 2.26
|
| L4 | Llama-3.2-1B | 4 | 512 | 1 | 0.1642 | 0.6 | -25.0 | -25.2 | 2.04
|
| T4 | Qwen3-0.6B | 16 | 512 | 1 | 0.2213 | 5.7 | -29.1 | -28.8 | 2.15 |
| T4 | Qwen3-0.6B | 4 | 512 | 1 | 0.2531 | 6.5 | -24.3 | -25.9 | 2.34 |

Where auto keeps graphs off (GPU-bound), it matches base inside the A/A
spread, while forcing graphs on costs time:

| GPU | model | bits | seq | bs | base s | A/A % | auto % | forced on %
| ratio |
|---|---|---|---|---|---|---|---|---|---|
| A100 | Qwen3-0.6B | 16 | 2048 | 8 | 0.5526 | 0.1 | -0.0 | +0.6 | 0.55
|
| A100 | Qwen3-0.6B | 4 | 2048 | 8 | 0.5567 | 0.1 | +0.1 | +0.5 | 0.66 |
| A100 | Llama-3.2-1B | 16 | 2048 | 8 | 0.7230 | 0.0 | +0.2 | +1.0 |
0.22 |
| A100 | Llama-3.2-1B | 4 | 2048 | 8 | 0.7286 | 0.0 | -0.0 | +0.7 | 0.25
|
| L4 | Llama-3.2-1B | 16 | 512 | 4 | 0.3481 | 0.1 | +0.0 | +1.5 | 0.67 |
| L4 | Llama-3.2-1B | 16 | 512 | 8 | 0.7083 | 1.1 | +0.2 | +1.6 | 0.31 |
| L4 | Llama-3.2-1B | 16 | 2048 | 1 | 0.3693 | 0.3 | -0.1 | +1.1 | 0.64
|
| L4 | Llama-3.2-1B | 16 | 2048 | 8 | 3.2199 | 1.3 | +1.0 | +2.0 | 0.07
|
| L4 | Llama-3.2-1B | 4 | 2048 | 8 | 3.2285 | 2.0 | +0.9 | +2.7 | 0.08 |
| L4 | Qwen3-0.6B | 16 | 512 | 8 | 0.5153 | 2.0 | +0.7 | +3.6 | 0.80 |
| L4 | Qwen3-0.6B | 4 | 512 | 8 | 0.5288 | 0.4 | -0.2 | +2.9 | 0.91 |
| L4 | Qwen3-0.6B | 16 | 2048 | 2 | 0.5939 | 0.6 | -0.2 | +2.9 | 0.71 |
| L4 | Qwen3-0.6B | 16 | 2048 | 8 | 2.4181 | 0.9 | +0.5 | +2.1 | 0.16 |
| L4 | Qwen3-0.6B | 4 | 2048 | 8 | 2.4317 | 0.7 | +0.7 | +2.8 | 0.18 |
| L4 | Llama-3.2-1B | 4 | 2048 | 1 | 0.3901 | 0.3 | -0.1 | +0.8 | 0.72 |
| L4 | Llama-3.2-1B | 4 | 512 | 8 | 0.7393 | 0.6 | +0.2 | +1.4 | 0.34 |
| T4 | Llama-3.2-1B | 4 | 512 | 1 | 0.2574 | 2.1 | +0.8 | +1.2 | 0.82 |
| T4 | Qwen3-0.6B | 16 | 2048 | 1 | 0.6802 | 1.2 | +0.9 | +3.2 | 0.69 |
| T4 | Qwen3-0.6B | 4 | 2048 | 4 | 2.5835 | 0.1 | -0.1 | +0.7 | 0.17 |

The L4 gray zone: on L4, block ratios of 1.49 to 1.71 turned graphs on
for little or nothing (-3.1% to +0.5%), while on A100 ratios of 1.33 to
1.43 gave 15 to 20%. None of these cases is slower than base beyond the
A/A spread, so the threshold stays at 1.2 and keeps the A100 gains. The
price on L4 there is 0.3 to 0.5 GB more reserved memory.

Other checks:

- Variable padded lengths (pad to the longest row of each batch): auto
stays off (`batch shape changed`), +0.5% on A100 and -0.6% on L4 (A/A
1.0% and 0.1%). Forced on recorded 189 graphs and was 4.3% (A100) and
1.5% (L4) slower.
- `use_gradient_checkpointing=True` (torch reentrant) and `False`: auto
on, -50.6% and -45.4% on A100, +0.5% and -1.1% on L4 (single base run,
ratios 1.58 / 1.59), losses within the A/A band.
- Full finetuning: auto stays off by rule (forced on was 10.7% faster on
A100, but full-finetune losses are not reproducible enough between two
base runs to check parity, so it is left out).
- torch 2.10: FastLanguageModel LoRA blocks are not compiled before
2.11, so graphs never engage. All 2.10 arms match base within A/A (A100
and L4).
- Recordings after step 5: 0 in every auto-on run (no recapture churn).
- Loss parity: the largest |loss diff| between auto and base over 30
steps is in the same range as base vs base (about 1e-3 for bf16). Runs
are not bitwise identical, and neither are two base runs.
- Memory: when auto turns graphs on, peak reserved goes up by 0.1 to 0.8
GB. When it keeps them off, peak memory is identical to base.
- One-time cost: the graphed region compiles and records at pass 4. With
a cold Inductor cache (Qwen3-0.6B, A100), that step takes 5.1 s, so a
30-step run is 2 s longer in total and the graphs pay for themselves
after about 45 steps. Timing adds one sync and four short GPU sleeps
(about 10 ms each), once.
- `tests/test_block_cudagraphs_gpu.py` (real cudagraph trees, reentrant
checkpointing and gradient accumulation weights match eager) passes on
A100, L4 and T4 with torch 2.14.1, and on A100 and L4 with torch 2.10.0.

## Tests

`tests/test_block_cudagraphs_auto.py` (CPU, fake compile and a stubbed
timer): mode parsing, the on path at a pass boundary, GPU-bound, the
ratio threshold, a shape change while probing, the shape cap after on,
packed rows, low free memory, static rules (torch floor, full
finetuning, distributed), recomputes not counted as passes, explicit off
never probing, a new model deciding again, and the hidden-states forward
hook being installed only where auto can turn graphs on (not on ROCm or
torch < 2.13). These fail on the base commit and pass here.
`test_block_cudagraphs_clone.py`, `test_block_compile.py`,
`test_block_compile_discovery.py`,
`test_legacy_block_compile_install.py` and
`test_attention_dispatch_compiled_block.py` pass, except
`test_sm_count_is_read_outside_the_trace`, which fails the same way on
the base commit.

## Not covered

- torch 2.13 is allowed by the floor but was not measured. Only 2.14.1
was measured with graphs engaged.
- G4 / Blackwell and H100 were not measured.
- Distributed runs, full finetuning and torch < 2.13 keep the old
behaviour (off unless `=1`).
- Models other than Qwen3-0.6B and Llama-3.2-1B were not measured. MoE
and flex attention blocks never use graphs.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 28, 2026
… the block backend compiled (#15777)

### Problem

With `UNSLOTH_BLOCK_CUDAGRAPHS=1`, going past the shape cap turns block
graphs off and releases the cudagraph tree pool via
`reset_cudagraph_trees()`, but only when every tree function belongs to
a block compile (#15352). Ownership was taken as every tree function
created during a graphed block call (`ids_to_funcs` before / after delta
in `_graphed_call`).

A third-party `torch.compile(mode="reduce-overhead")` function that is
first called inside a block (behind a graph break, e.g. through a
`torch.compiler.disable` helper) registers its tree function during that
same call, so it was counted as the block's. Past the cap the release
then reset the shared tree, and the next call of that function failed
with `AssertionError: Running CUDAGraph after shutdown`.

### Change

The graphs-on block compile now uses a subclass of the stock inductor
backend (`torch._TorchCompileInductorWrapper`, same options) that
records `CompileContext.current_compile_id()` for every graph it
compiles. A foreign region compiles through its own backend, so its
compile ids are never recorded. `_graphed_call` only counts new tree
functions whose compile id the block backend recorded; anything else
makes the release verdict "foreign" and the pool is kept, as already
happens for regions created before the first block call. The backward
tree function carries the forward's compile id, so a block-only tree is
still released. If the backend cannot be built, nothing counts as the
block's and the pool is kept. The graphs-off copy and runs without
`UNSLOTH_BLOCK_CUDAGRAPHS=1` are unchanged.

### Tests

`tests/test_block_cudagraphs_clone.py`:
- `test_foreign_function_first_called_inside_a_block_is_not_ours`: a
mocked tree manager gets a block and a foreign tree function during one
`_graphed_call`; only the block one is ours and the verdict is
"foreign". Fails on main.
- `test_block_backend_notes_the_compile_ids_it_builds`,
`test_only_the_graphs_on_compile_gets_the_owning_backend`: the backend
records the compile id and keeps the block options; only the graphs-on
compile gets it.
- `test_graphed_call_records_the_compile_ids_it_created` updated for the
recorded ids.

CPU: `test_block_cudagraphs_clone.py`, `test_block_compile.py`,
`test_block_compile_discovery.py`,
`test_legacy_block_compile_install.py`,
`test_fsdp2_native_block_cudagraphs*_gloo.py`: 138 passed, 6 skipped, 1
failed (`test_sm_count_is_read_outside_the_trace` needs a CUDA device
and fails the same way on main).

GPU (RTX PRO 6000 Blackwell, torch 2.14.1+cu130): one decoder layer
whose forward calls a `reduce-overhead` helper through a
`torch.compiler.disable` boundary, sequence lengths 40, 48, 56 so the
third shape passes the cap of 2:

| | foreign helper inside the block | block only |
| --- | --- | --- |
| main | pool released, then `Running CUDAGraph after shutdown` at step
8 | pool released |
| this change | pool kept, every step and a later standalone helper call
succeed | pool released |

### Not covered

torch 2.7 to 2.13 on GPU were not run (the backend class and
`CompileContext.current_compile_id()` exist across that range). Multi
GPU runs were not run.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 28, 2026
`Repo tests (CPU, fsdp2)` on #15833's staging run passed every test and
still went red:

```
364 passed, 28 skipped, 80 warnings in 2092.29s (0:34:52)
##[error]Process completed with exit code 124.
```

The shard's pytest step runs under `timeout --signal=INT --kill-after=60
2100`. pytest finished 8 s under that cap, and the cap then fired while
it was exiting.

## Cause

#15291 moved the FSDP2 gloo tests into their own shard at about ten
minutes of runner time. They have grown since, with most of a dozen
FSDP2 PRs merged today adding tests there (#15756, #15748, #15720,
#15709, #15708, #15352, ...). Over the last twenty-odd staging runs this
job took 21 to 38 minutes, so it now sits at its cap on an ordinary
runner. Nothing failed; the shard is simply too big for its timeout.

## Fix

Split the shard in two by file name, balanced on measured time. Per-test
durations on main, summed per file across all 76 files:

| shard | selection | files | tests | measured time |
|---|---|---|---|---|
| `fsdp2` | `tests/test_fsdp2_[!n]*.py tests/test_fsdp2_n[!a]*.py
tests/test_fsdp2_native_[abc]*.py` | 34 | 237 | 1156 s (45%) |
| `fsdp2-native` (new) | `tests/test_fsdp2_native_[!abc]*.py` | 42 | 276
| 1406 s (55%) |
| both together, unchanged total | `tests/test_fsdp2*.py` | 76 | 513 |
2562 s |

`fsdp2` keeps its name, so its check name is unchanged. The step timeout
and job cap are left alone, so each half gets the whole budget.

## Guards

- `tests/test_ci_repo_cpu_shards.py` already fails when a file lands in
no shard or in two. It caught my first draft, which dropped
`test_fsdp2_non_cuda_accelerate_route.py`; hence the `n[!a]` glob.
- A new check, `TestEveryGlobRootMatchesAFile`, fails if a shard glob
matches no test file. bash passes an unmatched glob through literally
and pytest then fails the whole shard on a missing path. Sabotage:
adding `tests/test_fsdp2_zz*.py` to a selection fails it with
`[('fsdp2', 'tests/test_fsdp2_zz*.py')]`.
- `tests/studio/test_backend_ci_parallel_isolation.py` pins the number
of parallel runs, now nine (six repo-root shards).

## Verification

- `tests/test_ci_repo_cpu_shards.py` and
`tests/studio/test_backend_ci_parallel_isolation.py`: 56 passed.
- With `tests/studio/test_cache_budget_discipline.py` added: everything
passes except the guard on my first draft, fixed above.
- `--collect-only` on the two selections gives 237 + 276 = 513, the same
as the old single glob.

The per-file times are from a local `-n 8` run, so the split ratio is
approximate. The first runs of the two new shards will show the actual
runner times.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 23, 2026
…AGRAPHS_DDP=1, -20% to -27% step on 2xT4) (unslothai#18873)

## Problem

Auto mode for block CUDA graphs (unslothai#15768) never turns graphs on when a
process group has more than one rank. `_auto_static_reason` returns
`"distributed"` for any initialized group with world > 1. The rule was
written as a precaution and never measured. The only multi-GPU number on
record is the forced-graphs DDP matrix in unslothai#15352, which ran 1,024-token
rows with checkpointing on a T4 and came out a tie (1478 / 1490 / 1486
ms). That step is GPU-bound, and auto mode's own probe already keeps
graphs off for that case on one GPU. Launch-bound DDP runs, such as
small models with short padded rows, lose the 1-GPU gain.

## Change

Auto mode may now turn graphs on under **plain DDP over every rank**:
block weights are replicated and no collective runs inside a block.

- Every rank probes exactly as on one GPU: shape, packed rows,
non-reentrant checkpointing, MoE, flex, launch / GPU ratio and free
memory. Each rank then publishes its verdict (`on`, or `off:<why>`) to
the process group's store.
- A rank switches graphs on, at a forward-pass boundary, only once
**every** rank published `on`. Any `off` keeps graphs off on every rank,
with the reason naming the rank, for example `rank 1: batch shape
changed`. So does no full set of verdicts within
`UNSLOTH_BLOCK_CUDAGRAPHS_AGREE_TIMEOUT` seconds (default 120).
- No collective is issued, only store `set` / `check` / `get`. A rank
that turned off early, or never reaches a block call, cannot hang the
others or interleave with DDP's gradient all-reduce.
- Graphs stay off as before for:
  - FSDP2 / tensor parallel (DTensor block weights),
  - DDP over a sub-group (pipeline or TP x DP),
  - context parallel (`get_cp_manager()` is active),
- a process group with no DDP forward around the block
(`DistributedDataParallel._get_active_ddp_module()` is None),
  - a block outside the DDP module,
  - no store.

Full finetuning, ROCm and torch < 2.13 keep their existing rules.
`UNSLOTH_BLOCK_CUDAGRAPHS=0` / `=1` keep their meaning.
- The "graphs on" notice prints on rank 0 once every rank agreed, with
`(every rank agreed)` appended.
- Gradient flow is unchanged. The existing first-write `.grad` clone
(`_param_grads_out_of_pool`) runs as a tensor hook, before DDP's
post-accumulate bucket hook, so buckets never read graph pool memory.
Under `no_sync`, gradients accumulate into the cloned `.grad` as on one
GPU.

## Kaggle 2x T4 A/B (2 ranks, torch 2.14.1, fp16)

Setup:

- Model: Qwen3-0.6B, LoRA r16 on all linear layers,
`use_gradient_checkpointing = "unsloth"`, 1 row per rank, `max_length`
512, `padding_free = False`, adamw_8bit.
- Base = `main` (f5dfe68) as installed. Head = the same install with
this branch's `_block_compile.py`. Every arm checks which tree it
imported.
- Arms run base, head, head, base, each a fresh `torchrun` with a fresh
compile cache, so each side has its own A/A pair.
- Step time = mean over ranks of the median steady step. GA 1: 60 steps,
first 15 dropped. GA 4: 30 steps, first 8 dropped. Variable-length
cells: 40 / 20 steps, rows of uniform random length in 128-512.

| cell | base s/step | head s/step | delta | A/A base / head | auto on
head (both ranks) | graphs built per rank | peak alloc / reserved GiB,
base to head |
|---|---|---|---|---|---|---|---|
| 16-bit LoRA, GA 1, padded | 0.2353 | 0.1765 | **-25.0%** | 0.2% / 2.2%
| on (ratio 2.1-2.6) | 2 | 1.56 / 1.59 to 1.61 / 1.72 |
| 16-bit LoRA, GA 4, padded | 0.8156 | 0.6700 | **-17.9%** | 2.3% / 0.1%
| on (ratio 1.95-2.0) | 2 | 1.60 / 1.62 to 1.65 / 1.74 |
| QLoRA, GA 1, padded | 0.3419 | 0.2168 | **-36.6%** | 1.8% / 5.6% | on
(ratio 2.8-3.2) | 8 | 0.99 / 1.03 to 1.03 / 1.16 |
| QLoRA, GA 4, padded | 1.2243 | 0.7998 | **-34.7%** | 2.5% / 2.1% | on
(ratio 2.7-3.0) | 8 | 1.02 / 1.06 to 1.07 / 1.18 |
| 16-bit LoRA, GA 1, variable length | 0.2482 | 0.2443 | -1.6% | 6.5% /
1.4% | off, `batch shape changed` | 0 | unchanged |
| 16-bit LoRA, GA 4, variable length | 0.8362 | 0.8632 | +3.2% | 0.5% /
4.7% | off, `batch shape changed` | 0 | unchanged |
| QLoRA, GA 1, variable length | 0.3509 | 0.3459 | -1.4% | 0.2% / 0.3% |
off, `batch shape changed` | 0 | unchanged |
| QLoRA, GA 4, variable length | 1.2773 | 1.2865 | +0.7% | 0.9% / 5.8% |
off, `batch shape changed` | 0 | unchanged |

Base reported `distributed` on both ranks in every cell.

- **Where graphs engage** (fixed-shape padded rows), the step is 17.9%
to 36.6% faster, above the A/A spread plus 5% in all four cells. Both
ranks report phase `on`, and rank 0 printed the `(every rank agreed)`
notice. The graph count is the same at GA 1 (60 steps) and GA 4 (30
steps), so nothing re-records per step. Cost: +0.04 to +0.05 GiB peak
allocated and +0.12 to +0.13 GiB peak reserved per rank.
- **Variable-length rows**: both ranks turn off at the second forward
pass, before anything is timed or recorded, and 0 graphs are built. The
head deltas sit inside the A/A spread of the noisier side. The +3.2%
cell comes from one head arm, 0.8812 / 0.8857 s on its two ranks; the
other head arm ran 0.8428 / 0.8431 s, +0.8% against the base mean. After
that pass the head code path is the base path plus one store write, so I
read it as T4 drift, not a cost.
- **Losses**: no pair of runs is bitwise equal, base against base
included, so the check is against that run-to-run spread. Max |diff| of
logged losses, base against head, stayed inside the run-to-run band in
every cell:

| cell | base vs base | head vs head | base vs head, closest pair | base
vs head, worst pair |
  |---|---|---|---|---|
  | 16-bit LoRA, GA 1, padded | 6.8e-4 | 2.5e-3 | 4.6e-4 | 2.2e-3 |
  | QLoRA, GA 1, padded | 1.4e-3 | - | - | 1.1e-3 |
  | the other six cells | 2.1e-4 to 7.8e-4 | - | - | 2.0e-4 to 8.2e-4 |

Mean loss over 60 steps (16-bit LoRA, GA 1, padded): 3.00858 / 3.00870
base, 3.00869 / 3.00855 head.
- **One-off cost**: the graphed region is compiled and recorded once at
the switch, as on one GPU. Whole-run wall time for these short runs,
base to head:
  - 16-bit LoRA, GA 1: 33.9 / 29.1 s to 36.5 / 33.1 s (60 steps).
  - QLoRA, GA 1: 77.2 / 59.1 s to 94.7 / 81.1 s (60 steps).

The per-step saving pays this back after roughly 60 to 150 steps on
these shapes. unslothai#15768 measured the same one-off cost (about 5 s,
break-even about 45 steps on one A100).

## Tests

`tests/test_block_cudagraphs_auto_ddp_gloo.py` (new, CPU, gloo world 2,
real DDP and the real store; compile and timing stubbed as in
`test_block_cudagraphs_auto.py`):

- A process group without a DDP forward keeps graphs off (`distributed,
not DDP`).
- Under DDP both ranks turn graphs on at the same step.
- One GPU-bound rank keeps graphs off on both ranks (`rank 1: GPU-bound
...`).
- A batch shape change on one rank keeps graphs off on both (`rank 1:
batch shape changed`).
- A rank that never decides makes the other time out to off instead of
waiting.

All 5 fail on `main`: every case reports `distributed`, and in the
timeout case rank 0 turns graphs on alone. All 5 pass here.
`test_block_compile*.py`, `test_block_cudagraphs*.py` and
`test_fsdp2_native_block_cudagraphs_gloo.py`: 191 passed, 29 skipped on
this branch. On `main` the only failures are the 5 new tests.

## Not covered

- Only Kaggle 2x T4, one model (Qwen3-0.6B) and one row shape (1 x 512).
No L4 / A100 / H100 multi-GPU run, no 4+ rank run, no bf16 run.
- FSDP2, tensor, pipeline and context parallel are deliberately
unchanged. No timing for them here.
- A rank that turns off after the others already read an all-`on` set (a
shape change exactly at the switch pass) leaves graphs on for the others
only. The math is still correct, since DDP averages the same gradients,
but that run gains nothing. Covered by reasoning, not by a test.
- torch 2.13 under DDP was not run; only 2.14.1.
- GPU-bound DDP shapes (long rows), where auto should report `GPU-bound`
on every rank, were not run in this A/B. They are covered by the 1-GPU
probe and the CPU test.


## Update (7d28175): one collective per agreement point

The rank agreement no longer polls the TCP store. The first eager block
call inside a DDP forward attaches a forward pre-hook to that DDP
wrapper. On grad-synced DDP forwards only (which DDP already requires
every rank to run), the hook runs one eager `all_reduce(MIN)` on the DDP
process group carrying each rank's state (off / probing / ready) and its
vote count. Graphs turn on only from that result, so every rank switches
in the same forward; any veto or a count mismatch turns them off
everywhere.

- Later rank-local fallbacks (packed rows, the shape cap, a failed graph
compile, a block called outside the DDP module, context parallel) turn
graphs off on that rank at once, and the other ranks follow at the next
check (1, 2, 4, ... up to every 64 synced forwards).
- Ownership, DTensor weights and context parallel (Unsloth's and torch's
native `context_parallel()`) are checked on every block call, including
the fast path. FSDP2 modules, DTensor parameters and sub-group DDP are
refused at enrollment.
- `DDP.join()`, `torch.compile` around the DDP model, a rank still
probing after 64 synced forwards, and graphs enabled before the process
group existed all keep graphs off on every rank.
- The store keys, round keys, deadlines and
`UNSLOTH_BLOCK_CUDAGRAPHS_AGREE_TIMEOUT` are gone.
`UNSLOTH_BLOCK_CUDAGRAPHS_DDP=0` turns the DDP path off.
- Test workers drop inherited `UNSLOTH_*` settings and use
`tests._rendezvous_port.free_port`.

Tests (CPU gloo, world 2): the new test file has 11 tests; 7 fail on the
previous store protocol (ranks switching at different steps under
`no_sync()`, a late shape-cap veto ignored by the peer, a block outside
the DDP module, context parallel turned on late, a probe before the
process group, `join()` with uneven inputs, a rank that never finishes
probing) and all 11 pass now. The block-compile and CUDA-graph suites
give 229 passed, 30 skipped (GPU).

Kaggle 2xT4, Qwen3-0.6B 16-bit LoRA, 1 x 512 padded rows, base = merge
base, each side run twice:

| | base s/step | head s/step | change | A/A base / head | peak reserved
GiB, base -> head |
|---|---|---|---|---|---|
| GA 1 | 0.2443 | 0.1859 | -23.9% | 2.7% / 1.2% | 1.59 -> 1.72 |
| GA 4 | 0.8615 | 0.7014 | -18.6% | 3.1% / 1.5% | 1.62 -> 1.74 |

Both ranks report graphs on with identical vote counts. Loss differences
base vs head (1.9e-3 at GA 1, 2.5e-4 at GA 4) are within the earlier
run-to-run spread.

## Update (9f3544537): DDP path is opt-in, enrollment at DDP
construction, join pauses the vote

Default under DDP is back to what main does: any process group keeps
block CUDA graphs off, `DistributedDataParallel` is not touched, no hook
is registered and no collective is added. Set
`UNSLOTH_BLOCK_CUDAGRAPHS_DDP=1` (the same on every rank, before Unsloth
loads a model) to turn the agreement on. Single-GPU auto mode is
unchanged.

With the variable set:

- Every DDP wrapper is enrolled right after it is built, on every rank
(the constructor already runs collectives on every rank). Before, a rank
enrolled at its first eager block call, so a rank-local first forward
(an eval pass on rank 0, an extra `no_sync()` microbatch) made one rank
vote a forward earlier than the other and aborted the collective.
- The hook sits on `ddp.module`, so it runs inside the DDP forward after
DDP's own pre-forward collectives (bucket rebuild, buffer broadcast,
join notification).
- Under `DDP.join()` no vote is taken and the vote count stands still on
every rank, so ranks with different numbers of inputs leave the window
on the same schedule. A rank that runs a forward inside the window turns
its graphs off, and the first vote after the window turns them off
everywhere.
- Local refusals (graphs mode not auto, block compile disabled, no
compiled blocks, not CUDA, platform, `torch.compile` inside or around
the DDP wrapper, FSDP2 / DTensor) are sent as votes of 0. A rank never
skips a vote.
- The vote tensor sits on the module's own GPU for NCCL (not the current
device, which can be another rank's GPU when `device_ids=None`) and on
the CPU for gloo.
- A session replaced by a newer model or a re-wrap votes 0 without
touching the new state. A DDP veto is cleared for the next model once
its graph pool is released.
- Graph pool release on every veto path (compiled and stock calls),
ownership checks for stock calls, DTensor checks repeated when a block's
parameters change, checkpoint recomputes use graphs only after a forward
in the owning DDP forward, `BackendCompilerFailed` subclasses
(`InductorError`) fall back to plain blocks under DDP, a late
gradient-carrying side input and a new shape at the switch both veto.

Tests (CPU, gloo, 2 ranks):
`tests/test_block_cudagraphs_auto_ddp_gloo.py` has 15 tests. Against the
previous commit, 5 fail: the default run issues votes and turns graphs
on; a rank-local eval forward first and a rank-local `no_sync()`
microbatch first abort with a gloo collective mismatch (SIGABRT); an
uneven `join()` window after graphs are on aborts the same way; a
persistent context-parallel veto never releases the graph pool. All 15
pass now, also with `UNSLOTH_COMPILE_DISABLE=1
UNSLOTH_BLOCK_CUDAGRAPHS=1` in the parent environment. The default-off
test also passes on the merge base. Block compile, CUDA graph and FSDP2
block suites: 361 passed, 39 skipped.

Kaggle 2x T4, Qwen3-0.6B 16-bit LoRA, 1 x 512 padded rows, seconds per
step (median of both ranks), merge base vs this commit. Two sessions,
each arm run twice in the same session:

| | base | `UNSLOTH_BLOCK_CUDAGRAPHS_DDP=1` | change | unset | change |
A/A spread base / on / unset |
|---|---|---|---|---|---|---|
| Session 1, GA 1 | 0.2418 | 0.1920 | -20.6% | 0.2398 | -0.8% | 0.9% /
3.3% / 2.5% |
| Session 1, GA 4 | 0.8264 | 0.7253 | -12.2% | 0.8356 | +1.1% | 1.0% /
0.4% / 4.0% |
| Session 2, GA 1 | 0.2457 | 0.1795 | -26.9% | | | 1.5% / 1.0% |
| Session 2, GA 4 | 0.8382 | 0.6679 | -20.3% | | | 2.0% / 0.3% |

Session 2 also ran the previous commit in the same session: 0.1793 (GA
1) and 0.6664 (GA 4) s/step, within 0.2% of this commit. So the new
checks cost nothing measurable, and the GA 4 gap in session 1 comes from
that machine. On a CPU microbenchmark the per-call check went from 0.7
to 1.7 us, under 1 ms per GA 4 step.

With the variable set, both ranks report graphs on, the same vote count
(GA 1: 9, GA 4: 5) and the same schedule. Peak reserved memory per rank
goes from 1.59 to 1.72 GiB (GA 1) and from 1.62 to 1.74 GiB (GA 4). With
it unset, every rank reports graphs off for `distributed` (main's
reason), 0 Unsloth collectives, an unpatched
`DistributedDataParallel.__init__`, the same reserved memory as base,
and step times within the base A/A spread. Final losses match base to
within the run-to-run spread (largest difference 2e-4).

Not covered: NCCL with `device_ids=None` (the vote device is checked on
CPU only), QLoRA, variable-length rows, more than 2 ranks, GPUs other
than T4.



## GPU check at the current head

Kaggle 2x T4 at the current head 8cf9916, NCCL: the one-rank
`ddp.module.compile()` repro hits the 200 s NCCL watchdog at 82a391d
and completes 4 steps here with both ranks agreeing graphs off. Plain
LoRA with `UNSLOTH_BLOCK_CUDAGRAPHS_DDP=1`: graphs engage on every run
(2 graphs, 9 votes per rank, every rank agreed), step 0.2076 -> 0.1737 s
(-16.3%, three interleaved pairs, A/A 1.6% / 1.1%), peak 1.646 -> 1.665
GiB.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant