trainstream 0.8.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.8.0/trainstream.egg-info → trainstream-0.8.1}/PKG-INFO +77 -57
- {trainstream-0.8.0 → trainstream-0.8.1}/README.md +76 -56
- {trainstream-0.8.0 → trainstream-0.8.1}/setup.py +1 -1
- trainstream-0.8.1/tests/test_embed.py +115 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/__init__.py +1 -1
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/bindings.cpp +1 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/fused.cpp +16 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/fused_kernel.cu +33 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/kernels.h +6 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/trainstream.h +4 -0
- trainstream-0.8.1/trainstream/embed.py +107 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/wrapper.py +44 -3
- {trainstream-0.8.0 → trainstream-0.8.1/trainstream.egg-info}/PKG-INFO +77 -57
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream.egg-info/SOURCES.txt +2 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/LICENSE +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/MANIFEST.in +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/NOTICE +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/build.bat +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/pyproject.toml +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/setup.cfg +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_aio.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_arena.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_attention.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_checkpoint.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_distributed.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_dpo.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_experts.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_features.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_fp8_grads.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_fused.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_gemm.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_guard.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_huggingface.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_kvcache.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_lora_fused.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_lowp.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_multigpu.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_offload.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_optimizer.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_outliers.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_packing.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_paging.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_peer.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_pissa.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_planner.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_quality_options.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_quant.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_recompute.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/tests/test_ring.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/_build.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/attention.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/checkpoint.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/aio.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/aio.h +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/ckpt.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/disk.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/gemm_fp4_kernel.cu +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/guard.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/memory_pinner.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/offload_adamw.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/offload_adamw.h +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/offload_adamw_kernel.cu +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/peer.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/quant.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/quant_kernel.cu +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/ring.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/csrc/shm.cpp +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/disk.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/experts.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/fused.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/hooks.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/integrations/__init__.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/integrations/huggingface.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/kvcache.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/lora.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/losses.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/lowp.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/optimizer.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/packing.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/paging.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/peer.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/planner.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/profiler.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/quant.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/ring.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream/shared.py +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream.egg-info/dependency_links.txt +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream.egg-info/not-zip-safe +0 -0
- {trainstream-0.8.0 → trainstream-0.8.1}/trainstream.egg-info/requires.txt +0 -0
- {trainstream-0.8.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.8.
|
|
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,25 @@ 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
|
+
|
|
52
71
|
## What's new in 0.8
|
|
53
72
|
|
|
54
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.
|
|
@@ -162,40 +181,40 @@ Measured in the full check of 11 November 2026 on an RTX 5090 Laptop GPU (24 GB)
|
|
|
162
181
|
|
|
163
182
|
## Against other libraries (same laptop: WSL2 with a 49 GB VM, then Windows 11 with 64 GB)
|
|
164
183
|
|
|
165
|
-
> TrainStream 0.8.
|
|
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.
|
|
166
185
|
|
|
167
186
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512 (WSL2)**
|
|
168
187
|
|
|
169
188
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
170
189
|
|---|---|---|---|
|
|
171
|
-
| TrainStream, NVFP4 base (FP4 tensor cores) | 0.
|
|
172
|
-
| TrainStream, NF4 base | 0.
|
|
173
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
174
|
-
| Unsloth (4-bit) | 0.
|
|
175
|
-
| bitsandbytes QLoRA + Liger kernels | 0.
|
|
176
|
-
|
|
|
177
|
-
|
|
|
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× |
|
|
178
197
|
|
|
179
198
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 2048 (WSL2)**
|
|
180
199
|
|
|
181
200
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
182
201
|
|---|---|---|---|
|
|
183
|
-
| TrainStream, NVFP4 base | 1.
|
|
184
|
-
| TrainStream, NF4 base | 1.
|
|
185
|
-
| Unsloth (4-bit) | 2.
|
|
186
|
-
| bitsandbytes QLoRA + Liger kernels | 2.
|
|
187
|
-
| bitsandbytes QLoRA + gradient checkpointing | 2.
|
|
188
|
-
| 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× |
|
|
189
208
|
|
|
190
209
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512, every engine held to 12 GB of VRAM (WSL2)**
|
|
191
210
|
|
|
192
211
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
193
212
|
|---|---|---|---|
|
|
194
|
-
| TrainStream, NVFP4 base | 0.
|
|
195
|
-
| Unsloth (4-bit) | 0.
|
|
196
|
-
| TrainStream, NF4 base | 0.
|
|
197
|
-
| bitsandbytes QLoRA + Liger kernels | 0.
|
|
198
|
-
| 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× |
|
|
199
218
|
|
|
200
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.
|
|
201
220
|
|
|
@@ -203,11 +222,11 @@ bitsandbytes QLoRA, with or without gradient checkpointing, ran out of memory un
|
|
|
203
222
|
|
|
204
223
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
205
224
|
|---|---|---|---|
|
|
206
|
-
| TrainStream, NVFP4 base | 3.
|
|
207
|
-
| TrainStream, NF4 base | 5.
|
|
208
|
-
| bitsandbytes QLoRA + Liger kernels | 5.
|
|
209
|
-
| bitsandbytes QLoRA + gradient checkpointing | 6.
|
|
210
|
-
| TrainStream (auto) | 6.
|
|
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× |
|
|
211
230
|
|
|
212
231
|
Unsloth isn't compared here: it patches attention itself, so the harness can't check that attention stays inside each packed document.
|
|
213
232
|
|
|
@@ -215,61 +234,61 @@ Unsloth isn't compared here: it patches attention itself, so the harness can't c
|
|
|
215
234
|
|
|
216
235
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
217
236
|
|---|---|---|---|
|
|
218
|
-
| TrainStream (auto) | 1.
|
|
219
|
-
| Stock PyTorch | 1.
|
|
220
|
-
| DeepSpeed ZeRO-2, optimizer offload | 1.
|
|
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× |
|
|
221
240
|
|
|
222
241
|
**The same on Windows 11 (64 GB RAM; Unsloth, Liger and DeepSpeed aren't installed there)**
|
|
223
242
|
|
|
224
243
|
| Engine | LoRA 14B, 1 × 512 | LoRA 14B, 1 × 2048 | 14B, 12 GB VRAM | 14B, packed | Full fine-tune 1.5B |
|
|
225
244
|
|---|---|---|---|---|---|
|
|
226
|
-
| TrainStream, NVFP4 base | **0.
|
|
227
|
-
| TrainStream, NF4 base | 0.
|
|
228
|
-
| TrainStream (auto) | 0.
|
|
229
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
230
|
-
| bitsandbytes QLoRA + gradient checkpointing | 0.
|
|
231
|
-
| Stock PyTorch | spills past VRAM | spills past VRAM | — | — | 1.
|
|
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) |
|
|
232
251
|
|
|
233
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).
|
|
234
|
-
- 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.
|
|
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).
|
|
235
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.
|
|
236
|
-
- `"auto"` with 49–64 GB of RAM keeps the 14B base exact in bf16 and streams
|
|
237
|
-
- 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.
|
|
238
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.
|
|
239
|
-
-
|
|
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.
|
|
240
259
|
|
|
241
260
|
**Perplexity against bf16** (`benchmarks/quality.py`, held-out Python standard-library source; lower is better)
|
|
242
261
|
|
|
243
262
|
| Format | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
244
263
|
|---|---|---|---|---|
|
|
245
|
-
| int8 | −0.00 % | −0.
|
|
246
|
-
| FP8 (tensor cores) | +0.89 % | +0.
|
|
247
|
-
| NF4 | +3.10 % | +2.
|
|
248
|
-
| NF4, `keep_precise="auto"` | +2.89 % | +2.
|
|
249
|
-
| NF4, `error_rank=16` (LoftQ) | +3.06 % | +2.
|
|
250
|
-
| NF4, `double_quant=True` | +2.79 % | +2.
|
|
251
|
-
| NVFP4, weights only (bf16 matmuls) | +2.63 % | +2.
|
|
252
|
-
| NVFP4 (tensor cores) | +5.19 % | +4.
|
|
253
|
-
| NVFP4 with `outliers=0.01` | +4.78 % | +4.
|
|
254
|
-
| NVFP4, `error_rank=16` (LoftQ) | +5.14 % | +4.
|
|
255
|
-
| NVFP4, `nvfp4_backward=True` | +5.19 % | +
|
|
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 % |
|
|
256
275
|
|
|
257
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:
|
|
258
277
|
|
|
259
278
|
| Format, LoRA at 2e-5 | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
260
279
|
|---|---|---|---|---|
|
|
261
|
-
| NF4 | +3.10 % | +3.
|
|
262
|
-
| NF4, `lora_init="pissa"` | +2.96 % | +1.
|
|
263
|
-
| NVFP4 (tensor cores) | +5.19 % | +
|
|
264
|
-
| NVFP4, `lora_init="pissa"` | +5.27 % | +4.
|
|
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 % |
|
|
265
284
|
|
|
266
|
-
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.
|
|
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).
|
|
267
286
|
|
|
268
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`.
|
|
269
288
|
|
|
270
289
|
## Results (RTX 5090 Laptop GPU 24 GB, 64 GB RAM)
|
|
271
290
|
|
|
272
|
-
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.
|
|
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).
|
|
273
292
|
|
|
274
293
|
| Workload | Stock PyTorch | TrainStream |
|
|
275
294
|
|---|---|---|
|
|
@@ -291,7 +310,7 @@ Offloading costs throughput when a model already fits, which is why `offload="au
|
|
|
291
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)
|
|
292
311
|
- Optional, for the Hugging Face integration: `transformers`, `accelerate`, and `peft` for LoRA (all three come with `trainstream[hf]`)
|
|
293
312
|
|
|
294
|
-
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.
|
|
295
314
|
|
|
296
315
|
## Install
|
|
297
316
|
|
|
@@ -468,6 +487,7 @@ model._trainstream_session.adapting # True while it is still tuning itself
|
|
|
468
487
|
| `offload` | `"auto"`, `True` | `"auto"` | `"auto"` switches to fused torch AdamW after 2 steps if the model fits |
|
|
469
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 |
|
|
470
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 |
|
|
471
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 |
|
|
472
492
|
| `quant_block_size` | even integer ≥ 2 | `64` | values per fp32 scale (int8 / nf4; fp8 and nvfp4 use fixed 32 / 16) |
|
|
473
493
|
| `prefer` | `"exact"`, `"speed"` | `"exact"` | `"speed"` lets `quantize="auto"` choose NF4 when it keeps every layer in VRAM |
|
|
@@ -679,7 +699,7 @@ Methods and attributes:
|
|
|
679
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"` |
|
|
680
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 |
|
|
681
701
|
|
|
682
|
-
`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`).
|
|
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`).
|
|
683
703
|
|
|
684
704
|
The session behind a wrapped model is `model._trainstream_session` (`trainstream.TrainStreamSession`):
|
|
685
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
|
|
@@ -9,6 +9,25 @@ model, optimizer = trainstream.wrap(model, optimizer)
|
|
|
9
9
|
|
|
10
10
|
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.
|
|
11
11
|
|
|
12
|
+
## What's new in 0.8.1
|
|
13
|
+
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
- **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:
|
|
17
|
+
|
|
18
|
+
| Qwen2.5-14B LoRA | WSL, 0.8.0 → 0.8.1 | Windows, 0.8.0 → 0.8.1 | blocks in VRAM |
|
|
19
|
+
|---|---|---|---|
|
|
20
|
+
| NF4 base, 1 × 512, 12 GB of VRAM | 0.779 → 0.743 s | 0.730 → 0.710 s | 36–37 → 46–47 of 48 |
|
|
21
|
+
| NVFP4 base, 1 × 512, 12 GB of VRAM | 0.657 → 0.630 s | 0.569 → 0.670 s (see below) | 37 → 48 |
|
|
22
|
+
| `"auto"` (bf16 base), 1 × 512 | 0.968 → 0.838 s | 0.982 → 0.895 s | 28 → 31 |
|
|
23
|
+
| `"auto"`, 1 × 2,048 | 3.04 → 2.84 s | 3.04 → 2.82 s | 23–24 → 25–26 |
|
|
24
|
+
| `"auto"`, 1 × 512, 12 GB of VRAM | 2.13 → 1.89 s | 1.60 → 1.50 s | 9–10 → 12–13 |
|
|
25
|
+
| `"auto"`, 2 × 2,048 packed | 6.76 → 6.43 s | 6.75 → 6.61 s | 22 → 25 |
|
|
26
|
+
|
|
27
|
+
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).
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
12
31
|
## What's new in 0.8
|
|
13
32
|
|
|
14
33
|
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.
|
|
@@ -122,40 +141,40 @@ Measured in the full check of 11 November 2026 on an RTX 5090 Laptop GPU (24 GB)
|
|
|
122
141
|
|
|
123
142
|
## Against other libraries (same laptop: WSL2 with a 49 GB VM, then Windows 11 with 64 GB)
|
|
124
143
|
|
|
125
|
-
> TrainStream 0.8.
|
|
144
|
+
> 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.
|
|
126
145
|
|
|
127
146
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512 (WSL2)**
|
|
128
147
|
|
|
129
148
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
130
149
|
|---|---|---|---|
|
|
131
|
-
| TrainStream, NVFP4 base (FP4 tensor cores) | 0.
|
|
132
|
-
| TrainStream, NF4 base | 0.
|
|
133
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
134
|
-
| Unsloth (4-bit) | 0.
|
|
135
|
-
| bitsandbytes QLoRA + Liger kernels | 0.
|
|
136
|
-
|
|
|
137
|
-
|
|
|
150
|
+
| TrainStream, NVFP4 base (FP4 tensor cores) | 0.451 s | 16.8 GB | fastest |
|
|
151
|
+
| TrainStream, NF4 base | 0.537 s (3 runs: 0.536–0.541) | 16.8 GB | 1.19× |
|
|
152
|
+
| bitsandbytes QLoRA (NF4) + PEFT | 0.570 s (3 runs: 0.550–0.571) | 17.4 GB | 1.26× |
|
|
153
|
+
| Unsloth (4-bit) | 0.691 s | 11.5 GB | 1.53× |
|
|
154
|
+
| bitsandbytes QLoRA + Liger kernels | 0.787 s | 12.0 GB | 1.74× |
|
|
155
|
+
| TrainStream (auto: exact bf16 base, 17 of 48 layers streamed) | 0.838 s | 21.5 GB | 1.86× |
|
|
156
|
+
| bitsandbytes QLoRA + gradient checkpointing | 0.843 s | 12.7 GB | 1.87× |
|
|
138
157
|
|
|
139
158
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 2048 (WSL2)**
|
|
140
159
|
|
|
141
160
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
142
161
|
|---|---|---|---|
|
|
143
|
-
| TrainStream, NVFP4 base | 1.
|
|
144
|
-
| TrainStream, NF4 base | 1.
|
|
145
|
-
| Unsloth (4-bit) | 2.
|
|
146
|
-
| bitsandbytes QLoRA + Liger kernels | 2.
|
|
147
|
-
| bitsandbytes QLoRA + gradient checkpointing | 2.
|
|
148
|
-
| TrainStream (auto) |
|
|
162
|
+
| TrainStream, NVFP4 base | 1.32 s | 21.2 GB | fastest |
|
|
163
|
+
| TrainStream, NF4 base | 1.91 s | 19.2 GB | 1.45× |
|
|
164
|
+
| Unsloth (4-bit) | 2.46 s | 11.7 GB | 1.87× |
|
|
165
|
+
| bitsandbytes QLoRA + Liger kernels | 2.52 s | 13.0 GB | 1.91× |
|
|
166
|
+
| bitsandbytes QLoRA + gradient checkpointing | 2.69 s | 16.3 GB | 2.04× |
|
|
167
|
+
| TrainStream (auto) | 2.84 s | 22.6 GB | 2.15× |
|
|
149
168
|
|
|
150
169
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512, every engine held to 12 GB of VRAM (WSL2)**
|
|
151
170
|
|
|
152
171
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
153
172
|
|---|---|---|---|
|
|
154
|
-
| TrainStream, NVFP4 base | 0.
|
|
155
|
-
| Unsloth (4-bit) | 0.
|
|
156
|
-
| TrainStream, NF4 base | 0.
|
|
157
|
-
| bitsandbytes QLoRA + Liger kernels | 0.
|
|
158
|
-
| TrainStream (auto) |
|
|
173
|
+
| TrainStream, NVFP4 base | 0.630 s (3 runs: 0.627–0.646) | 11.8 GB | fastest |
|
|
174
|
+
| Unsloth (4-bit) | 0.685 s (3 runs: 0.683–0.687) | 11.4 GB | 1.09× |
|
|
175
|
+
| TrainStream, NF4 base | 0.743 s (3 runs: 0.735–0.747) | 11.5 GB | 1.18× |
|
|
176
|
+
| bitsandbytes QLoRA + Liger kernels | 0.805 s | 12.0 GB | 1.28× |
|
|
177
|
+
| TrainStream (auto) | 1.89 s | 11.8 GB | 2.99× |
|
|
159
178
|
|
|
160
179
|
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.
|
|
161
180
|
|
|
@@ -163,11 +182,11 @@ bitsandbytes QLoRA, with or without gradient checkpointing, ran out of memory un
|
|
|
163
182
|
|
|
164
183
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
165
184
|
|---|---|---|---|
|
|
166
|
-
| TrainStream, NVFP4 base | 3.
|
|
167
|
-
| TrainStream, NF4 base | 5.
|
|
168
|
-
| bitsandbytes QLoRA + Liger kernels | 5.
|
|
169
|
-
| bitsandbytes QLoRA + gradient checkpointing | 6.
|
|
170
|
-
| TrainStream (auto) | 6.
|
|
185
|
+
| TrainStream, NVFP4 base | 3.54 s | 19.9 GB | fastest |
|
|
186
|
+
| TrainStream, NF4 base | 5.31 s (3 runs: 5.30–5.42) | 19.8 GB | 1.50× |
|
|
187
|
+
| bitsandbytes QLoRA + Liger kernels | 5.74 s (3 runs: 5.72–5.82) | 14.4 GB | 1.62× |
|
|
188
|
+
| bitsandbytes QLoRA + gradient checkpointing | 6.20 s | 21.0 GB | 1.75× |
|
|
189
|
+
| TrainStream (auto) | 6.43 s | 21.3 GB | 1.82× |
|
|
171
190
|
|
|
172
191
|
Unsloth isn't compared here: it patches attention itself, so the harness can't check that attention stays inside each packed document.
|
|
173
192
|
|
|
@@ -175,61 +194,61 @@ Unsloth isn't compared here: it patches attention itself, so the harness can't c
|
|
|
175
194
|
|
|
176
195
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
177
196
|
|---|---|---|---|
|
|
178
|
-
| TrainStream (auto) | 1.
|
|
179
|
-
| Stock PyTorch | 1.
|
|
180
|
-
| DeepSpeed ZeRO-2, optimizer offload | 1.
|
|
197
|
+
| TrainStream (auto) | 1.07 s | 18.8 GB | fastest |
|
|
198
|
+
| Stock PyTorch | 1.42 s | 32.4 GB | 1.33× (spills past VRAM) |
|
|
199
|
+
| DeepSpeed ZeRO-2, optimizer offload | 1.75 s | 13.3 GB | 1.64× |
|
|
181
200
|
|
|
182
201
|
**The same on Windows 11 (64 GB RAM; Unsloth, Liger and DeepSpeed aren't installed there)**
|
|
183
202
|
|
|
184
203
|
| Engine | LoRA 14B, 1 × 512 | LoRA 14B, 1 × 2048 | 14B, 12 GB VRAM | 14B, packed | Full fine-tune 1.5B |
|
|
185
204
|
|---|---|---|---|---|---|
|
|
186
|
-
| TrainStream, NVFP4 base | **0.
|
|
187
|
-
| TrainStream, NF4 base | 0.
|
|
188
|
-
| TrainStream (auto) | 0.
|
|
189
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
190
|
-
| bitsandbytes QLoRA + gradient checkpointing | 0.
|
|
191
|
-
| Stock PyTorch | spills past VRAM | spills past VRAM | — | — | 1.
|
|
205
|
+
| TrainStream, NVFP4 base | **0.502 s** | **1.40 s** | **0.670 s** | **3.74 s** | — |
|
|
206
|
+
| TrainStream, NF4 base | 0.561 s | 2.05 s | 0.710 s | 5.46 s | — |
|
|
207
|
+
| TrainStream (auto) | 0.895 s | 2.82 s | 1.50 s | 6.61 s | **1.11 s** |
|
|
208
|
+
| bitsandbytes QLoRA (NF4) + PEFT | 0.621 s | spills past VRAM | out of memory | left out (hit the time limit in an earlier run) | — |
|
|
209
|
+
| bitsandbytes QLoRA + gradient checkpointing | 0.897 s | 2.98 s | out of memory | 6.52 s | — |
|
|
210
|
+
| Stock PyTorch | spills past VRAM | spills past VRAM | — | — | 1.45 s (spills) |
|
|
192
211
|
|
|
193
212
|
- 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).
|
|
194
|
-
- 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.
|
|
213
|
+
- 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).
|
|
195
214
|
- 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.
|
|
196
|
-
- `"auto"` with 49–64 GB of RAM keeps the 14B base exact in bf16 and streams
|
|
197
|
-
- The full fine-tune: TrainStream keeps its activations in VRAM and stays at 18.8 GB, 1.
|
|
215
|
+
- `"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.
|
|
216
|
+
- 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.
|
|
198
217
|
- 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.
|
|
199
|
-
-
|
|
218
|
+
- 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.
|
|
200
219
|
|
|
201
220
|
**Perplexity against bf16** (`benchmarks/quality.py`, held-out Python standard-library source; lower is better)
|
|
202
221
|
|
|
203
222
|
| Format | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
204
223
|
|---|---|---|---|---|
|
|
205
|
-
| int8 | −0.00 % | −0.
|
|
206
|
-
| FP8 (tensor cores) | +0.89 % | +0.
|
|
207
|
-
| NF4 | +3.10 % | +2.
|
|
208
|
-
| NF4, `keep_precise="auto"` | +2.89 % | +2.
|
|
209
|
-
| NF4, `error_rank=16` (LoftQ) | +3.06 % | +2.
|
|
210
|
-
| NF4, `double_quant=True` | +2.79 % | +2.
|
|
211
|
-
| NVFP4, weights only (bf16 matmuls) | +2.63 % | +2.
|
|
212
|
-
| NVFP4 (tensor cores) | +5.19 % | +4.
|
|
213
|
-
| NVFP4 with `outliers=0.01` | +4.78 % | +4.
|
|
214
|
-
| NVFP4, `error_rank=16` (LoftQ) | +5.14 % | +4.
|
|
215
|
-
| NVFP4, `nvfp4_backward=True` | +5.19 % | +
|
|
224
|
+
| int8 | −0.00 % | −0.02 % | +0.02 % | −0.01 % |
|
|
225
|
+
| FP8 (tensor cores) | +0.89 % | +0.70 % | +1.70 % | +1.54 % |
|
|
226
|
+
| NF4 | +3.10 % | +2.83 % | +5.94 % | +5.02 % |
|
|
227
|
+
| NF4, `keep_precise="auto"` | +2.89 % | +2.71 % | +5.27 % | +4.26 % |
|
|
228
|
+
| NF4, `error_rank=16` (LoftQ) | +3.06 % | +2.75 % | +5.76 % | +4.06 % |
|
|
229
|
+
| NF4, `double_quant=True` | +2.79 % | +2.65 % | +5.96 % | +4.95 % |
|
|
230
|
+
| NVFP4, weights only (bf16 matmuls) | +2.63 % | +2.31 % | +5.42 % | +5.00 % |
|
|
231
|
+
| NVFP4 (tensor cores) | +5.19 % | +4.81 % | +10.86 % | +10.38 % |
|
|
232
|
+
| NVFP4 with `outliers=0.01` | +4.78 % | +4.15 % | +8.99 % | +8.48 % |
|
|
233
|
+
| NVFP4, `error_rank=16` (LoftQ) | +5.14 % | +4.63 % | +10.85 % | +8.76 % |
|
|
234
|
+
| NVFP4, `nvfp4_backward=True` | +5.19 % | +5.06 % | +10.86 % | +10.16 % |
|
|
216
235
|
|
|
217
236
|
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:
|
|
218
237
|
|
|
219
238
|
| Format, LoRA at 2e-5 | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
220
239
|
|---|---|---|---|---|
|
|
221
|
-
| NF4 | +3.10 % | +3.
|
|
222
|
-
| NF4, `lora_init="pissa"` | +2.96 % | +1.
|
|
223
|
-
| NVFP4 (tensor cores) | +5.19 % | +
|
|
224
|
-
| NVFP4, `lora_init="pissa"` | +5.27 % | +4.
|
|
240
|
+
| NF4 | +3.10 % | +3.09 % | +5.94 % | +5.66 % |
|
|
241
|
+
| NF4, `lora_init="pissa"` | +2.96 % | +1.97 % | +5.47 % | +4.55 % |
|
|
242
|
+
| NVFP4 (tensor cores) | +5.19 % | +4.67 % | +10.86 % | +10.49 % |
|
|
243
|
+
| NVFP4, `lora_init="pissa"` | +5.27 % | +4.52 % | +10.20 % | +8.81 % |
|
|
225
244
|
|
|
226
|
-
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.
|
|
245
|
+
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).
|
|
227
246
|
|
|
228
247
|
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`.
|
|
229
248
|
|
|
230
249
|
## Results (RTX 5090 Laptop GPU 24 GB, 64 GB RAM)
|
|
231
250
|
|
|
232
|
-
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.
|
|
251
|
+
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).
|
|
233
252
|
|
|
234
253
|
| Workload | Stock PyTorch | TrainStream |
|
|
235
254
|
|---|---|---|
|
|
@@ -251,7 +270,7 @@ Offloading costs throughput when a model already fits, which is why `offload="au
|
|
|
251
270
|
- 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)
|
|
252
271
|
- Optional, for the Hugging Face integration: `transformers`, `accelerate`, and `peft` for LoRA (all three come with `trainstream[hf]`)
|
|
253
272
|
|
|
254
|
-
Tested on an RTX 5090 Laptop GPU with Windows 11 (PyTorch 2.14.1, CUDA 13.4, MSVC, Python 3.14), where all
|
|
273
|
+
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.
|
|
255
274
|
|
|
256
275
|
## Install
|
|
257
276
|
|
|
@@ -428,6 +447,7 @@ model._trainstream_session.adapting # True while it is still tuning itself
|
|
|
428
447
|
| `offload` | `"auto"`, `True` | `"auto"` | `"auto"` switches to fused torch AdamW after 2 steps if the model fits |
|
|
429
448
|
| `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 |
|
|
430
449
|
| `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 |
|
|
450
|
+
| `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 |
|
|
431
451
|
| `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 |
|
|
432
452
|
| `quant_block_size` | even integer ≥ 2 | `64` | values per fp32 scale (int8 / nf4; fp8 and nvfp4 use fixed 32 / 16) |
|
|
433
453
|
| `prefer` | `"exact"`, `"speed"` | `"exact"` | `"speed"` lets `quantize="auto"` choose NF4 when it keeps every layer in VRAM |
|
|
@@ -639,7 +659,7 @@ Methods and attributes:
|
|
|
639
659
|
| `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"` |
|
|
640
660
|
| `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 |
|
|
641
661
|
|
|
642
|
-
`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`).
|
|
662
|
+
`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`).
|
|
643
663
|
|
|
644
664
|
The session behind a wrapped model is `model._trainstream_session` (`trainstream.TrainStreamSession`):
|
|
645
665
|
- `.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
|
|
@@ -87,7 +87,7 @@ with open(os.path.join(HERE, "README.md"), encoding="utf-8") as fh:
|
|
|
87
87
|
|
|
88
88
|
setup(
|
|
89
89
|
name="trainstream",
|
|
90
|
-
version="0.8.
|
|
90
|
+
version="0.8.1",
|
|
91
91
|
author="John Anish G",
|
|
92
92
|
license="Apache-2.0",
|
|
93
93
|
description="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.",
|