trainstream 0.7.0__tar.gz → 0.8.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {trainstream-0.7.0/trainstream.egg-info → trainstream-0.8.1}/PKG-INFO +163 -65
- {trainstream-0.7.0 → trainstream-0.8.1}/README.md +162 -64
- {trainstream-0.7.0 → trainstream-0.8.1}/setup.py +16 -2
- trainstream-0.8.1/tests/test_aio.py +219 -0
- trainstream-0.8.1/tests/test_checkpoint.py +270 -0
- trainstream-0.8.1/tests/test_embed.py +115 -0
- trainstream-0.8.1/tests/test_experts.py +254 -0
- trainstream-0.8.1/tests/test_fp8_grads.py +200 -0
- trainstream-0.8.1/tests/test_gemm.py +347 -0
- trainstream-0.8.1/tests/test_guard.py +357 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_huggingface.py +53 -0
- trainstream-0.8.1/tests/test_lora_fused.py +205 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_offload.py +21 -1
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_optimizer.py +3 -3
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_paging.py +7 -4
- trainstream-0.8.1/tests/test_pissa.py +308 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_planner.py +10 -5
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_recompute.py +3 -1
- trainstream-0.8.1/tests/test_ring.py +163 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/__init__.py +8 -2
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/_build.py +62 -24
- trainstream-0.8.1/trainstream/checkpoint.py +385 -0
- trainstream-0.8.1/trainstream/csrc/aio.cpp +725 -0
- trainstream-0.8.1/trainstream/csrc/aio.h +111 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/bindings.cpp +97 -1
- trainstream-0.8.1/trainstream/csrc/ckpt.cpp +198 -0
- trainstream-0.8.1/trainstream/csrc/disk.cpp +359 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/fused.cpp +106 -4
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/fused_kernel.cu +69 -17
- trainstream-0.8.1/trainstream/csrc/gemm_fp4_kernel.cu +405 -0
- trainstream-0.8.1/trainstream/csrc/guard.cpp +103 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/kernels.h +75 -7
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/memory_pinner.cpp +39 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/offload_adamw.cpp +401 -37
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/offload_adamw.h +140 -1
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/offload_adamw_kernel.cu +91 -10
- trainstream-0.8.1/trainstream/csrc/ring.cpp +290 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/trainstream.h +101 -0
- trainstream-0.8.1/trainstream/disk.py +121 -0
- trainstream-0.8.1/trainstream/embed.py +107 -0
- trainstream-0.8.1/trainstream/experts.py +474 -0
- trainstream-0.8.1/trainstream/fused.py +555 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/hooks.py +139 -15
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/integrations/huggingface.py +115 -7
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/lora.py +55 -10
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/optimizer.py +188 -13
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/paging.py +99 -12
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/quant.py +277 -23
- trainstream-0.8.1/trainstream/ring.py +160 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/wrapper.py +381 -36
- {trainstream-0.7.0 → trainstream-0.8.1/trainstream.egg-info}/PKG-INFO +163 -65
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream.egg-info/SOURCES.txt +18 -0
- trainstream-0.7.0/tests/test_experts.py +0 -75
- trainstream-0.7.0/tests/test_lora_fused.py +0 -111
- trainstream-0.7.0/trainstream/disk.py +0 -60
- trainstream-0.7.0/trainstream/experts.py +0 -136
- trainstream-0.7.0/trainstream/fused.py +0 -301
- {trainstream-0.7.0 → trainstream-0.8.1}/LICENSE +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/MANIFEST.in +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/NOTICE +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/build.bat +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/pyproject.toml +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/setup.cfg +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_arena.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_attention.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_distributed.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_dpo.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_features.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_fused.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_kvcache.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_lowp.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_multigpu.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_outliers.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_packing.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_peer.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_quality_options.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/tests/test_quant.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/attention.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/peer.cpp +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/quant.cpp +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/quant_kernel.cu +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/csrc/shm.cpp +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/integrations/__init__.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/kvcache.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/losses.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/lowp.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/packing.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/peer.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/planner.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/profiler.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream/shared.py +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream.egg-info/dependency_links.txt +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream.egg-info/not-zip-safe +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream.egg-info/requires.txt +0 -0
- {trainstream-0.7.0 → trainstream-0.8.1}/trainstream.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trainstream
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.1
|
|
4
4
|
Summary: Zero-dependency PyTorch training offload: optimizer, gradients, activations and weights to host RAM, with a memory planner and built-in int8/NF4/FP8/NVFP4 quantization.
|
|
5
5
|
Home-page: https://github.com/johnanishg/TrainStream
|
|
6
6
|
Author: John Anish G
|
|
@@ -49,6 +49,57 @@ model, optimizer = trainstream.wrap(model, optimizer)
|
|
|
49
49
|
|
|
50
50
|
TrainStream is a C++/CUDA extension for PyTorch. It uses only the C++ standard library, the CUDA runtime and PyTorch's ATen: no DeepSpeed, no bitsandbytes. Updates match `torch.optim.AdamW` (max parameter difference ≈3·10⁻⁷ after 20 steps), and activation and weight paging are bit-exact.
|
|
51
51
|
|
|
52
|
+
## What's new in 0.8.1
|
|
53
|
+
|
|
54
|
+
Measured in the full check of 30 November 2026 on an RTX 5090 Laptop GPU (24 GB), in WSL2 (49 GB VM) and on Windows 11 (64 GB), against the 0.8.0 check of 23 November. All 465 tests pass on Windows and in WSL (from a wheel installed with pip and with uv), and perplexity before fine-tuning is the same as 0.8.0's in every format.
|
|
55
|
+
|
|
56
|
+
- **The input embedding moves to host RAM before any layer does** (`embed_offload="auto"`). A frozen input embedding is a lookup table: a step reads only its batch's rows (5 MB of Qwen2.5-14B's 1.45 GiB at 512 tokens). When the memory plan would stream transformer blocks from RAM, the table now goes to pinned host RAM instead, and a kernel reads the rows it needs straight from there (zero-copy, on the GPU's own stream, so nothing waits for the host). The output is the same bits. The VRAM it frees holds more blocks:
|
|
57
|
+
|
|
58
|
+
| Qwen2.5-14B LoRA | WSL, 0.8.0 → 0.8.1 | Windows, 0.8.0 → 0.8.1 | blocks in VRAM |
|
|
59
|
+
|---|---|---|---|
|
|
60
|
+
| NF4 base, 1 × 512, 12 GB of VRAM | 0.779 → 0.743 s | 0.730 → 0.710 s | 36–37 → 46–47 of 48 |
|
|
61
|
+
| NVFP4 base, 1 × 512, 12 GB of VRAM | 0.657 → 0.630 s | 0.569 → 0.670 s (see below) | 37 → 48 |
|
|
62
|
+
| `"auto"` (bf16 base), 1 × 512 | 0.968 → 0.838 s | 0.982 → 0.895 s | 28 → 31 |
|
|
63
|
+
| `"auto"`, 1 × 2,048 | 3.04 → 2.84 s | 3.04 → 2.82 s | 23–24 → 25–26 |
|
|
64
|
+
| `"auto"`, 1 × 512, 12 GB of VRAM | 2.13 → 1.89 s | 1.60 → 1.50 s | 9–10 → 12–13 |
|
|
65
|
+
| `"auto"`, 2 × 2,048 packed | 6.76 → 6.43 s | 6.75 → 6.61 s | 22 → 25 |
|
|
66
|
+
|
|
67
|
+
On Windows the GPU ran at a lower clock in this check than in 0.8.0's, for every engine: bitsandbytes was 9 % slower too, and in the uncapped NVFP4 run, which this change doesn't touch, the same FP4 matmuls took 391 ms per step against 258 ms (1,417 MHz against 2,400 MHz). Alternating runs with the option on and off in one session are the cleaner comparison there: NVFP4 base under the 12 GB cap 0.700 / 0.699 / 0.703 s → 0.669 / 0.671 / 0.670 s (4 % faster, 30 November); NF4 base 0.759 / 0.758 s → 0.681 / 0.686 s (10 % faster, 23 November).
|
|
68
|
+
|
|
69
|
+
Against Unsloth held to 12 GB of VRAM (WSL, 3 runs each): TrainStream's NF4 base takes 0.743 s against Unsloth's 0.685 s, so Unsloth is still 1.08× faster (1.10× in 0.8.0); the NVFP4 base stays ahead, 0.630 s (1.09×). Where everything already fits in VRAM (the 4-bit bases without a cap) the option doesn't engage and nothing changes. `embed_offload=False` keeps 0.8.0's behaviour.
|
|
70
|
+
|
|
71
|
+
## What's new in 0.8
|
|
72
|
+
|
|
73
|
+
Measured in the full check of 23 November 2026 on an RTX 5090 Laptop GPU (24 GB), in WSL2 (49 GB VM) and on Windows 11 (64 GB), with the non-finite guard on (the new default). Every number is in the tables below.
|
|
74
|
+
|
|
75
|
+
- **Speed against other libraries**, Qwen2.5-14B LoRA, TrainStream against the fastest rival that trains the same adapters:
|
|
76
|
+
- NVFP4 base: 1.27× bitsandbytes at 512 tokens (WSL; 1.45× on Windows), 1.79× Unsloth at 2,048 tokens (2.13× bitsandbytes with checkpointing on Windows), 1.62× bitsandbytes + Liger on packed documents (1.77× bitsandbytes with checkpointing on Windows), and 1.08× Unsloth held to 12 GB of VRAM.
|
|
77
|
+
- NF4 base, the format bitsandbytes and Unsloth use: 1.05× bitsandbytes at 512 tokens (1.09× on Windows), 1.25× Unsloth at 2,048 tokens, 1.09× bitsandbytes + Liger on packed documents (1.23× bitsandbytes with checkpointing on Windows).
|
|
78
|
+
- Held to 12 GB of VRAM, Unsloth is 1.10× faster than TrainStream's NF4 base (0.711 s against 0.779 s, three runs each; in 0.7's check they were level). TrainStream streams 12 of the 48 4-bit layers from RAM there, where Unsloth keeps them all in VRAM.
|
|
79
|
+
- **Non-finite guard** (`nan_guard`, on by default). A step whose gradients hold a NaN or Inf is skipped as a whole: weights, moments and step counts stay exactly as they were, the gradients are dropped and training continues with the next batch. The fused kernels flag where a bad value first appeared. It needs every gradient of a step before any update runs, so eager updates are off while it is on, and each trained value keeps a 4-byte host accumulator. (Before it, a NaN gradient norm also silently disabled clipping.)
|
|
80
|
+
- **PiSSA** (`lora_init="pissa"`). LoRA adapters start at their base weight's principal part (one randomized SVD each) and the base stores the rest, quantized. `trainstream.pissa_to_lora` turns a trained adapter into an ordinary LoRA for the original weights. A PiSSA adapter holds the weight's largest directions, so the same learning rate moves the model much further than it does a zero-started LoRA: train it at about 2e-5. At 2e-5 it was the best 4-bit option measured, after LoRA against bf16 at the same learning rate: NF4 +1.94 % against +3.04 % without PiSSA on Qwen2.5-14B, +4.57 % against +5.64 % on 1.5B; NVFP4 +4.03 % against +5.23 %, and +8.81 % against +10.59 %. All four gains were larger than the run-to-run variation, and the NF4 ones repeated in four runs. At 2e-4 PiSSA ended worse than plain NF4 (+24 % against +5 % on 1.5B), so `wrap()` warns when PiSSA adapters train above 3e-5.
|
|
81
|
+
- **`load_model` refuses a model larger than RAM** (`check_memory=True`). It adds up what the quantized model will take before reading a byte and raises `MemoryError` if that exceeds the available RAM, saying whether the model is larger than RAM and VRAM together, and listing the options (a smaller format, `disk_offload=`, `check_memory=False`). Before, such a model loaded into the OS page file on the SSD.
|
|
82
|
+
- **Disk tier without page faults.** `disk_offload` weights are read with asynchronous unbuffered I/O (an I/O completion port on Windows, io_uring through raw system calls on Linux, a thread pool as fallback) into pinned staging memory ahead of the layer that needs them, and copied to the GPU on a stream that waits for the read itself. Nothing passes through the OS page cache or blocks the training thread. The weights are written once and only read after that. Covered by tests, not benchmarked.
|
|
83
|
+
- **Background checkpoints** (`trainstream.save_checkpoint`, `TrainStreamTrainer` `async_checkpoint`). The optimizer state is written by a detached thread straight from the host buffers while training goes on; a resumed run continues bit for bit.
|
|
84
|
+
- **LoRA backward on a partly arrived input** (`lora_chunks`). A large paged activation returns in pieces; an adapter's weight gradient is summed piece by piece when its input is still crossing PCIe.
|
|
85
|
+
- **MoE expert paging** (`moe_cache`, `moe_capacity`). One look at the routing per layer, every needed expert queued on the copy stream before the first computes, a VRAM cache, exact prefetch in backward and guessed prefetch of the next layer in forward; results stay bit-identical. `moe_capacity` (off by default) bounds the copies per layer by re-routing tokens, which changes the model's output. Also fixed: the memory plan counted experts held in host RAM as resident, so a MoE larger than VRAM was refused. Covered by tests, not benchmarked on a real MoE model.
|
|
86
|
+
- **FP8 gradient transport** (`fp8_gradients`, opt-in). Gradients cross PCIe as one e4m3 byte per value with stochastic rounding: half the traffic of bf16 gradients, a quarter of fp32.
|
|
87
|
+
- **Ring all-reduce** (`distributed_backend`). Data-parallel ranks on different machines sum gradients around a TCP ring; every rank ends with the same bits. Tested with three processes on one machine, not across machines.
|
|
88
|
+
- **Gated MLP front** (`mlp_recompute`, `fused_gemm`). A gated MLP can keep its input for backward instead of its two [tokens, intermediate] projection outputs, and run the projections again there: the same bits, a third fewer activation bytes per layer. `"auto"` (the default) does it for tensor-core MLPs in blocks whose activations are paged to host RAM. `fused_gemm=True` computes the front in one hand-written FP4 tensor-core kernel (products, LoRA terms and activation accumulated in registers; PTX, no CUTLASS); it is correct but slower than cuBLAS, so it is off by default.
|
|
89
|
+
|
|
90
|
+
Measured on Qwen2.5-14B, NVFP4 base, LoRA r=16, RTX 5090 Laptop GPU (24 GB), Windows 11, 10 steps each after warm-up, median step time (targeted runs of `benchmarks/compare.py`'s `trainstream_nvfp4` engine, 13 November 2026; run-to-run spread on this machine is about 5 %):
|
|
91
|
+
|
|
92
|
+
| Scenario | gate / up kept (`mlp_recompute=False`) | `"auto"` | `fused_gemm=True` |
|
|
93
|
+
|---|---|---|---|
|
|
94
|
+
| 1 x 2,048 tokens, every block's activations paged (`activation_offload=True, recompute=False`) | 2.08 s, 14.2 GiB paged per step | 1.67 s, 9.3 GiB paged per step | not run |
|
|
95
|
+
| 1 x 2,048 tokens, defaults (blocks recomputed, none paged) | 1.44 s | off (identical path) | 1.44 s |
|
|
96
|
+
| 2 x 2,048 tokens packed, defaults | 3.77 s | off (identical path) | 3.76 s |
|
|
97
|
+
| 1 x 512 tokens, 12 GB cap, defaults | 0.75 s | off (identical path) | 0.74 s |
|
|
98
|
+
|
|
99
|
+
So the recompute pays where activations cross PCIe (19 % faster there) and the fused kernel pays nowhere measured: per MLP front at 4,096 tokens it takes 4.3 ms against 4.1 ms for cuBLAS's two FP4 matmuls plus the LoRA and activation passes (cuBLAS's FP4 matmul runs at 228 T multiply-adds/s, this kernel at 137). With defaults this machine never pages activations in these scenarios (recomputing whole blocks measured faster), so `"auto"` stays off in them.
|
|
100
|
+
|
|
101
|
+
Not in this release: LoRA weight-gradient matmuls on FP8 tensor cores.
|
|
102
|
+
|
|
52
103
|
## What's new in 0.7
|
|
53
104
|
|
|
54
105
|
Measured in the full check of 11 November 2026 on an RTX 5090 Laptop GPU (24 GB), in WSL2 (49 GB VM) and on Windows 11 (64 GB). Every number is in the tables below.
|
|
@@ -130,52 +181,52 @@ Measured in the full check of 11 November 2026 on an RTX 5090 Laptop GPU (24 GB)
|
|
|
130
181
|
|
|
131
182
|
## Against other libraries (same laptop: WSL2 with a 49 GB VM, then Windows 11 with 64 GB)
|
|
132
183
|
|
|
133
|
-
> TrainStream 0.
|
|
184
|
+
> TrainStream 0.8.1, full check of 30 November 2026. Each engine runs in a fresh process, 10 steps after its warm-up (TrainStream: after it has finished tuning itself), and its step time is the median of those. Where two compared engines were within 10 %, both ran 3 times and the median run counts; a win counts only when the gap is wider than the runs' spread. Every engine listed finished all its steps. Between full checks the laptop's speed moves by 5–10 % for every engine alike (on Windows this check ran at a lower GPU clock than 0.8.0's, for bitsandbytes as much as for TrainStream), so read smaller differences as noise.
|
|
134
185
|
|
|
135
186
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512 (WSL2)**
|
|
136
187
|
|
|
137
188
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
138
189
|
|---|---|---|---|
|
|
139
|
-
| TrainStream, NVFP4 base (FP4 tensor cores) | 0.
|
|
140
|
-
| TrainStream, NF4 base | 0.
|
|
141
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
142
|
-
| Unsloth (4-bit) | 0.
|
|
143
|
-
| bitsandbytes QLoRA + Liger kernels | 0.
|
|
144
|
-
|
|
|
145
|
-
|
|
|
190
|
+
| TrainStream, NVFP4 base (FP4 tensor cores) | 0.451 s | 16.8 GB | fastest |
|
|
191
|
+
| TrainStream, NF4 base | 0.537 s (3 runs: 0.536–0.541) | 16.8 GB | 1.19× |
|
|
192
|
+
| bitsandbytes QLoRA (NF4) + PEFT | 0.570 s (3 runs: 0.550–0.571) | 17.4 GB | 1.26× |
|
|
193
|
+
| Unsloth (4-bit) | 0.691 s | 11.5 GB | 1.53× |
|
|
194
|
+
| bitsandbytes QLoRA + Liger kernels | 0.787 s | 12.0 GB | 1.74× |
|
|
195
|
+
| TrainStream (auto: exact bf16 base, 17 of 48 layers streamed) | 0.838 s | 21.5 GB | 1.86× |
|
|
196
|
+
| bitsandbytes QLoRA + gradient checkpointing | 0.843 s | 12.7 GB | 1.87× |
|
|
146
197
|
|
|
147
198
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 2048 (WSL2)**
|
|
148
199
|
|
|
149
200
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
150
201
|
|---|---|---|---|
|
|
151
|
-
| TrainStream, NVFP4 base | 1.
|
|
152
|
-
| TrainStream, NF4 base |
|
|
153
|
-
| Unsloth (4-bit) | 2.
|
|
154
|
-
| bitsandbytes QLoRA + Liger kernels | 2.
|
|
155
|
-
| bitsandbytes QLoRA + gradient checkpointing |
|
|
156
|
-
| TrainStream (auto) |
|
|
202
|
+
| TrainStream, NVFP4 base | 1.32 s | 21.2 GB | fastest |
|
|
203
|
+
| TrainStream, NF4 base | 1.91 s | 19.2 GB | 1.45× |
|
|
204
|
+
| Unsloth (4-bit) | 2.46 s | 11.7 GB | 1.87× |
|
|
205
|
+
| bitsandbytes QLoRA + Liger kernels | 2.52 s | 13.0 GB | 1.91× |
|
|
206
|
+
| bitsandbytes QLoRA + gradient checkpointing | 2.69 s | 16.3 GB | 2.04× |
|
|
207
|
+
| TrainStream (auto) | 2.84 s | 22.6 GB | 2.15× |
|
|
157
208
|
|
|
158
209
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512, every engine held to 12 GB of VRAM (WSL2)**
|
|
159
210
|
|
|
160
211
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
161
212
|
|---|---|---|---|
|
|
162
|
-
|
|
|
163
|
-
|
|
|
164
|
-
| TrainStream,
|
|
165
|
-
| bitsandbytes QLoRA + Liger kernels | 0.
|
|
166
|
-
| TrainStream (auto) |
|
|
213
|
+
| TrainStream, NVFP4 base | 0.630 s (3 runs: 0.627–0.646) | 11.8 GB | fastest |
|
|
214
|
+
| Unsloth (4-bit) | 0.685 s (3 runs: 0.683–0.687) | 11.4 GB | 1.09× |
|
|
215
|
+
| TrainStream, NF4 base | 0.743 s (3 runs: 0.735–0.747) | 11.5 GB | 1.18× |
|
|
216
|
+
| bitsandbytes QLoRA + Liger kernels | 0.805 s | 12.0 GB | 1.28× |
|
|
217
|
+
| TrainStream (auto) | 1.89 s | 11.8 GB | 2.99× |
|
|
167
218
|
|
|
168
|
-
bitsandbytes QLoRA, with or without gradient checkpointing, ran out of memory under the 12 GB cap.
|
|
219
|
+
bitsandbytes QLoRA, with or without gradient checkpointing, ran out of memory under the 12 GB cap in earlier runs, so the full check leaves it out.
|
|
169
220
|
|
|
170
221
|
**LoRA r=16, Qwen2.5-14B, documents of 64–2,048 tokens packed into 2 rows of 2,048 (WSL2)**
|
|
171
222
|
|
|
172
223
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
173
224
|
|---|---|---|---|
|
|
174
|
-
| TrainStream, NVFP4 base |
|
|
175
|
-
| TrainStream, NF4 base | 5.
|
|
176
|
-
| bitsandbytes QLoRA + Liger kernels |
|
|
177
|
-
| bitsandbytes QLoRA + gradient checkpointing |
|
|
178
|
-
| TrainStream (auto) |
|
|
225
|
+
| TrainStream, NVFP4 base | 3.54 s | 19.9 GB | fastest |
|
|
226
|
+
| TrainStream, NF4 base | 5.31 s (3 runs: 5.30–5.42) | 19.8 GB | 1.50× |
|
|
227
|
+
| bitsandbytes QLoRA + Liger kernels | 5.74 s (3 runs: 5.72–5.82) | 14.4 GB | 1.62× |
|
|
228
|
+
| bitsandbytes QLoRA + gradient checkpointing | 6.20 s | 21.0 GB | 1.75× |
|
|
229
|
+
| TrainStream (auto) | 6.43 s | 21.3 GB | 1.82× |
|
|
179
230
|
|
|
180
231
|
Unsloth isn't compared here: it patches attention itself, so the harness can't check that attention stays inside each packed document.
|
|
181
232
|
|
|
@@ -183,51 +234,61 @@ Unsloth isn't compared here: it patches attention itself, so the harness can't c
|
|
|
183
234
|
|
|
184
235
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
185
236
|
|---|---|---|---|
|
|
186
|
-
| TrainStream (auto) | 1.
|
|
187
|
-
| Stock PyTorch | 1.
|
|
188
|
-
| DeepSpeed ZeRO-2, optimizer offload |
|
|
237
|
+
| TrainStream (auto) | 1.07 s | 18.8 GB | fastest |
|
|
238
|
+
| Stock PyTorch | 1.42 s | 32.4 GB | 1.33× (spills past VRAM) |
|
|
239
|
+
| DeepSpeed ZeRO-2, optimizer offload | 1.75 s | 13.3 GB | 1.64× |
|
|
189
240
|
|
|
190
241
|
**The same on Windows 11 (64 GB RAM; Unsloth, Liger and DeepSpeed aren't installed there)**
|
|
191
242
|
|
|
192
243
|
| Engine | LoRA 14B, 1 × 512 | LoRA 14B, 1 × 2048 | 14B, 12 GB VRAM | 14B, packed | Full fine-tune 1.5B |
|
|
193
244
|
|---|---|---|---|---|---|
|
|
194
|
-
| TrainStream, NVFP4 base | **0.
|
|
195
|
-
| TrainStream, NF4 base | 0.
|
|
196
|
-
| TrainStream (auto) |
|
|
197
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
198
|
-
| bitsandbytes QLoRA + gradient checkpointing | 0.
|
|
199
|
-
| Stock PyTorch | spills past VRAM | spills past VRAM | — | — | 1.
|
|
200
|
-
|
|
201
|
-
- With an NVFP4 base TrainStream had the fastest step in every 14B scenario, in WSL and on Windows,
|
|
202
|
-
- With an NF4 base, the format bitsandbytes and Unsloth use, TrainStream was ahead of every rival in every scenario except under the 12 GB cap, where
|
|
245
|
+
| TrainStream, NVFP4 base | **0.502 s** | **1.40 s** | **0.670 s** | **3.74 s** | — |
|
|
246
|
+
| TrainStream, NF4 base | 0.561 s | 2.05 s | 0.710 s | 5.46 s | — |
|
|
247
|
+
| TrainStream (auto) | 0.895 s | 2.82 s | 1.50 s | 6.61 s | **1.11 s** |
|
|
248
|
+
| bitsandbytes QLoRA (NF4) + PEFT | 0.621 s | spills past VRAM | out of memory | left out (hit the time limit in an earlier run) | — |
|
|
249
|
+
| bitsandbytes QLoRA + gradient checkpointing | 0.897 s | 2.98 s | out of memory | 6.52 s | — |
|
|
250
|
+
| Stock PyTorch | spills past VRAM | spills past VRAM | — | — | 1.45 s (spills) |
|
|
251
|
+
|
|
252
|
+
- With an NVFP4 base TrainStream had the fastest step in every 14B scenario, in WSL and on Windows, including under the 12 GB cap. NVFP4 costs quality (see the perplexity table below).
|
|
253
|
+
- With an NF4 base, the format bitsandbytes and Unsloth use, TrainStream was ahead of every rival in every scenario except under the 12 GB cap, where Unsloth was 1.08× faster (1.10× in 0.8.0). TrainStream now keeps 46 of the 48 4-bit layers in VRAM there (36 in 0.8.0); Unsloth keeps them all. At 512 tokens its lead over bitsandbytes is small (1.06× in WSL, 1.11× on Windows).
|
|
203
254
|
- When it has room, TrainStream holds more in VRAM than Unsloth (16.8 GB against 11.5 GB at 512 tokens) because it plans up to a VRAM target; held to 12 GB it fits like Unsloth does.
|
|
204
|
-
- `"auto"` with 49–64 GB of RAM keeps the 14B base exact in bf16 and streams
|
|
205
|
-
- The full fine-tune: TrainStream keeps its activations in VRAM and stays at 18.8 GB, 1.
|
|
255
|
+
- `"auto"` with 49–64 GB of RAM keeps the 14B base exact in bf16 and streams 17–23 of its 48 layers from RAM (35–36 under the 12 GB cap). That is slower than the 4-bit engines and changes no weight.
|
|
256
|
+
- The full fine-tune: TrainStream keeps its activations in VRAM and stays at 18.8 GB, 1.33× faster than stock PyTorch in WSL and 1.31× on Windows. Stock PyTorch peaks at 32.4 GB, more than the GPU's 24 GB, so its step time depends on how the driver spills into system RAM.
|
|
206
257
|
- Stock PyTorch and DeepSpeed in the 14B scenarios, and bitsandbytes without checkpointing at 2,048 tokens, don't fit in 24 GB of VRAM: in earlier runs the driver spilled into system RAM at 46–371 s per step, so the full check leaves them out.
|
|
258
|
+
- Between the two environments, every engine was within 11 % of its time in the other, except `"auto"` under the 12 GB cap, 26 % slower in WSL (1.89 s against 1.50 s; 33 % in 0.8.0). In this check most engines, bitsandbytes included, were faster in WSL, the opposite of 0.8.0's, because Windows ran at the lower GPU clock.
|
|
207
259
|
|
|
208
260
|
**Perplexity against bf16** (`benchmarks/quality.py`, held-out Python standard-library source; lower is better)
|
|
209
261
|
|
|
210
262
|
| Format | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
211
263
|
|---|---|---|---|---|
|
|
212
|
-
| int8 | −0.00 % |
|
|
213
|
-
| FP8 (tensor cores) | +0.89 % | +0.
|
|
214
|
-
| NF4 | +3.10 % | +2.
|
|
215
|
-
| NF4, `keep_precise="auto"` | +2.89 % | +2.
|
|
216
|
-
| NF4, `error_rank=16` (LoftQ) | +3.06 % | +2.
|
|
217
|
-
| NF4, `double_quant=True` | +2.79 % | +2.
|
|
218
|
-
| NVFP4, weights only (bf16 matmuls) | +2.63 % | +2.
|
|
219
|
-
| NVFP4 (tensor cores) | +5.19 % | +
|
|
220
|
-
| NVFP4 with `outliers=0.01` | +4.78 % | +4.
|
|
221
|
-
| NVFP4, `error_rank=16` (LoftQ) | +5.14 % | +4.
|
|
222
|
-
| NVFP4, `nvfp4_backward=True` | +5.19 % | +
|
|
223
|
-
|
|
224
|
-
|
|
264
|
+
| int8 | −0.00 % | −0.02 % | +0.02 % | −0.01 % |
|
|
265
|
+
| FP8 (tensor cores) | +0.89 % | +0.70 % | +1.70 % | +1.54 % |
|
|
266
|
+
| NF4 | +3.10 % | +2.83 % | +5.94 % | +5.02 % |
|
|
267
|
+
| NF4, `keep_precise="auto"` | +2.89 % | +2.71 % | +5.27 % | +4.26 % |
|
|
268
|
+
| NF4, `error_rank=16` (LoftQ) | +3.06 % | +2.75 % | +5.76 % | +4.06 % |
|
|
269
|
+
| NF4, `double_quant=True` | +2.79 % | +2.65 % | +5.96 % | +4.95 % |
|
|
270
|
+
| NVFP4, weights only (bf16 matmuls) | +2.63 % | +2.31 % | +5.42 % | +5.00 % |
|
|
271
|
+
| NVFP4 (tensor cores) | +5.19 % | +4.81 % | +10.86 % | +10.38 % |
|
|
272
|
+
| NVFP4 with `outliers=0.01` | +4.78 % | +4.15 % | +8.99 % | +8.48 % |
|
|
273
|
+
| NVFP4, `error_rank=16` (LoftQ) | +5.14 % | +4.63 % | +10.85 % | +8.76 % |
|
|
274
|
+
| NVFP4, `nvfp4_backward=True` | +5.19 % | +5.06 % | +10.86 % | +10.16 % |
|
|
275
|
+
|
|
276
|
+
The LoRA steps above use learning rate 2e-4. PiSSA needs a lower one, so it was measured at 2e-5, together with the formats it is compared with:
|
|
277
|
+
|
|
278
|
+
| Format, LoRA at 2e-5 | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
279
|
+
|---|---|---|---|---|
|
|
280
|
+
| NF4 | +3.10 % | +3.09 % | +5.94 % | +5.66 % |
|
|
281
|
+
| NF4, `lora_init="pissa"` | +2.96 % | +1.97 % | +5.47 % | +4.55 % |
|
|
282
|
+
| NVFP4 (tensor cores) | +5.19 % | +4.67 % | +10.86 % | +10.49 % |
|
|
283
|
+
| NVFP4, `lora_init="pissa"` | +5.27 % | +4.52 % | +10.20 % | +8.81 % |
|
|
284
|
+
|
|
285
|
+
bf16 itself: 2.300 (14B) and 3.251 (1.5B) on 16 and 64 windows of 1,024 tokens. NVFP4's 4-bit weights alone cost less than NF4; its extra loss comes from quantizing the activations. On 1.5B the short fine-tune at 2e-4 raised bf16's own held-out perplexity (3.251 → 3.306), so compare the formats with each other there. The columns before fine-tuning repeat exactly from run to run. The ones after it don't, since training on the GPU isn't bit-exact: across the saved runs the NF4 formats moved by up to 0.2 points and the NVFP4 formats by up to about 1 point, so differences that small there are noise. In this check PiSSA's gain at 2e-5 was larger than that variation for NF4 on both models and for NVFP4 on 1.5B; for NVFP4 on 14B (+4.52 % against +4.67 %) it was within it (it was 1.20 points in 0.8.0's).
|
|
225
286
|
|
|
226
287
|
Each engine runs in a fresh process with the same model, random-token data (the packed scenario: random documents of 64–2,048 tokens), LoRA settings (r=16, all projections), learning rate and loop. Each computes its loss its own recommended way: TrainStream in chunks from the hidden states, Liger with its fused linear cross-entropy, Unsloth with its own, the others through the model. Re-run with `benchmarks/compare.py` and `benchmarks/quality.py`.
|
|
227
288
|
|
|
228
289
|
## Results (RTX 5090 Laptop GPU 24 GB, 64 GB RAM)
|
|
229
290
|
|
|
230
|
-
Measured with TrainStream 0.1–0.4, when each feature arrived: these rows show what fits and how, not today's speed (the comparison above is 0.
|
|
291
|
+
Measured with TrainStream 0.1–0.4, when each feature arrived: these rows show what fits and how, not today's speed (the comparison above is 0.8.1).
|
|
231
292
|
|
|
232
293
|
| Workload | Stock PyTorch | TrainStream |
|
|
233
294
|
|---|---|---|
|
|
@@ -249,7 +310,7 @@ Offloading costs throughput when a model already fits, which is why `offload="au
|
|
|
249
310
|
- The CUDA toolkit matching PyTorch's CUDA major version, and a C++ compiler (Visual Studio 2022+ Build Tools with "Desktop development with C++" on Windows, GCC 11+ on Linux)
|
|
250
311
|
- Optional, for the Hugging Face integration: `transformers`, `accelerate`, and `peft` for LoRA (all three come with `trainstream[hf]`)
|
|
251
312
|
|
|
252
|
-
Tested on an RTX 5090 Laptop GPU with Windows 11 (PyTorch 2.14.1, CUDA 13.4, MSVC, Python 3.14), where all
|
|
313
|
+
Tested on an RTX 5090 Laptop GPU with Windows 11 (PyTorch 2.14.1, CUDA 13.4, MSVC, Python 3.14), where all 465 tests pass with no warnings, and Ubuntu 24.04 under WSL2 (PyTorch 2.14.1, CUDA 13.3, GCC 13.3, Python 3.12), where all 465 pass as well (with bitsandbytes 0.50.2 installed for the NF4 comparison), both from a wheel installed with pip and with uv. Installs were checked with pip and with uv 0.13 (`uv pip install`, `uv sync` in a project, and building from the sdist) on both. Native Linux and other GPUs are untested.
|
|
253
314
|
|
|
254
315
|
## Install
|
|
255
316
|
|
|
@@ -426,6 +487,7 @@ model._trainstream_session.adapting # True while it is still tuning itself
|
|
|
426
487
|
| `offload` | `"auto"`, `True` | `"auto"` | `"auto"` switches to fused torch AdamW after 2 steps if the model fits |
|
|
427
488
|
| `activation_offload` | `"auto"`, `True`, `False`, fraction 0.0–1.0 | `"auto"` | how many blocks' activations are paged to RAM; `"auto"`: measured in the first step, kept in VRAM if they fit under the VRAM target, otherwise paged as far as host RAM holds them (see `recompute` for the rest): at most 60 % of the RAM available, after what the pinned staging arena may still grow by, always leaving 10 % of physical RAM (at least 4 GiB) free; if available RAM later falls under that floor, half of the paged blocks are recomputed instead; `True`: all but the last block |
|
|
428
489
|
| `param_offload` | `"auto"`, `True`, `False`, fraction 0.0–1.0, list of block indices | `"auto"` | `"auto"`: the memory planner decides which layers stay in VRAM |
|
|
490
|
+
| `embed_offload` | `"auto"`, `True`, `False` | `"auto"` | keep a frozen input embedding (a plain `nn.Embedding` not tied to the output layer) in pinned host RAM. Each forward gathers the batch's rows straight from there on the GPU (zero-copy reads over PCIe, about 10 KB per token for a 5,120-wide model), and the VRAM the table held (1.45 GiB for Qwen2.5-14B) goes to blocks and activations. The output is the same bits. `"auto"`: only when the memory plan would otherwise stream transformer blocks from RAM; `True`: whenever the embedding qualifies; `False`: never |
|
|
429
491
|
| `quantize` | `"auto"`, `"none"`, `None`, `False`, `"int8"`, `"nf4"`, `"fp8"`, `"nvfp4"` | `"auto"` | frozen weights only; `"auto"` quantizes only when the run can't fit otherwise (int8 before NF4); fp8 / nvfp4 run on Blackwell tensor cores |
|
|
430
492
|
| `quant_block_size` | even integer ≥ 2 | `64` | values per fp32 scale (int8 / nf4; fp8 and nvfp4 use fixed 32 / 16) |
|
|
431
493
|
| `prefer` | `"exact"`, `"speed"` | `"exact"` | `"speed"` lets `quantize="auto"` choose NF4 when it keeps every layer in VRAM |
|
|
@@ -435,18 +497,28 @@ model._trainstream_session.adapting # True while it is still tuning itself
|
|
|
435
497
|
| `nvfp4_backward` | `True`, `False` | `False` | with `quantize="nvfp4"` on tensor cores: the input gradient of each frozen matmul in NVFP4 too (the gradient and the transposed weight quantized along the reduced dimension, round to nearest) instead of bf16. Faster backward matmuls, about 12 % relative error in those gradients (0.2 % in bf16); measure it with `quality.py --formats nvfp4 nvfp4-b` |
|
|
436
498
|
| `kernels` | `"auto"`, `True`, `False`, `None` | `"auto"` | fused CUDA kernels for each block's RMSNorm, rotary embedding and gated MLP activation (`trainstream.fused`); each is checked once against the model's own code and used only where they agree. They compute in fp32 and round once, so results differ from PyTorch's in the last bits: `"auto"` turns them on when the frozen weights are quantized (already not bit-exact), off otherwise |
|
|
437
499
|
| `fused_lora` | `"auto"`, `True`, `False`, `None` | `"auto"` | PEFT LoRA adapters (no dropout, DoRA or adapter bias) computed by one autograd function: two matmuls forward, the second accumulating into the base output, three backward, keeping the input the base read instead of a copy (`trainstream.lora`). Matches PEFT up to the rounding of its intermediate products; `"auto"`: on when the frozen weights are quantized |
|
|
500
|
+
| `mlp_recompute` | `"auto"`, `True`, `False`, `None` | `"auto"` | with `kernels` on: a gated MLP keeps its input for backward instead of the outputs of `gate_proj` and `up_proj`, and runs those two projections again in backward, through the model's own modules (the same bits, the same gradients). The two outputs are each [tokens, intermediate], roughly a third of everything a decoder layer keeps for backward, so under memory pressure they are bytes that cross PCIe twice; recomputing them costs two matmuls and the LoRA terms per MLP. `"auto"`: for MLPs whose projections both run on tensor cores (nvfp4 / fp8 on Blackwell, where those matmuls are cheap), from the first step at which the run streams weights from host RAM or pages or recomputes activations, and from then on; `True`: every MLP, always (with bf16 or expanded weights the recomputation is two full-size matmuls: measure it); `False`: never. Projections with LoRA dropout in effect are never recomputed. `memory_report()["mlp_front"]` counts the fronts and the bytes not kept |
|
|
501
|
+
| `fused_gemm` | `True`, `False` | `False` | compute those MLP fronts with TrainStream's own kernel where it applies, instead of cuBLAS's matmuls and separate passes: the two FP4 tensor-core products, the LoRA terms and the activation in one kernel, accumulated in registers, so gate / up outputs never exist in memory (`csrc/gemm_fp4_kernel.cu`, hand-written PTX, no CUTLASS). It applies on consumer Blackwell (sm_120) to MLPs whose `gate_proj` and `up_proj` are nvfp4 without bias or outlier channels, with plain LoRA or none, and bf16 output; such MLPs then always use the recompute front. Off by default because it measured slower than cuBLAS: see **What's new in 0.8** above |
|
|
502
|
+
| `lora_chunks` | `"auto"`, `True`, `False`, `None`, integer 0–64 | `"auto"` | how a large paged activation comes back from host RAM: as several back-to-back copies with a CUDA event after each, so the fused LoRA backward can sum an adapter's weight gradient over the rows that have landed while the rest of its input is still crossing PCIe. It changes the computation only when backward reaches a layer before its input has arrived; the gradient is then a sum of per-piece matmuls, equal up to rounding. `"auto"`: pieces of at least 4 MiB, at most 8; an integer: that many pieces (activations of 2 MiB or more); `False`: one copy. `memory_report()["activations"]["chunked"]` counts both cases |
|
|
503
|
+
| `nan_guard` | `True`, `False` | `True` | skip, as a whole, any optimizer step whose gradients hold a NaN or Inf: weights, moments and step counts stay as they were, the gradients are dropped, a `RuntimeWarning` names the step and training continues (`optimizer.skipped_steps`, `memory_report()["guard"]`; 50 skipped steps in a row raise `FloatingPointError`). The fused kernels also flag where a non-finite value first appeared. The verdict needs all of a step's gradients before any update runs, so eager updates are off and each trained value keeps a 4-byte host accumulator (both already so with clipping or accumulation). `False`: no checks, eager updates where possible |
|
|
504
|
+
| `fp8_gradients` | `True`, `False` | `False` | with `optimizer_mode="cpu"`: gradients cross PCIe as one byte per value (an e4m3 code against an fp32 scale per 256 values, rounded stochastically on the GPU so the rounding is zero-mean noise) instead of two (bf16) or four (fp32), and are expanded into the host's fp32 accumulator. Half or a quarter of the gradient traffic and of its pinned staging memory; matters for full fine-tunes, whose gradients are as large as the model. Each value is off by up to 12.5 %; not bit-exact with fp32 gradients |
|
|
438
505
|
| `keep_precise` | `0`, `False`, `None`, `"auto"`, `True`, fraction up to 0.5 | `0` | with `quantize="nf4"` / `"nvfp4"`: the weights that lose the most in that format (relative error, measured one by one) are stored one step more precise, int8 / fp8, as long as the extra bytes stay within this fraction of the quantized weights' size; `"auto"` / `True` mean `0.05` |
|
|
439
506
|
| `error_rank` | integer ≥ 0 | `0` | LoftQ: quantizing a weight also fits a rank-`error_rank` approximation of what quantization lost, and the PEFT LoRA adapters on it start there instead of at zero, so base + adapter starts close to the original weights (use the LoRA rank). Weights quantized beforehand with `error_rank` start their adapters the same way |
|
|
440
|
-
| `error_iters` | integer ≥ 1 | `1` | LoftQ rounds: alternate quantizing `W - BA` and fitting `BA` to what that lost |
|
|
507
|
+
| `error_iters` | integer ≥ 1 | `1` | LoftQ rounds: alternate quantizing `W - BA` and fitting `BA` to what that lost. PiSSA: rounds of refitting the principal part against the stored residual |
|
|
508
|
+
| `lora_init` | `"loftq"`, `"pissa"` | `"loftq"` | what the low-rank factors of a quantized weight are. `"loftq"`: its quantization error (off while `error_rank` is 0). `"pissa"`: each quantized weight that carries a plain PEFT LoRA adapter is split with one randomized SVD into its principal part, of the adapter's own rank (`error_rank` is not needed), and the rest; the adapter starts at the principal part and the rest is what gets quantized, so base + adapter still starts at the original weight, up to the residual's quantization. Weights without an adapter are quantized as usual. The base then holds only the residual: `trainstream.pissa_to_lora(model)` converts a trained adapter for the original weights. For a base that is not quantized, use PEFT's own `init_lora_weights="pissa"`. PiSSA adapters need a lower learning rate than a zero-started LoRA (about 2e-5); `wrap()` warns when their optimizer group's learning rate is above 3e-5 |
|
|
441
509
|
| `double_quant` | `True`, `False` | `False` | int8 / NF4 block scales stored as one-byte log codes with an fp32 scale per 256 blocks (decoded to the same values on the GPU and in `dequantize`): about 0.37 bit per weight less, 0.65 GB on a 14B model, at no measurable error |
|
|
442
|
-
| `disk_offload` | `None`, a directory | `None` | frozen paged weights the page-lock budget can't hold go to
|
|
443
|
-
| `
|
|
510
|
+
| `disk_offload` | `None`, a directory | `None` | frozen paged weights the page-lock budget can't hold go to files there (`trainstream.disk`) instead of ordinary RAM, and the RAM check stops counting them. Training reads them with asynchronous unbuffered I/O (an I/O completion port on Windows, io_uring on Linux, a thread pool where neither is available: no OS page cache, no page faults) into pinned staging memory ahead of the layer that needs them, and the copy to the GPU waits for the read on a CUDA stream of its own, so the training loop never waits for the SSD. Use a fast SSD; the folder is removed at exit. `memory_report()["disk"]` shows the traffic |
|
|
511
|
+
| `disk_lookahead` | `"auto"`, integer ≥ 1 | `"auto"` (`prefetch_depth + 1`) | with `disk_offload`: how many paged blocks ahead of the running one have their files read into pinned staging memory. The first `prefetch_depth` of them are also copied to VRAM; the rest wait in host memory, which keeps the SSD ahead of the PCIe copy at the price of one staging slot (a block's disk-backed bytes, pinned) each |
|
|
512
|
+
| `moe_paging` | `True`, `False` | `False` | the frozen experts of mixture-of-experts layers (Hugging Face's stacked experts: Qwen3-MoE, Qwen2-MoE, Mixtral…) stay in pinned host RAM and each layer copies in only the experts its tokens were routed to (`trainstream.experts`). A layer looks at its routing once, queues every expert it needs on the copy stream before computing the first, and computes each as its own copy lands; backward queues a layer's experts, and those of the MoE layer below, when it reaches the layer. Bit-identical to the unpaged model. Pays when a step routes to few experts; `memory_report()["experts"]` counts what was copied |
|
|
513
|
+
| `moe_cache` | `"auto"`, `True`, `False`, `None`, bytes | `"auto"` (10 % of the GPU's memory budget, at most the experts' size) | with `moe_paging`: VRAM that keeps recently used experts, least recently used out first, so an expert used again (by the next step, or by backward) is not copied again. With a cache, a layer also queues the experts the next MoE layer will probably need (that layer's router applied to this layer's input; guessing stops for a layer where it is wrong more often than right). `False` / `0`: no cache and no guessing |
|
|
514
|
+
| `moe_capacity` | `None`, integer ≥ 1 | `None` | with `moe_paging`: at most this many experts are copied in per MoE layer and pass. Beyond it the most-used ones are copied, and tokens routed to any other expert that is not in VRAM are re-routed: the router's top-k runs again over the allowed experts and its weights are renormalized as the router does. **This changes what the model computes**, in exchange for a bound on PCIe traffic; needs Hugging Face's top-k router next to the experts. `None`: no limit, the model's own routing always |
|
|
444
515
|
| `host_arena` | `"auto"`, `False`, `None`, bytes | `"auto"` | page-locked host memory reserved up front, from which paged activations, staging and other pinned buffers are carved; `"auto"`: when the run streams anything, reserve one slab now and grow on demand within the page-lock budget; bytes: reserve that much now and cap growth there |
|
|
445
516
|
| `peer` | `"auto"`, `False`, `None`, bytes | `"auto"` | data parallel on one machine: pool the frozen blocks every rank streams in the GPUs' VRAM and copy them GPU to GPU (needs peer access between the GPUs and CUDA IPC; set up collectively at step 10); `"auto"`: when peer copies reach 0.9× the host link, each GPU gives half the headroom under the memory plan's target; bytes: that much per GPU. While active, `unwrap()` is collective |
|
|
446
517
|
| `moment_dtype` | `"auto"`, `"float32"`, `"bfloat16"`, `"bf16"`, `torch.bfloat16`, `"int8"` | `"auto"` | fp32 unless that wouldn't fit in RAM, then bf16 (stochastic rounding), then 8-bit with the host optimizer; `"int8"`: one byte per moment value (see `OffloadAdamW`), a quarter of fp32's RAM |
|
|
447
518
|
| `device` | `None`, `"cuda"`, `"cuda:N"`, `torch.device` | `None` | target GPU when the model is on the CPU |
|
|
448
519
|
| `blocks` | `None`, list of layer modules | `None` | the repeated layer stack; auto-detected |
|
|
449
520
|
| `distributed` | `None`, `True`, `False` | `None` | data parallel when a process group with > 1 rank exists |
|
|
521
|
+
| `distributed_backend` | `"auto"`, `"ring"`, `"gloo"` | `"auto"` | how data-parallel ranks sum a gradient. `"auto"`: through shared memory when every rank is on this machine, otherwise around a TCP ring between the ranks (`trainstream.ring`): each rank sends 2 (N − 1) / N of the gradient whatever the number of ranks N, and every rank ends with the same bits. `"ring"`: the ring even on one machine. `"gloo"`: `torch.distributed`'s `all_reduce` instead of the ring. Parameters are broadcast, and the ranks find each other, through a gloo group either way |
|
|
450
522
|
| `guard_params` | `True`, `False` | `True` | reads of a weight wait for its in-flight update |
|
|
451
523
|
| `max_grad_norm` | `None`, float | `None` | global-norm clipping inside the optimizer |
|
|
452
524
|
| `accumulation_steps` | integer ≥ 1 | `1` | backward passes per `step()` |
|
|
@@ -486,16 +558,19 @@ NF4 is bit-identical to bitsandbytes' NF4 (same codes, packing and scales); Trai
|
|
|
486
558
|
| `quant_block_size` | even integer ≥ 2 | `64` |
|
|
487
559
|
| `keep_precise` | as `wrap()` | `0` (the chosen matrices are read again from the checkpoint and stored int8 / fp8) |
|
|
488
560
|
| `error_rank`, `error_iters` | as `wrap()` | `0`, `1` (LoftQ factors kept with each quantized matrix; `wrap()` starts the adapters at them) |
|
|
561
|
+
| `lora_init` | `"loftq"`, `"pissa"` | `"loftq"` (`"pissa"`, with `error_rank` = the r of the LoRA adapters you will add: each matrix is split as it is read into its rank-`error_rank` principal part, which `wrap()` starts the adapter at, and the rest, which is what gets quantized) |
|
|
562
|
+
| `lora_targets` | `None`, list of module-name suffixes | `None` (every quantized matrix; with `lora_init="pissa"` only matrices that will carry an adapter may be split: pass the same list as `LoraConfig.target_modules`. `wrap()` raises if a split matrix has no adapter) |
|
|
489
563
|
| `double_quant` | `True`, `False` | `False` (as `wrap()`) |
|
|
490
|
-
| `disk_offload` | `None`, a directory | `None` (decoder-layer matrices that aren't quantized are written to
|
|
564
|
+
| `disk_offload` | `None`, a directory | `None` (decoder-layer matrices that aren't quantized are written to files there as they're read, so a base larger than RAM loads; `wrap()` streams them from there with unbuffered I/O) |
|
|
491
565
|
| `random_weights` | `True`, `False` | `False` (build the shapes without reading a checkpoint) |
|
|
492
566
|
| `ram_fraction` | float 0.0–1.0 | `0.85` |
|
|
567
|
+
| `check_memory` | `True`, `False` | `True` (before anything is read, the model's size in the chosen format is compared with the available RAM; if it doesn't fit, `MemoryError` says so, and whether it exceeds RAM and VRAM combined, instead of loading into the OS page file on the SSD. RAM alone is the limit because `load_model` holds the whole model in RAM until `wrap()` moves part of it to the GPU. Skipped with `disk_offload`) |
|
|
493
568
|
| `trust_remote_code` | `True`, `False` | `False` |
|
|
494
569
|
| `**config_overrides` | any config field, e.g. `num_hidden_layers=4` | — |
|
|
495
570
|
|
|
496
571
|
An NVFP4 checkpoint exported by NVIDIA ModelOpt (`"quant_method": "modelopt", "quant_algo": "NVFP4"` in its config) is read as it is stored: the packed codes and e4m3 scales become TrainStream NVFP4 weights without being expanded or quantized again (`quantize` is ignored for it; matrices the export kept in 16 bits stay so). Tested on a checkpoint written in that layout, not yet on one exported by ModelOpt itself.
|
|
497
572
|
|
|
498
|
-
### `trainstream.quantize_model(model, quantize="nf4", *, blocks=None, block_size=64, pin_budget=None, keep_precise=0, error_rank=0, error_iters=1, double_quant=False)`
|
|
573
|
+
### `trainstream.quantize_model(model, quantize="nf4", *, blocks=None, block_size=64, pin_budget=None, keep_precise=0, error_rank=0, error_iters=1, double_quant=False, lora_init="loftq", lora_targets=None)`
|
|
499
574
|
|
|
500
575
|
Quantizes the frozen block weights in place, one tensor at a time, before `wrap()`. Returns `{"tensors": count, "kept_precise": count, "bytes_before": ..., "bytes_after": ...}`.
|
|
501
576
|
|
|
@@ -509,8 +584,12 @@ Quantizes the frozen block weights in place, one tensor at a time, before `wrap(
|
|
|
509
584
|
| `keep_precise` | as `wrap()` | `0` | store the weights that lose the most one step more precise, within that fraction of extra bytes |
|
|
510
585
|
| `error_rank`, `error_iters` | as `wrap()` | `0`, `1` | keep LoftQ factors with each weight for `init_lora_from_error` / `wrap()` |
|
|
511
586
|
| `double_quant` | `True`, `False` | `False` | one-byte int8 / NF4 block scales |
|
|
587
|
+
| `lora_init` | `"loftq"`, `"pissa"` | `"loftq"` | what the `error_rank` factors are: the quantization error, or (`"pissa"`, which needs `error_rank` = the adapters' r) the weight's principal part, with the residual being what is stored |
|
|
588
|
+
| `lora_targets` | `None`, list of module-name suffixes | `None` (every quantized matrix) | which matrices get factors: with `"pissa"`, the same list as `LoraConfig.target_modules`, since a split matrix must carry an adapter |
|
|
589
|
+
|
|
590
|
+
`trainstream.init_lora_from_error(model) → int` starts every PEFT LoRA adapter whose base weight carries low-rank factors and returns how many it set; `wrap()` calls it for you. LoftQ factors: at that weight's quantization error (`lora_B = B / scaling`, `lora_A = A`, their first r components). PiSSA factors: at the weight's principal part; the adapter must be a plain one with r at least the factors' rank, and a split weight without an adapter raises `ValueError`. An adapter is started once: wrapping the model again leaves trained adapters alone.
|
|
512
591
|
|
|
513
|
-
`trainstream.
|
|
592
|
+
`trainstream.pissa_to_lora(model, save_directory=None, adapter_name=None) → dict` returns the trained adapters as an ordinary LoRA on the *original* base weights: `{"<module>.lora_A.weight" / ".lora_B.weight": fp32 CPU tensor}` at rank 2r (`lora_B' = [B, −B0]`, `lora_A' = [A; A0]`, same scaling; adapters not started by PiSSA are padded with zeros). With `save_directory` it also writes `adapter_model.safetensors` and an `adapter_config.json` with `r` and `lora_alpha` doubled, which `peft.PeftModel.from_pretrained(original_base, save_directory)` loads. Works while the model is wrapped and after `unwrap()`.
|
|
514
593
|
|
|
515
594
|
### `trainstream.OffloadAdamW(params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, weight_decay=1e-2, *, ...)`
|
|
516
595
|
|
|
@@ -526,13 +605,18 @@ AdamW with its moments and fp32 master weights in host RAM. `wrap()` creates or
|
|
|
526
605
|
| `threads` | `None`, integer | `None` (all cores) | host AdamW worker threads |
|
|
527
606
|
| `chunk_elems` | integer | `1048576` | elements per work chunk when a tensor's update is split across threads |
|
|
528
607
|
| `accumulation_steps` | integer ≥ 1 | `1` | backward passes per `step()`; an extra backward before `step()` raises |
|
|
529
|
-
| `eager` | `None`, `True`, `False` | `None` (on when there is no clipping or
|
|
608
|
+
| `eager` | `None`, `True`, `False` | `None` (on when there is no clipping, norm or `nan_guard`) | start each tensor's update as soon as its last gradient lands, during backward. Has no effect while `nan_guard` is on |
|
|
530
609
|
| `pin_moments` | `None`, `True`, `False` | `None` (pin unless it would lock more than 40 % of RAM) | page-lock the moments in host RAM (`"gpu"` mode always pins) |
|
|
531
610
|
| `moment_dtype` | `"float32"`, `"fp32"`, `"bfloat16"`, `"bf16"`, `torch.float32`, `torch.bfloat16`, `"int8"`, `"8bit"` | `"float32"` | bf16 halves moment memory and traffic, with stochastic rounding. `"int8"` (`"cpu"` mode only) keeps one byte per value, a small float relative to an fp32 absmax per 256 values (`exp_avg_sq` as its square root, stochastic rounding; `exp_avg` rounded to nearest): 2 bytes per parameter instead of 8. After 30 steps of a test MLP the weights are within 5 % of how far fp32 AdamW moved them (bitsandbytes' `AdamW8bit`: 4 %). `state_dict()` hands the moments out as fp32 |
|
|
532
611
|
| `distributed` | `True`, `False` | `False` | data parallel: broadcast from rank 0, gradients averaged on the host (`"cpu"` mode only) |
|
|
612
|
+
| `distributed_backend` | `"auto"`, `"ring"`, `"gloo"` | `"auto"` | as `wrap()` |
|
|
613
|
+
| `nan_guard` | `True`, `False` | `True` | skip any step whose gradients hold a NaN or Inf, leaving weights, moments and step counts untouched (as `wrap()`) |
|
|
614
|
+
| `fp8_gradients` | `True`, `False` | `False` | `"cpu"` mode: gradients cross PCIe as e4m3 bytes with stochastic rounding (as `wrap()`) |
|
|
533
615
|
|
|
534
616
|
Methods and attributes: `step(closure=None)`, `zero_grad()`, `attach(model, guard=True)` (install the streaming hooks; `wrap()` does this), `detach()`, `synchronize()` (block until every queued update has landed), `stats()`, `state_dict()` / `load_state_dict()` (compatible with `torch.optim.AdamW`, plus the fp32 `master` weights), `add_param_group()`, `last_grad_norm`.
|
|
535
617
|
|
|
618
|
+
Also: `skipped_steps` (steps the non-finite guard dropped; a step still in flight is counted once its gradients have been checked), `set_nan_guard(on)`, and `save_async(path, extra=None, model=None)` (a background checkpoint: `trainstream.save_checkpoint(model, optimizer, path, extra=extra)`). `stats()` adds `nan_guard`, `skipped_steps`, `fp8_gradients` and, under data parallel, `distributed_backend` (`"shm"`, `"ring"` or `"gloo"`) and `ring` (`calls`, `bytes_sent`, `bytes_received`, `wall_ms`).
|
|
619
|
+
|
|
536
620
|
### `trainstream.integrations.huggingface`
|
|
537
621
|
|
|
538
622
|
| Function / class | Arguments | What it does |
|
|
@@ -545,6 +629,8 @@ Methods and attributes: `step(closure=None)`, `zero_grad()`, `attach(model, guar
|
|
|
545
629
|
| `reference_logprobs(model, batches, *, chunk_size=1024, average=False)` | `batches`: iterable of dicts with `"input_ids"` and optionally `"labels"` and `"attention_mask"` | DPO's reference log-probs without a second model: a PEFT model runs with its adapters off, in eval mode and without gradients; one float32 CPU tensor with every sequence's value, in order |
|
|
546
630
|
| `TrainStreamCache(model, max_tokens, *, resident_layers="auto", page_tokens=256, vram_fraction=0.5)` | `model`: a decoder with full attention in every layer (sliding-window models are refused). Other arguments as `PagedKVCache` below | a `transformers` `Cache` for `model.generate(past_key_values=...)` whose keys and values are partly in host RAM; greedy or sampling (no beam search); `.reset()` before the next prompts; `.kv` is the `PagedKVCache`. Needs `transformers` ≥ 4.56 |
|
|
547
631
|
|
|
632
|
+
`trainstream={"async_checkpoint": True}` (default `False`): the Trainer's checkpoints keep their layout, except that the optimizer state (fp32 master weights and both moments, most of a checkpoint's bytes) is written by a background thread to `trainstream.ckpt` in the checkpoint folder instead of being pickled into `optimizer.pt` on the training thread, so training goes on while it is written. `train(resume_from_checkpoint=...)` reads either; `train()` returns once the last one is complete; `trainer.last_checkpoint` is its `CheckpointHandle`.
|
|
633
|
+
|
|
548
634
|
How `TrainStreamTrainer` uses `TrainingArguments`:
|
|
549
635
|
- `optim` must be an Adam/AdamW variant.
|
|
550
636
|
- `learning_rate`, `adam_beta1`, `adam_beta2`, `adam_epsilon`, `weight_decay` and the decay / no-decay split carry over.
|
|
@@ -608,6 +694,12 @@ Methods and attributes:
|
|
|
608
694
|
| `trainstream.reserve_pinned(bytes_now, cap=0, slab=0)` | `bytes_now`: page-lock this much for the arena now. `cap`: let it grow on demand up to this (at least `bytes_now`). `slab`: slab size in bytes (`0` keeps the current one) | the bytes reserved so far; `wrap(host_arena=...)` calls it for you |
|
|
609
695
|
| `trainstream.transfer_stats(device=None)` | `device`: GPU (default the current one) | cumulative bytes and copies on TrainStream's D2H and H2D streams |
|
|
610
696
|
| `trainstream.find_blocks(model)` | a model | the repeated layer stack `wrap()` would use (the largest `ModuleList` / `Sequential` of ≥ 2 same-type children), or `[]` |
|
|
697
|
+
| `trainstream.save_checkpoint(model, optimizer, path, *, extra=None, blocking=False)` | `model`: the model being trained (records each trained parameter's name; `None`: positions only). `optimizer`: its `OffloadAdamW`. `path`: the file; it appears only once complete (`<path>.tmp` meanwhile). `extra`: a JSON-serializable dict (the step, a scheduler's state). `blocking`: wait for the write | a `CheckpointHandle` at once: `done()`, `wait()` (raises `OSError` if the write failed), `error`, `seconds`, `bytes`, `path`. A detached thread writes the trained parameters and the optimizer state (masters, moments as stored, step counts, param-group hyper-parameters) with unbuffered I/O straight from the optimizer's host buffers; each tensor's next update waits only until that tensor is on disk. Frozen weights are not saved |
|
|
698
|
+
| `trainstream.load_checkpoint(path, model, optimizer)` | `model`: built and wrapped as when the checkpoint was saved (required when weights are paged). `optimizer`: its `OffloadAdamW`; it may differ in mode or moment precision from the saving one (moments are converted, bit for bit where the storage is the same) | the `extra` dict that was saved |
|
|
699
|
+
| `trainstream.read_checkpoint(path, keys=None)` | `keys`: which tensors to read (`None`: all; `[]`: none) | `{"manifest": dict, "tensors": {key: flat CPU tensor}}`; keys are `"slot/<n>/<part>"` (`master`, `exp_avg`, `exp_avg_sq`, `m_scale`, `v_scale`, `param_stage`, `param`, `step`) and `"steps"` |
|
|
700
|
+
| `trainstream.pissa_to_lora(model, save_directory=None, adapter_name=None)` | see `quantize_model` above | the trained adapters as a LoRA for the original base weights |
|
|
701
|
+
|
|
702
|
+
`memory_report()` keys added in 0.8: `"guard"` (`enabled`, `skipped_steps`, `kernel_flags`: which fused kernels saw a NaN / Inf since the last skipped step); `"disk"` when weights are on disk (`backend`: `"iocp"`, `"io_uring"` or `"threads"`, `lookahead`, `frozen_bytes`, `bytes_read`, `staged_bytes`, `stage_hits`, `copied_bytes`, `stream_wait_ms`, `slots`, `slot_bytes`, `ops`, `busy_ms`); in `"params"`, `disk_bytes` (bytes copied from disk staging); in `"activations"`, `"chunked"` (`tensors` fetched in pieces, `pieces`, `overlapped`: LoRA weight gradients that started while their input was still arriving); in `"experts"`, `experts_used`, `experts_copied`, `bytes_copied`, `cache_budget`, `cache_bytes`, `cache_hits`, `cache_misses`, `cache_evictions`, `prefetch_issued`, `prefetch_hits`, `prefetch_stopped_stacks`, `capacity`, `rerouted_layers`, `rerouted_tokens`; in `"optimizer"`, `nan_guard`, `skipped_steps`, `fp8_gradients`, `distributed_backend`, `ring`; `"mlp_front"` when gated MLPs can drop their gate / up outputs (`mode`, `engaged`: whether `"auto"` has switched on, `recomputed`: fronts run without keeping them, `kernel`: of those, computed by the fused FP4 kernel, `bytes_not_kept`, `fused_gemm`, `kernel_available`). Added in 0.8.1: `"embedding"` when the input embedding is kept in host RAM (`host_bytes`, `rows`).
|
|
611
703
|
|
|
612
704
|
The session behind a wrapped model is `model._trainstream_session` (`trainstream.TrainStreamSession`):
|
|
613
705
|
- `.adapting`: `True` while it is still tuning itself. Meanwhile it may reset PyTorch's peak-memory counter (`torch.cuda.reset_peak_memory_stats`) to measure single steps; once it is `False`, the counter is left alone
|
|
@@ -632,6 +724,7 @@ The session behind a wrapped model is `model._trainstream_session` (`trainstream
|
|
|
632
724
|
| `tune_window` | integer ≥ 1 | `3` | steps measured per setting while tuning (the first after a change is discarded) |
|
|
633
725
|
| `max_inflight_bytes` | bytes | `1073741824` | VRAM held by copies still crossing PCIe |
|
|
634
726
|
| `recompute` | `"auto"`, `True`, `False`, fraction, list of block indices | `"auto"` | blocks to recompute in backward instead of keeping or paging |
|
|
727
|
+
| `chunks` | `"auto"`, `False`, integer | `"auto"` | how large activations come back from host RAM (`wrap()`'s `lora_chunks`) |
|
|
635
728
|
| `reserved_link_bytes`, `memory_pressure`, `vram_target` | set by `wrap()` | `(0, 0)`, `False`, `None` | PCIe already used by the optimizer per step; whether weights page; the VRAM target for the probe step |
|
|
636
729
|
|
|
637
730
|
Attributes: `.policy` (per block: `"keep"`, `"offload"` or `"recompute"`), `.decision` (what the tuner measured and chose; `kept_blocks` lists blocks moved back to VRAM later), `.stats`, `.events`, `.block_bytes` (measured saved activations of one block), `.adjustable` (`True` when `"auto"` chose the policy, so `keep_resident` may change it), `.weights_paged` (set by `wrap()`: a callable saying whether weights stream at the moment; it words the probe's event).
|
|
@@ -646,10 +739,13 @@ Attributes: `.policy` (per block: `"keep"`, `"offload"` or `"recompute"`), `.dec
|
|
|
646
739
|
|---|---|
|
|
647
740
|
| `TRAINSTREAM_CACHE_DIR` | where builds are cached (default `%LOCALAPPDATA%\trainstream\build`; Linux `$XDG_CACHE_HOME/trainstream`, else `~/.cache/trainstream`) |
|
|
648
741
|
| `TRAINSTREAM_VERBOSE_BUILD=1` | show compiler output |
|
|
649
|
-
| `TORCH_CUDA_ARCH_LIST` | GPU architectures to compile for (default: the GPUs present) |
|
|
742
|
+
| `TORCH_CUDA_ARCH_LIST` | GPU architectures to compile for (default: the GPUs present; RTX 50-series GPUs are compiled as `12.0a`, the architecture's full feature set, which the FP4 tensor-core kernel needs) |
|
|
743
|
+
| `TRAINSTREAM_NO_FP4=1` | compile without the FP4 tensor-core kernel (`fused_gemm` is then unavailable). The build also does this by itself, after one failed attempt, when the CUDA toolkit cannot assemble the instruction |
|
|
650
744
|
| `CUDA_HOME` / `CUDA_PATH` | CUDA toolkit to use, if it isn't found automatically |
|
|
651
745
|
| `LOCAL_WORLD_SIZE` / `SLURM_NTASKS_PER_NODE` | processes sharing the machine; the planner splits RAM between them, and data parallel shares host memory when all ranks are local |
|
|
652
746
|
| `TRAINSTREAM_SHM=0` | data parallel without shared host memory (per-rank copies, gloo reduction); also turns off peer-GPU pooling, which uses the same local group |
|
|
747
|
+
| `TRAINSTREAM_RING_HOST` | the address (name or IPv4) a data-parallel rank tells the others to reach it at for the ring all-reduce. Default: the loopback address when every rank is on this machine, else the address this machine uses to reach `MASTER_ADDR`, else its host name |
|
|
748
|
+
| `TRAINSTREAM_NO_IO_URING=1` | Linux: read the disk tier and write checkpoints with a thread pool instead of io_uring (it is also the automatic fallback where io_uring is unavailable or forbidden) |
|
|
653
749
|
| `TRAINSTREAM_HOST_ARENA_SLAB` | size of one pinned-arena slab, in bytes or with a `K` / `M` / `G` suffix (default `1G`) |
|
|
654
750
|
| `TRAINSTREAM_EVENT_WAIT` | how TrainStream's host threads wait for the GPU: `poll` (default) checks for `TRAINSTREAM_EVENT_SPIN_US` microseconds (default 50), then sleeps `TRAINSTREAM_EVENT_SLEEP_US` (default 100) between checks; `spin` keeps a core busy until the GPU is done (CUDA's default; the CPU optimizer's threads then held 6–10 cores at 100 %); `block` sleeps until the GPU signals (on an RTX 5090 Laptop under Windows the GPU then drew about half its power and a 14B LoRA step took 1.8× longer; WSL spins anyway) |
|
|
655
751
|
| `TRAINSTREAM_EVENT_SPIN_US` / `TRAINSTREAM_EVENT_SLEEP_US` | with `poll`: how long to check before sleeping, and how long each sleep is, in microseconds |
|
|
@@ -671,7 +767,7 @@ Attributes: `.policy` (per block: `"keep"`, `"offload"` or `"recompute"`), `.dec
|
|
|
671
767
|
| `examples/train_bigger_than_vram.py` | 1.8B model (7.3 GB of fp32 weights) inside a 4 GB VRAM cap | `--vram-gb`, `--moments fp32\|bf16`, `--layers`, `--d-model` |
|
|
672
768
|
| `examples/verify_ram_offload.py` | proves where training memory lives, with a PASS/FAIL verdict | `--gpt`, `--hf`, `--vram-cap-gb`, `--engine both\|baseline\|trainstream` |
|
|
673
769
|
| `benchmarks/compare.py` | head-to-head with stock PyTorch, bitsandbytes QLoRA, Unsloth, DeepSpeed; each result has the GPU's median clock while measured | `--scenario full1.5b\|lora14b\|lora14b_2k`, `--engines ...`, `--steps` (2 warm-up + measured; default 10), `--timeout`, `--out`, `--profile N` (N more steps per engine traced with `torch.profiler`: GPU time per kernel category, host↔GPU copies, GPU idle; engines slower than 60 s per step are skipped; default 0), `--profile-ops` (with `--profile N`: N more steps traced with the CPU-side operations and their input shapes, listing the operations whose kernels took the most GPU time), `--repeat N` (each engine N times in fresh processes, reporting the median run and the spread; engines slower than 10 s per step run once; default 1). Each result also has `cpu_cores`, the CPU cores the engine kept busy over its measured steps. Scenarios also `lora14b_12gb` (every engine held to 12 GB of VRAM), `lora8b_llama` (Llama-3.1-8B, when downloaded) and `lora14b_var` (documents of 64–2,048 tokens packed into 2 rows of 2,048, the same for every engine; not Unsloth, which patches attention itself); engine `bnb_liger` (bitsandbytes NF4 with Liger's Triton kernels and checkpointing; Unsloth runs with `use_gradient_checkpointing="unsloth"`) |
|
|
674
|
-
| `benchmarks/quality.py` | perplexity of each quantization format, before and after a short LoRA fine-tune, with the steady training step time and the GPU's median clock while it trained | `--model`, `--formats none int8 nf4 fp8 nvfp4 nvfp4-w nvfp4-o nf4-k nf4-l nvfp4-l nf4-dq nvfp4-b` (`nvfp4-w`: 4-bit weights only, expanded before each matmul; `nvfp4-o`: tensor cores with `outliers=0.01`; `nf4-k`: `keep_precise="auto"`; `nf4-l` / `nvfp4-l`: LoRA started at the quantization error, `error_rank=16`; `nf4-dq`: `double_quant=True`; `nvfp4-b`: `nvfp4_backward=True`), `--windows`, `--seq`, `--train-steps`, `--batch`, `--lr`, `--out`; `--format F` runs one format in this process, `--live` with it streams progress as `LIVE {json}` lines and the result as `RESULT {json}` |
|
|
770
|
+
| `benchmarks/quality.py` | perplexity of each quantization format, before and after a short LoRA fine-tune, with the steady training step time and the GPU's median clock while it trained | `--model`, `--formats none int8 nf4 fp8 nvfp4 nvfp4-w nvfp4-o nf4-k nf4-l nvfp4-l nf4-dq nvfp4-b nf4-p nvfp4-p` (`nvfp4-w`: 4-bit weights only, expanded before each matmul; `nvfp4-o`: tensor cores with `outliers=0.01`; `nf4-k`: `keep_precise="auto"`; `nf4-l` / `nvfp4-l`: LoRA started at the quantization error, `error_rank=16`; `nf4-dq`: `double_quant=True`; `nvfp4-b`: `nvfp4_backward=True`; `nf4-p` / `nvfp4-p`: LoRA started at the weights' principal part, `lora_init="pissa"` with `error_rank=16`), `--windows`, `--seq`, `--train-steps`, `--batch`, `--lr`, `--out`; `--format F` runs one format in this process, `--live` with it streams progress as `LIVE {json}` lines and the result as `RESULT {json}` |
|
|
675
771
|
|
|
676
772
|
## Limitations
|
|
677
773
|
|
|
@@ -679,8 +775,10 @@ Attributes: `.policy` (per block: `"keep"`, `"offload"` or `"recompute"`), `.dec
|
|
|
679
775
|
- Quantization covers frozen block weights only (not embeddings, the output layer or trained weights) and isn't bit-exact. FP8 / NVFP4 tensor-core matmuls need a Blackwell GPU and quantize activations too; `outliers=` recovers part of the activation error, never the weights' own 4-bit error. `load_model` reads `.safetensors` causal-LM checkpoints only.
|
|
680
776
|
- `PagedKVCache` / `TrainStreamCache`: inference only, full-attention decoders, no beam search. With paged weights, every decoded token also streams the paged blocks over PCIe; a larger generation batch (which the paged cache makes room for) amortizes that.
|
|
681
777
|
- Weight paging covers the repeated block stack and needs `optimizer_mode="cpu"`; each paged weight crosses PCIe twice per step.
|
|
682
|
-
- Data parallel only (no tensor or pipeline parallelism). Ranks on one machine share host memory; tested with 2 processes on 1 GPU, not on a multi-GPU machine or across machines. Peer-GPU pooling covers frozen weights only and needs CUDA IPC and GPUs with peer access (GeForce pairs usually have none); tested with two processes on one GPU (Windows 11, WSL2), copies between two real GPUs are untested.
|
|
778
|
+
- Data parallel only (no tensor or pipeline parallelism). Ranks on one machine share host memory; tested with 2 and 3 processes on 1 GPU, not on a multi-GPU machine or across machines (the ring all-reduce included: its sockets have only carried loopback traffic). Peer-GPU pooling covers frozen weights only and needs CUDA IPC and GPUs with peer access (GeForce pairs usually have none); tested with two processes on one GPU (Windows 11, WSL2), copies between two real GPUs are untested.
|
|
683
779
|
- `TrainStreamTrainer` is single-process. fp16 with a GradScaler and AMSGrad aren't supported; `torch.compile` hasn't been tested.
|
|
780
|
+
- Checkpoints from `save_checkpoint` hold what training changes (trained parameters, optimizer state), not the frozen base.
|
|
781
|
+
- `lora_init="pissa"` covers quantized bases with one plain LoRA adapter per split matrix, and needs a lower learning rate than a zero-started LoRA (at 2e-4 it made perplexity worse on both models measured; see above); `fp8_gradients` and `moe_capacity` trade exactness for traffic and are off by default.
|
|
684
782
|
- Host AdamW speed is bounded by system RAM bandwidth.
|
|
685
783
|
|
|
686
784
|
## License
|