trainstream 0.8.1__tar.gz → 0.8.2__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.1/trainstream.egg-info → trainstream-0.8.2}/PKG-INFO +72 -57
- {trainstream-0.8.1 → trainstream-0.8.2}/README.md +71 -56
- {trainstream-0.8.1 → trainstream-0.8.2}/setup.py +1 -1
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_attention.py +24 -0
- trainstream-0.8.2/tests/test_graphs.py +354 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/__init__.py +1 -1
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/attention.py +28 -0
- trainstream-0.8.2/trainstream/graphs.py +723 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/optimizer.py +7 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/paging.py +51 -5
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/wrapper.py +86 -0
- {trainstream-0.8.1 → trainstream-0.8.2/trainstream.egg-info}/PKG-INFO +72 -57
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream.egg-info/SOURCES.txt +2 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/LICENSE +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/MANIFEST.in +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/NOTICE +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/build.bat +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/pyproject.toml +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/setup.cfg +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_aio.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_arena.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_checkpoint.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_distributed.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_dpo.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_embed.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_experts.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_features.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_fp8_grads.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_fused.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_gemm.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_guard.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_huggingface.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_kvcache.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_lora_fused.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_lowp.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_multigpu.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_offload.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_optimizer.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_outliers.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_packing.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_paging.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_peer.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_pissa.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_planner.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_quality_options.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_quant.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_recompute.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/tests/test_ring.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/_build.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/checkpoint.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/aio.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/aio.h +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/bindings.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/ckpt.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/disk.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/fused.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/fused_kernel.cu +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/gemm_fp4_kernel.cu +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/guard.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/kernels.h +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/memory_pinner.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/offload_adamw.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/offload_adamw.h +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/offload_adamw_kernel.cu +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/peer.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/quant.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/quant_kernel.cu +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/ring.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/shm.cpp +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/csrc/trainstream.h +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/disk.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/embed.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/experts.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/fused.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/hooks.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/integrations/__init__.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/integrations/huggingface.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/kvcache.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/lora.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/losses.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/lowp.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/packing.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/peer.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/planner.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/profiler.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/quant.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/ring.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream/shared.py +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream.egg-info/dependency_links.txt +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream.egg-info/not-zip-safe +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/trainstream.egg-info/requires.txt +0 -0
- {trainstream-0.8.1 → trainstream-0.8.2}/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.2
|
|
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,20 @@ 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.2
|
|
53
|
+
|
|
54
|
+
- **Transformer blocks run as CUDA graphs** (`cuda_graphs="auto"`). At small batches TrainStream's Python launched kernels more slowly than the GPU ran them: one training step of Qwen2.5-14B LoRA on an NVFP4 base at 512 tokens is about 10,600 kernels, and in a traced step the GPU stood idle between them for about 105 ms and, never fully busy, ran at a lower clock. Now, once a run has settled with nothing moving during a step (the optimizer in VRAM, every block's weights in VRAM as bf16 or as fp8 / nvfp4 on tensor cores, activations kept), each block's forward and backward are recorded once as two CUDA graphs and replayed from then on: the same kernels on the same memory, so gradients are bit-identical (checked on Qwen2.5-14B: the loss and all 672 LoRA gradients of a step). Measured on Qwen2.5-14B, LoRA r=16, NVFP4 base, batch 1 × 512, RTX 5090 Laptop GPU:
|
|
55
|
+
|
|
56
|
+
| | without graphs | with graphs |
|
|
57
|
+
|---|---|---|
|
|
58
|
+
| Windows, alternating runs (30 November, 3 each) | 0.509 / 0.515 / 0.521 s | 0.361 / 0.378 / 0.377 s (27–29 % faster) |
|
|
59
|
+
| Windows, full checks: 0.8.1's (30 November) and 0.8.2's (1 December) | 0.502 s, 1.24× bitsandbytes | 0.356 s, 1.61× bitsandbytes |
|
|
60
|
+
| WSL, the same two full checks | 0.451 s, 1.26× bitsandbytes | 0.360 s, 1.66× bitsandbytes |
|
|
61
|
+
| Qwen2.5-1.5B LoRA, batch 2 × 1024 (`benchmarks/quality.py`, Windows, 0.8.1's and 0.8.2's quality runs of 30 November): NVFP4 / FP8 / bf16 | 0.259 / 0.235 / 0.294 s | 0.206 / 0.210 / 0.283 s |
|
|
62
|
+
|
|
63
|
+
In 0.8.2's full check every rival ran 5–15 % slower than in 0.8.1's (bitsandbytes 0.570 → 0.599 s in WSL), so the step times understate the change; the ratios against bitsandbytes don't. Peak VRAM did not change (16.79 against 16.78 GB): the graphs keep one step's activations (1.26 GiB here) in a memory pool of their own, as the eager step held them. Where graphs do not engage, nothing changes: NF4 and int8 bases (their weights are expanded block by block on a copy stream beside the compute; inside a graph that expansion would run in line and cost more than graphs save), blocks streamed from RAM, activations paged or recomputed (in the benchmarks: 2,048 tokens, packed documents, the 12 GB cap), the host optimizer, data parallel. A forward whose inputs differ from the recorded ones, without gradients, in eval mode, under activation checkpointing, or before the previous forward's backward has run, runs eagerly as before. `memory_report()["graphs"]` says what happened and why; `cuda_graphs=False` turns it off.
|
|
64
|
+
- **Fix: Hugging Face gradient checkpointing with `attention="auto"`** (since 0.5). A layer that `gradient_checkpointing_enable()` runs again in backward ran outside the attention-backend order its forward used, so it could pick PyTorch's default kernel instead (on an RTX 50-series GPU, where cuDNN's attention is chosen, it did), and `torch.utils.checkpoint` stopped training with a `CheckpointError` about mismatched saved tensors. Blocks recomputed inside backward now re-enter their forward's order.
|
|
65
|
+
|
|
52
66
|
## What's new in 0.8.1
|
|
53
67
|
|
|
54
68
|
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.
|
|
@@ -181,40 +195,40 @@ Measured in the full check of 11 November 2026 on an RTX 5090 Laptop GPU (24 GB)
|
|
|
181
195
|
|
|
182
196
|
## Against other libraries (same laptop: WSL2 with a 49 GB VM, then Windows 11 with 64 GB)
|
|
183
197
|
|
|
184
|
-
> TrainStream 0.8.
|
|
198
|
+
> TrainStream 0.8.2: performance from the full check of 1 December 2026, tests and quality from those of 30 November and 1 December. Each engine runs in a fresh process, 10 steps after its warm-up (TrainStream: after it has finished tuning itself, and recording its CUDA graphs where it does), 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–15 % for every engine alike (in this one every rival ran 5–15 % slower than in 0.8.1's), so compare engines within a table, and read smaller differences as noise.
|
|
185
199
|
|
|
186
200
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512 (WSL2)**
|
|
187
201
|
|
|
188
202
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
189
203
|
|---|---|---|---|
|
|
190
|
-
| TrainStream, NVFP4 base (FP4 tensor cores) | 0.
|
|
191
|
-
| TrainStream, NF4 base | 0.
|
|
192
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
193
|
-
| Unsloth (4-bit) | 0.
|
|
194
|
-
| bitsandbytes QLoRA +
|
|
195
|
-
|
|
|
196
|
-
|
|
|
204
|
+
| TrainStream, NVFP4 base (FP4 tensor cores, CUDA graphs) | 0.360 s | 16.8 GB | fastest |
|
|
205
|
+
| TrainStream, NF4 base | 0.567 s (3 runs: 0.553–0.574) | 16.8 GB | 1.58× |
|
|
206
|
+
| bitsandbytes QLoRA (NF4) + PEFT | 0.599 s (3 runs: 0.596–0.608) | 17.4 GB | 1.66× |
|
|
207
|
+
| Unsloth (4-bit) | 0.767 s | 11.5 GB | 2.13× |
|
|
208
|
+
| bitsandbytes QLoRA + gradient checkpointing | 0.864 s | 12.7 GB | 2.40× |
|
|
209
|
+
| bitsandbytes QLoRA + Liger kernels | 0.873 s | 12.0 GB | 2.43× |
|
|
210
|
+
| TrainStream (auto: exact bf16 base, 17 of 48 layers streamed) | 0.948 s | 21.5 GB | 2.63× |
|
|
197
211
|
|
|
198
212
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 2048 (WSL2)**
|
|
199
213
|
|
|
200
214
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
201
215
|
|---|---|---|---|
|
|
202
|
-
| TrainStream, NVFP4 base | 1.
|
|
203
|
-
| TrainStream, NF4 base |
|
|
204
|
-
| Unsloth (4-bit) | 2.
|
|
205
|
-
| bitsandbytes QLoRA + Liger kernels | 2.
|
|
206
|
-
| bitsandbytes QLoRA + gradient checkpointing |
|
|
207
|
-
| TrainStream (auto) |
|
|
216
|
+
| TrainStream, NVFP4 base | 1.49 s | 21.2 GB | fastest |
|
|
217
|
+
| TrainStream, NF4 base | 2.40 s | 19.3 GB | 1.61× |
|
|
218
|
+
| Unsloth (4-bit) | 2.73 s | 11.7 GB | 1.83× |
|
|
219
|
+
| bitsandbytes QLoRA + Liger kernels | 2.90 s | 13.0 GB | 1.95× |
|
|
220
|
+
| bitsandbytes QLoRA + gradient checkpointing | 3.02 s | 16.3 GB | 2.02× |
|
|
221
|
+
| TrainStream (auto) | 3.12 s | 23.1 GB | 2.10× |
|
|
208
222
|
|
|
209
223
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512, every engine held to 12 GB of VRAM (WSL2)**
|
|
210
224
|
|
|
211
225
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
212
226
|
|---|---|---|---|
|
|
213
|
-
| TrainStream, NVFP4 base | 0.
|
|
214
|
-
|
|
|
215
|
-
|
|
|
216
|
-
| bitsandbytes QLoRA + Liger kernels | 0.
|
|
217
|
-
| TrainStream (auto) |
|
|
227
|
+
| TrainStream, NVFP4 base | 0.575 s | 11.8 GB | fastest |
|
|
228
|
+
| TrainStream, NF4 base | 0.702 s (3 runs: 0.682–0.769) | 11.5 GB | 1.22× |
|
|
229
|
+
| Unsloth (4-bit) | 0.767 s (3 runs: 0.765–0.771) | 11.4 GB | 1.33× |
|
|
230
|
+
| bitsandbytes QLoRA + Liger kernels | 0.862 s | 12.0 GB | 1.50× |
|
|
231
|
+
| TrainStream (auto) | 2.08 s | 11.8 GB | 3.61× |
|
|
218
232
|
|
|
219
233
|
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.
|
|
220
234
|
|
|
@@ -222,11 +236,11 @@ bitsandbytes QLoRA, with or without gradient checkpointing, ran out of memory un
|
|
|
222
236
|
|
|
223
237
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
224
238
|
|---|---|---|---|
|
|
225
|
-
| TrainStream, NVFP4 base | 3.
|
|
226
|
-
| TrainStream, NF4 base | 5.
|
|
227
|
-
| bitsandbytes QLoRA + Liger kernels |
|
|
228
|
-
| bitsandbytes QLoRA + gradient checkpointing |
|
|
229
|
-
| TrainStream (auto) |
|
|
239
|
+
| TrainStream, NVFP4 base | 3.98 s | 19.9 GB | fastest |
|
|
240
|
+
| TrainStream, NF4 base | 5.76 s | 19.8 GB | 1.45× |
|
|
241
|
+
| bitsandbytes QLoRA + Liger kernels | 6.40 s | 14.4 GB | 1.61× |
|
|
242
|
+
| bitsandbytes QLoRA + gradient checkpointing | 7.06 s | 21.0 GB | 1.77× |
|
|
243
|
+
| TrainStream (auto) | 7.26 s | 21.3 GB | 1.82× |
|
|
230
244
|
|
|
231
245
|
Unsloth isn't compared here: it patches attention itself, so the harness can't check that attention stays inside each packed document.
|
|
232
246
|
|
|
@@ -234,61 +248,61 @@ Unsloth isn't compared here: it patches attention itself, so the harness can't c
|
|
|
234
248
|
|
|
235
249
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
236
250
|
|---|---|---|---|
|
|
237
|
-
| TrainStream (auto) | 1.
|
|
238
|
-
| Stock PyTorch | 1.
|
|
239
|
-
| DeepSpeed ZeRO-2, optimizer offload | 1.
|
|
251
|
+
| TrainStream (auto) | 1.13 s | 18.8 GB | fastest |
|
|
252
|
+
| Stock PyTorch | 1.63 s | 32.4 GB | 1.45× (spills past VRAM) |
|
|
253
|
+
| DeepSpeed ZeRO-2, optimizer offload | 1.81 s | 13.3 GB | 1.61× |
|
|
240
254
|
|
|
241
255
|
**The same on Windows 11 (64 GB RAM; Unsloth, Liger and DeepSpeed aren't installed there)**
|
|
242
256
|
|
|
243
257
|
| Engine | LoRA 14B, 1 × 512 | LoRA 14B, 1 × 2048 | 14B, 12 GB VRAM | 14B, packed | Full fine-tune 1.5B |
|
|
244
258
|
|---|---|---|---|---|---|
|
|
245
|
-
| TrainStream, NVFP4 base | **0.
|
|
246
|
-
| TrainStream, NF4 base | 0.
|
|
247
|
-
| TrainStream (auto) |
|
|
248
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
249
|
-
| bitsandbytes QLoRA + gradient checkpointing | 0.
|
|
250
|
-
| Stock PyTorch | spills past VRAM | spills past VRAM | — | — |
|
|
251
|
-
|
|
252
|
-
- With an NVFP4 base TrainStream had the fastest step in every 14B scenario, in WSL and on Windows
|
|
253
|
-
- With an NF4 base, the format bitsandbytes and Unsloth use, TrainStream was ahead of every rival in every scenario
|
|
259
|
+
| TrainStream, NVFP4 base | **0.356 s** | **1.48 s** | **0.560 s** | **3.80 s** | — |
|
|
260
|
+
| TrainStream, NF4 base | 0.542 s | 2.18 s | 0.642 s | 5.87 s | — |
|
|
261
|
+
| TrainStream (auto) | 1.02 s | 3.08 s | 1.50 s | 6.98 s | **1.08 s** |
|
|
262
|
+
| bitsandbytes QLoRA (NF4) + PEFT | 0.572 s | spills past VRAM | out of memory | left out (hit the time limit in an earlier run) | — |
|
|
263
|
+
| bitsandbytes QLoRA + gradient checkpointing | 0.877 s | 3.13 s | out of memory | 6.99 s | — |
|
|
264
|
+
| Stock PyTorch | spills past VRAM | spills past VRAM | — | — | 2.40 s (spills) |
|
|
265
|
+
|
|
266
|
+
- With an NVFP4 base TrainStream had the fastest step in every 14B scenario, in WSL and on Windows. At 512 tokens its blocks now run as CUDA graphs: 1.66× bitsandbytes in WSL and 1.61× on Windows (1.26× and 1.24× in 0.8.1's check). NVFP4 costs quality (see the perplexity table below).
|
|
267
|
+
- With an NF4 base, the format bitsandbytes and Unsloth use, TrainStream was ahead of every rival in every scenario. Held to 12 GB of VRAM its median run was 1.09× Unsloth's (0.702 s against 0.767 s), though the slowest of its three runs (0.769 s) was level with Unsloth's (in 0.8.1's check Unsloth was 1.08× faster). At 512 tokens its lead over bitsandbytes is small (1.06× in WSL and on Windows): NF4 blocks don't run as graphs.
|
|
254
268
|
- 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.
|
|
255
269
|
- `"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.
|
|
270
|
+
- The full fine-tune: TrainStream keeps its activations in VRAM and stays at 18.8 GB, 1.45× faster than stock PyTorch in WSL. 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 (2.40 s on Windows in this run, 1.45 s in 0.8.1's).
|
|
257
271
|
- 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
|
|
272
|
+
- Between the two environments every engine was within 10 % of its time in the other, except `"auto"` under the 12 GB cap, 1.39× slower in WSL (2.08 s against 1.50 s), and stock PyTorch's full fine-tune, which spills.
|
|
259
273
|
|
|
260
274
|
**Perplexity against bf16** (`benchmarks/quality.py`, held-out Python standard-library source; lower is better)
|
|
261
275
|
|
|
262
276
|
| Format | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
263
277
|
|---|---|---|---|---|
|
|
264
|
-
| int8 | −0.00 % |
|
|
265
|
-
| FP8 (tensor cores) | +0.89 % | +0.
|
|
266
|
-
| NF4 | +3.10 % | +2.
|
|
267
|
-
| NF4, `keep_precise="auto"` | +2.89 % | +2.
|
|
268
|
-
| NF4, `error_rank=16` (LoftQ) | +3.06 % | +2.
|
|
278
|
+
| int8 | −0.00 % | +0.07 % | +0.02 % | +0.02 % |
|
|
279
|
+
| FP8 (tensor cores) | +0.89 % | +0.80 % | +1.70 % | +1.40 % |
|
|
280
|
+
| NF4 | +3.10 % | +2.86 % | +5.94 % | +5.00 % |
|
|
281
|
+
| NF4, `keep_precise="auto"` | +2.89 % | +2.69 % | +5.27 % | +4.29 % |
|
|
282
|
+
| NF4, `error_rank=16` (LoftQ) | +3.06 % | +2.81 % | +5.76 % | +4.09 % |
|
|
269
283
|
| NF4, `double_quant=True` | +2.79 % | +2.65 % | +5.96 % | +4.95 % |
|
|
270
|
-
| NVFP4, weights only (bf16 matmuls) | +2.63 % | +2.
|
|
271
|
-
| NVFP4 (tensor cores) | +5.19 % | +4.
|
|
272
|
-
| NVFP4 with `outliers=0.01` | +4.78 % | +4.
|
|
273
|
-
| NVFP4, `error_rank=16` (LoftQ) | +5.14 % | +4.
|
|
274
|
-
| NVFP4, `nvfp4_backward=True` | +5.19 % | +5.
|
|
284
|
+
| NVFP4, weights only (bf16 matmuls) | +2.63 % | +2.30 % | +5.42 % | +5.02 % |
|
|
285
|
+
| NVFP4 (tensor cores) | +5.19 % | +4.54 % | +10.86 % | +10.17 % |
|
|
286
|
+
| NVFP4 with `outliers=0.01` | +4.78 % | +4.28 % | +8.99 % | +8.88 % |
|
|
287
|
+
| NVFP4, `error_rank=16` (LoftQ) | +5.14 % | +4.78 % | +10.85 % | +8.68 % |
|
|
288
|
+
| NVFP4, `nvfp4_backward=True` | +5.19 % | +5.02 % | +10.86 % | +10.08 % |
|
|
275
289
|
|
|
276
290
|
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
291
|
|
|
278
292
|
| Format, LoRA at 2e-5 | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
279
293
|
|---|---|---|---|---|
|
|
280
|
-
| NF4 | +3.10 % | +3.
|
|
281
|
-
| NF4, `lora_init="pissa"` | +2.96 % | +1.
|
|
282
|
-
| NVFP4 (tensor cores) | +5.19 % | +
|
|
283
|
-
| NVFP4, `lora_init="pissa"` | +5.27 % | +4.
|
|
294
|
+
| NF4 | +3.10 % | +3.10 % | +5.94 % | +5.69 % |
|
|
295
|
+
| NF4, `lora_init="pissa"` | +2.96 % | +1.95 % | +5.47 % | +4.57 % |
|
|
296
|
+
| NVFP4 (tensor cores) | +5.19 % | +5.02 % | +10.86 % | +10.62 % |
|
|
297
|
+
| NVFP4, `lora_init="pissa"` | +5.27 % | +4.46 % | +10.20 % | +8.72 % |
|
|
284
298
|
|
|
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.
|
|
299
|
+
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.46 % against +5.02 %) it was within it (it was 1.20 points in 0.8.0's).
|
|
286
300
|
|
|
287
301
|
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`.
|
|
288
302
|
|
|
289
303
|
## Results (RTX 5090 Laptop GPU 24 GB, 64 GB RAM)
|
|
290
304
|
|
|
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.
|
|
305
|
+
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.2).
|
|
292
306
|
|
|
293
307
|
| Workload | Stock PyTorch | TrainStream |
|
|
294
308
|
|---|---|---|
|
|
@@ -310,7 +324,7 @@ Offloading costs throughput when a model already fits, which is why `offload="au
|
|
|
310
324
|
- 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)
|
|
311
325
|
- Optional, for the Hugging Face integration: `transformers`, `accelerate`, and `peft` for LoRA (all three come with `trainstream[hf]`)
|
|
312
326
|
|
|
313
|
-
Tested on an RTX 5090 Laptop GPU with Windows 11 (PyTorch 2.14.1, CUDA 13.4, MSVC, Python 3.14), where all
|
|
327
|
+
Tested on an RTX 5090 Laptop GPU with Windows 11 (PyTorch 2.14.1, CUDA 13.4, MSVC, Python 3.14), where all 487 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 487 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.
|
|
314
328
|
|
|
315
329
|
## Install
|
|
316
330
|
|
|
@@ -514,6 +528,7 @@ model._trainstream_session.adapting # True while it is still tuning itself
|
|
|
514
528
|
| `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 |
|
|
515
529
|
| `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 |
|
|
516
530
|
| `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 |
|
|
531
|
+
| `cuda_graphs` | `"auto"`, `True`, `False`, `None` | `"auto"` | run each block's forward and backward as two recorded CUDA graphs instead of launching their kernels one by one from Python. At small batches the host launches kernels more slowly than the GPU runs them; replayed graphs keep the GPU busy (and at a higher clock). The same kernels on the same memory: gradients are bit-identical. `"auto"`: recorded between two steps once TrainStream runs with nothing moving during a step (optimizer in VRAM, every block's weights in VRAM as bf16 or as fp8 / nvfp4 on tensor cores, activations kept, one process) and the blocks' inputs have had the same shapes for two steps. Anything else runs eagerly as before: no gradients, eval mode, other input shapes (recorded again once they hold, up to 4 recordings), two forwards before a backward, activation checkpointing, switched adapters (the full list is in `trainstream.graphs`). The graphs hold one step's activations in a memory pool of their own. A training forward through graphed blocks leaves a Hugging Face KV cache empty (training never reads it). `True`: the same, plus a warning when the run doesn't qualify; `False` / `None`: never |
|
|
517
532
|
| `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 |
|
|
518
533
|
| `device` | `None`, `"cuda"`, `"cuda:N"`, `torch.device` | `None` | target GPU when the model is on the CPU |
|
|
519
534
|
| `blocks` | `None`, list of layer modules | `None` | the repeated layer stack; auto-detected |
|
|
@@ -699,7 +714,7 @@ Methods and attributes:
|
|
|
699
714
|
| `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
715
|
| `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
716
|
|
|
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`).
|
|
717
|
+
`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`). Added in 0.8.2: `"graphs"` unless `cuda_graphs=False` (`mode`; `state`: `"not started"`, `"watching"` (about to record), `"captured"` or `"off"`; `reason` it is off; `blocks`; `captures`: recordings so far; `capture_s`: seconds they took; `pool_bytes`: VRAM the recorded graphs hold for one step's activations; `replays`: block forwards run as graphs; `eager`: block calls that ran eagerly, counted by reason).
|
|
703
718
|
|
|
704
719
|
The session behind a wrapped model is `model._trainstream_session` (`trainstream.TrainStreamSession`):
|
|
705
720
|
- `.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,20 @@ 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.2
|
|
13
|
+
|
|
14
|
+
- **Transformer blocks run as CUDA graphs** (`cuda_graphs="auto"`). At small batches TrainStream's Python launched kernels more slowly than the GPU ran them: one training step of Qwen2.5-14B LoRA on an NVFP4 base at 512 tokens is about 10,600 kernels, and in a traced step the GPU stood idle between them for about 105 ms and, never fully busy, ran at a lower clock. Now, once a run has settled with nothing moving during a step (the optimizer in VRAM, every block's weights in VRAM as bf16 or as fp8 / nvfp4 on tensor cores, activations kept), each block's forward and backward are recorded once as two CUDA graphs and replayed from then on: the same kernels on the same memory, so gradients are bit-identical (checked on Qwen2.5-14B: the loss and all 672 LoRA gradients of a step). Measured on Qwen2.5-14B, LoRA r=16, NVFP4 base, batch 1 × 512, RTX 5090 Laptop GPU:
|
|
15
|
+
|
|
16
|
+
| | without graphs | with graphs |
|
|
17
|
+
|---|---|---|
|
|
18
|
+
| Windows, alternating runs (30 November, 3 each) | 0.509 / 0.515 / 0.521 s | 0.361 / 0.378 / 0.377 s (27–29 % faster) |
|
|
19
|
+
| Windows, full checks: 0.8.1's (30 November) and 0.8.2's (1 December) | 0.502 s, 1.24× bitsandbytes | 0.356 s, 1.61× bitsandbytes |
|
|
20
|
+
| WSL, the same two full checks | 0.451 s, 1.26× bitsandbytes | 0.360 s, 1.66× bitsandbytes |
|
|
21
|
+
| Qwen2.5-1.5B LoRA, batch 2 × 1024 (`benchmarks/quality.py`, Windows, 0.8.1's and 0.8.2's quality runs of 30 November): NVFP4 / FP8 / bf16 | 0.259 / 0.235 / 0.294 s | 0.206 / 0.210 / 0.283 s |
|
|
22
|
+
|
|
23
|
+
In 0.8.2's full check every rival ran 5–15 % slower than in 0.8.1's (bitsandbytes 0.570 → 0.599 s in WSL), so the step times understate the change; the ratios against bitsandbytes don't. Peak VRAM did not change (16.79 against 16.78 GB): the graphs keep one step's activations (1.26 GiB here) in a memory pool of their own, as the eager step held them. Where graphs do not engage, nothing changes: NF4 and int8 bases (their weights are expanded block by block on a copy stream beside the compute; inside a graph that expansion would run in line and cost more than graphs save), blocks streamed from RAM, activations paged or recomputed (in the benchmarks: 2,048 tokens, packed documents, the 12 GB cap), the host optimizer, data parallel. A forward whose inputs differ from the recorded ones, without gradients, in eval mode, under activation checkpointing, or before the previous forward's backward has run, runs eagerly as before. `memory_report()["graphs"]` says what happened and why; `cuda_graphs=False` turns it off.
|
|
24
|
+
- **Fix: Hugging Face gradient checkpointing with `attention="auto"`** (since 0.5). A layer that `gradient_checkpointing_enable()` runs again in backward ran outside the attention-backend order its forward used, so it could pick PyTorch's default kernel instead (on an RTX 50-series GPU, where cuDNN's attention is chosen, it did), and `torch.utils.checkpoint` stopped training with a `CheckpointError` about mismatched saved tensors. Blocks recomputed inside backward now re-enter their forward's order.
|
|
25
|
+
|
|
12
26
|
## What's new in 0.8.1
|
|
13
27
|
|
|
14
28
|
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.
|
|
@@ -141,40 +155,40 @@ Measured in the full check of 11 November 2026 on an RTX 5090 Laptop GPU (24 GB)
|
|
|
141
155
|
|
|
142
156
|
## Against other libraries (same laptop: WSL2 with a 49 GB VM, then Windows 11 with 64 GB)
|
|
143
157
|
|
|
144
|
-
> TrainStream 0.8.
|
|
158
|
+
> TrainStream 0.8.2: performance from the full check of 1 December 2026, tests and quality from those of 30 November and 1 December. Each engine runs in a fresh process, 10 steps after its warm-up (TrainStream: after it has finished tuning itself, and recording its CUDA graphs where it does), 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–15 % for every engine alike (in this one every rival ran 5–15 % slower than in 0.8.1's), so compare engines within a table, and read smaller differences as noise.
|
|
145
159
|
|
|
146
160
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512 (WSL2)**
|
|
147
161
|
|
|
148
162
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
149
163
|
|---|---|---|---|
|
|
150
|
-
| TrainStream, NVFP4 base (FP4 tensor cores) | 0.
|
|
151
|
-
| TrainStream, NF4 base | 0.
|
|
152
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
153
|
-
| Unsloth (4-bit) | 0.
|
|
154
|
-
| bitsandbytes QLoRA +
|
|
155
|
-
|
|
|
156
|
-
|
|
|
164
|
+
| TrainStream, NVFP4 base (FP4 tensor cores, CUDA graphs) | 0.360 s | 16.8 GB | fastest |
|
|
165
|
+
| TrainStream, NF4 base | 0.567 s (3 runs: 0.553–0.574) | 16.8 GB | 1.58× |
|
|
166
|
+
| bitsandbytes QLoRA (NF4) + PEFT | 0.599 s (3 runs: 0.596–0.608) | 17.4 GB | 1.66× |
|
|
167
|
+
| Unsloth (4-bit) | 0.767 s | 11.5 GB | 2.13× |
|
|
168
|
+
| bitsandbytes QLoRA + gradient checkpointing | 0.864 s | 12.7 GB | 2.40× |
|
|
169
|
+
| bitsandbytes QLoRA + Liger kernels | 0.873 s | 12.0 GB | 2.43× |
|
|
170
|
+
| TrainStream (auto: exact bf16 base, 17 of 48 layers streamed) | 0.948 s | 21.5 GB | 2.63× |
|
|
157
171
|
|
|
158
172
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 2048 (WSL2)**
|
|
159
173
|
|
|
160
174
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
161
175
|
|---|---|---|---|
|
|
162
|
-
| TrainStream, NVFP4 base | 1.
|
|
163
|
-
| TrainStream, NF4 base |
|
|
164
|
-
| Unsloth (4-bit) | 2.
|
|
165
|
-
| bitsandbytes QLoRA + Liger kernels | 2.
|
|
166
|
-
| bitsandbytes QLoRA + gradient checkpointing |
|
|
167
|
-
| TrainStream (auto) |
|
|
176
|
+
| TrainStream, NVFP4 base | 1.49 s | 21.2 GB | fastest |
|
|
177
|
+
| TrainStream, NF4 base | 2.40 s | 19.3 GB | 1.61× |
|
|
178
|
+
| Unsloth (4-bit) | 2.73 s | 11.7 GB | 1.83× |
|
|
179
|
+
| bitsandbytes QLoRA + Liger kernels | 2.90 s | 13.0 GB | 1.95× |
|
|
180
|
+
| bitsandbytes QLoRA + gradient checkpointing | 3.02 s | 16.3 GB | 2.02× |
|
|
181
|
+
| TrainStream (auto) | 3.12 s | 23.1 GB | 2.10× |
|
|
168
182
|
|
|
169
183
|
**LoRA r=16, Qwen2.5-14B, batch 1 × 512, every engine held to 12 GB of VRAM (WSL2)**
|
|
170
184
|
|
|
171
185
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
172
186
|
|---|---|---|---|
|
|
173
|
-
| TrainStream, NVFP4 base | 0.
|
|
174
|
-
|
|
|
175
|
-
|
|
|
176
|
-
| bitsandbytes QLoRA + Liger kernels | 0.
|
|
177
|
-
| TrainStream (auto) |
|
|
187
|
+
| TrainStream, NVFP4 base | 0.575 s | 11.8 GB | fastest |
|
|
188
|
+
| TrainStream, NF4 base | 0.702 s (3 runs: 0.682–0.769) | 11.5 GB | 1.22× |
|
|
189
|
+
| Unsloth (4-bit) | 0.767 s (3 runs: 0.765–0.771) | 11.4 GB | 1.33× |
|
|
190
|
+
| bitsandbytes QLoRA + Liger kernels | 0.862 s | 12.0 GB | 1.50× |
|
|
191
|
+
| TrainStream (auto) | 2.08 s | 11.8 GB | 3.61× |
|
|
178
192
|
|
|
179
193
|
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.
|
|
180
194
|
|
|
@@ -182,11 +196,11 @@ bitsandbytes QLoRA, with or without gradient checkpointing, ran out of memory un
|
|
|
182
196
|
|
|
183
197
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
184
198
|
|---|---|---|---|
|
|
185
|
-
| TrainStream, NVFP4 base | 3.
|
|
186
|
-
| TrainStream, NF4 base | 5.
|
|
187
|
-
| bitsandbytes QLoRA + Liger kernels |
|
|
188
|
-
| bitsandbytes QLoRA + gradient checkpointing |
|
|
189
|
-
| TrainStream (auto) |
|
|
199
|
+
| TrainStream, NVFP4 base | 3.98 s | 19.9 GB | fastest |
|
|
200
|
+
| TrainStream, NF4 base | 5.76 s | 19.8 GB | 1.45× |
|
|
201
|
+
| bitsandbytes QLoRA + Liger kernels | 6.40 s | 14.4 GB | 1.61× |
|
|
202
|
+
| bitsandbytes QLoRA + gradient checkpointing | 7.06 s | 21.0 GB | 1.77× |
|
|
203
|
+
| TrainStream (auto) | 7.26 s | 21.3 GB | 1.82× |
|
|
190
204
|
|
|
191
205
|
Unsloth isn't compared here: it patches attention itself, so the harness can't check that attention stays inside each packed document.
|
|
192
206
|
|
|
@@ -194,61 +208,61 @@ Unsloth isn't compared here: it patches attention itself, so the harness can't c
|
|
|
194
208
|
|
|
195
209
|
| Engine | Step time | Peak VRAM | Against the fastest |
|
|
196
210
|
|---|---|---|---|
|
|
197
|
-
| TrainStream (auto) | 1.
|
|
198
|
-
| Stock PyTorch | 1.
|
|
199
|
-
| DeepSpeed ZeRO-2, optimizer offload | 1.
|
|
211
|
+
| TrainStream (auto) | 1.13 s | 18.8 GB | fastest |
|
|
212
|
+
| Stock PyTorch | 1.63 s | 32.4 GB | 1.45× (spills past VRAM) |
|
|
213
|
+
| DeepSpeed ZeRO-2, optimizer offload | 1.81 s | 13.3 GB | 1.61× |
|
|
200
214
|
|
|
201
215
|
**The same on Windows 11 (64 GB RAM; Unsloth, Liger and DeepSpeed aren't installed there)**
|
|
202
216
|
|
|
203
217
|
| Engine | LoRA 14B, 1 × 512 | LoRA 14B, 1 × 2048 | 14B, 12 GB VRAM | 14B, packed | Full fine-tune 1.5B |
|
|
204
218
|
|---|---|---|---|---|---|
|
|
205
|
-
| TrainStream, NVFP4 base | **0.
|
|
206
|
-
| TrainStream, NF4 base | 0.
|
|
207
|
-
| TrainStream (auto) |
|
|
208
|
-
| bitsandbytes QLoRA (NF4) + PEFT | 0.
|
|
209
|
-
| bitsandbytes QLoRA + gradient checkpointing | 0.
|
|
210
|
-
| Stock PyTorch | spills past VRAM | spills past VRAM | — | — |
|
|
211
|
-
|
|
212
|
-
- With an NVFP4 base TrainStream had the fastest step in every 14B scenario, in WSL and on Windows
|
|
213
|
-
- With an NF4 base, the format bitsandbytes and Unsloth use, TrainStream was ahead of every rival in every scenario
|
|
219
|
+
| TrainStream, NVFP4 base | **0.356 s** | **1.48 s** | **0.560 s** | **3.80 s** | — |
|
|
220
|
+
| TrainStream, NF4 base | 0.542 s | 2.18 s | 0.642 s | 5.87 s | — |
|
|
221
|
+
| TrainStream (auto) | 1.02 s | 3.08 s | 1.50 s | 6.98 s | **1.08 s** |
|
|
222
|
+
| bitsandbytes QLoRA (NF4) + PEFT | 0.572 s | spills past VRAM | out of memory | left out (hit the time limit in an earlier run) | — |
|
|
223
|
+
| bitsandbytes QLoRA + gradient checkpointing | 0.877 s | 3.13 s | out of memory | 6.99 s | — |
|
|
224
|
+
| Stock PyTorch | spills past VRAM | spills past VRAM | — | — | 2.40 s (spills) |
|
|
225
|
+
|
|
226
|
+
- With an NVFP4 base TrainStream had the fastest step in every 14B scenario, in WSL and on Windows. At 512 tokens its blocks now run as CUDA graphs: 1.66× bitsandbytes in WSL and 1.61× on Windows (1.26× and 1.24× in 0.8.1's check). NVFP4 costs quality (see the perplexity table below).
|
|
227
|
+
- With an NF4 base, the format bitsandbytes and Unsloth use, TrainStream was ahead of every rival in every scenario. Held to 12 GB of VRAM its median run was 1.09× Unsloth's (0.702 s against 0.767 s), though the slowest of its three runs (0.769 s) was level with Unsloth's (in 0.8.1's check Unsloth was 1.08× faster). At 512 tokens its lead over bitsandbytes is small (1.06× in WSL and on Windows): NF4 blocks don't run as graphs.
|
|
214
228
|
- 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.
|
|
215
229
|
- `"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.
|
|
230
|
+
- The full fine-tune: TrainStream keeps its activations in VRAM and stays at 18.8 GB, 1.45× faster than stock PyTorch in WSL. 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 (2.40 s on Windows in this run, 1.45 s in 0.8.1's).
|
|
217
231
|
- 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.
|
|
218
|
-
- Between the two environments
|
|
232
|
+
- Between the two environments every engine was within 10 % of its time in the other, except `"auto"` under the 12 GB cap, 1.39× slower in WSL (2.08 s against 1.50 s), and stock PyTorch's full fine-tune, which spills.
|
|
219
233
|
|
|
220
234
|
**Perplexity against bf16** (`benchmarks/quality.py`, held-out Python standard-library source; lower is better)
|
|
221
235
|
|
|
222
236
|
| Format | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
223
237
|
|---|---|---|---|---|
|
|
224
|
-
| int8 | −0.00 % |
|
|
225
|
-
| FP8 (tensor cores) | +0.89 % | +0.
|
|
226
|
-
| NF4 | +3.10 % | +2.
|
|
227
|
-
| NF4, `keep_precise="auto"` | +2.89 % | +2.
|
|
228
|
-
| NF4, `error_rank=16` (LoftQ) | +3.06 % | +2.
|
|
238
|
+
| int8 | −0.00 % | +0.07 % | +0.02 % | +0.02 % |
|
|
239
|
+
| FP8 (tensor cores) | +0.89 % | +0.80 % | +1.70 % | +1.40 % |
|
|
240
|
+
| NF4 | +3.10 % | +2.86 % | +5.94 % | +5.00 % |
|
|
241
|
+
| NF4, `keep_precise="auto"` | +2.89 % | +2.69 % | +5.27 % | +4.29 % |
|
|
242
|
+
| NF4, `error_rank=16` (LoftQ) | +3.06 % | +2.81 % | +5.76 % | +4.09 % |
|
|
229
243
|
| NF4, `double_quant=True` | +2.79 % | +2.65 % | +5.96 % | +4.95 % |
|
|
230
|
-
| NVFP4, weights only (bf16 matmuls) | +2.63 % | +2.
|
|
231
|
-
| NVFP4 (tensor cores) | +5.19 % | +4.
|
|
232
|
-
| NVFP4 with `outliers=0.01` | +4.78 % | +4.
|
|
233
|
-
| NVFP4, `error_rank=16` (LoftQ) | +5.14 % | +4.
|
|
234
|
-
| NVFP4, `nvfp4_backward=True` | +5.19 % | +5.
|
|
244
|
+
| NVFP4, weights only (bf16 matmuls) | +2.63 % | +2.30 % | +5.42 % | +5.02 % |
|
|
245
|
+
| NVFP4 (tensor cores) | +5.19 % | +4.54 % | +10.86 % | +10.17 % |
|
|
246
|
+
| NVFP4 with `outliers=0.01` | +4.78 % | +4.28 % | +8.99 % | +8.88 % |
|
|
247
|
+
| NVFP4, `error_rank=16` (LoftQ) | +5.14 % | +4.78 % | +10.85 % | +8.68 % |
|
|
248
|
+
| NVFP4, `nvfp4_backward=True` | +5.19 % | +5.02 % | +10.86 % | +10.08 % |
|
|
235
249
|
|
|
236
250
|
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:
|
|
237
251
|
|
|
238
252
|
| Format, LoRA at 2e-5 | Qwen2.5-14B | after 20 LoRA steps | Qwen2.5-1.5B | after 40 LoRA steps |
|
|
239
253
|
|---|---|---|---|---|
|
|
240
|
-
| NF4 | +3.10 % | +3.
|
|
241
|
-
| NF4, `lora_init="pissa"` | +2.96 % | +1.
|
|
242
|
-
| NVFP4 (tensor cores) | +5.19 % | +
|
|
243
|
-
| NVFP4, `lora_init="pissa"` | +5.27 % | +4.
|
|
254
|
+
| NF4 | +3.10 % | +3.10 % | +5.94 % | +5.69 % |
|
|
255
|
+
| NF4, `lora_init="pissa"` | +2.96 % | +1.95 % | +5.47 % | +4.57 % |
|
|
256
|
+
| NVFP4 (tensor cores) | +5.19 % | +5.02 % | +10.86 % | +10.62 % |
|
|
257
|
+
| NVFP4, `lora_init="pissa"` | +5.27 % | +4.46 % | +10.20 % | +8.72 % |
|
|
244
258
|
|
|
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.
|
|
259
|
+
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.46 % against +5.02 %) it was within it (it was 1.20 points in 0.8.0's).
|
|
246
260
|
|
|
247
261
|
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`.
|
|
248
262
|
|
|
249
263
|
## Results (RTX 5090 Laptop GPU 24 GB, 64 GB RAM)
|
|
250
264
|
|
|
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.
|
|
265
|
+
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.2).
|
|
252
266
|
|
|
253
267
|
| Workload | Stock PyTorch | TrainStream |
|
|
254
268
|
|---|---|---|
|
|
@@ -270,7 +284,7 @@ Offloading costs throughput when a model already fits, which is why `offload="au
|
|
|
270
284
|
- 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)
|
|
271
285
|
- Optional, for the Hugging Face integration: `transformers`, `accelerate`, and `peft` for LoRA (all three come with `trainstream[hf]`)
|
|
272
286
|
|
|
273
|
-
Tested on an RTX 5090 Laptop GPU with Windows 11 (PyTorch 2.14.1, CUDA 13.4, MSVC, Python 3.14), where all
|
|
287
|
+
Tested on an RTX 5090 Laptop GPU with Windows 11 (PyTorch 2.14.1, CUDA 13.4, MSVC, Python 3.14), where all 487 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 487 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.
|
|
274
288
|
|
|
275
289
|
## Install
|
|
276
290
|
|
|
@@ -474,6 +488,7 @@ model._trainstream_session.adapting # True while it is still tuning itself
|
|
|
474
488
|
| `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 |
|
|
475
489
|
| `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 |
|
|
476
490
|
| `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 |
|
|
491
|
+
| `cuda_graphs` | `"auto"`, `True`, `False`, `None` | `"auto"` | run each block's forward and backward as two recorded CUDA graphs instead of launching their kernels one by one from Python. At small batches the host launches kernels more slowly than the GPU runs them; replayed graphs keep the GPU busy (and at a higher clock). The same kernels on the same memory: gradients are bit-identical. `"auto"`: recorded between two steps once TrainStream runs with nothing moving during a step (optimizer in VRAM, every block's weights in VRAM as bf16 or as fp8 / nvfp4 on tensor cores, activations kept, one process) and the blocks' inputs have had the same shapes for two steps. Anything else runs eagerly as before: no gradients, eval mode, other input shapes (recorded again once they hold, up to 4 recordings), two forwards before a backward, activation checkpointing, switched adapters (the full list is in `trainstream.graphs`). The graphs hold one step's activations in a memory pool of their own. A training forward through graphed blocks leaves a Hugging Face KV cache empty (training never reads it). `True`: the same, plus a warning when the run doesn't qualify; `False` / `None`: never |
|
|
477
492
|
| `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 |
|
|
478
493
|
| `device` | `None`, `"cuda"`, `"cuda:N"`, `torch.device` | `None` | target GPU when the model is on the CPU |
|
|
479
494
|
| `blocks` | `None`, list of layer modules | `None` | the repeated layer stack; auto-detected |
|
|
@@ -659,7 +674,7 @@ Methods and attributes:
|
|
|
659
674
|
| `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"` |
|
|
660
675
|
| `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 |
|
|
661
676
|
|
|
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`).
|
|
677
|
+
`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`). Added in 0.8.2: `"graphs"` unless `cuda_graphs=False` (`mode`; `state`: `"not started"`, `"watching"` (about to record), `"captured"` or `"off"`; `reason` it is off; `blocks`; `captures`: recordings so far; `capture_s`: seconds they took; `pool_bytes`: VRAM the recorded graphs hold for one step's activations; `replays`: block forwards run as graphs; `eager`: block calls that ran eagerly, counted by reason).
|
|
663
678
|
|
|
664
679
|
The session behind a wrapped model is `model._trainstream_session` (`trainstream.TrainStreamSession`):
|
|
665
680
|
- `.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.2",
|
|
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.",
|
|
@@ -156,3 +156,27 @@ def test_masked_inputs_keep_pytorchs_order():
|
|
|
156
156
|
assert all(b._ts_sdpa_order is not None for b in session.attention.blocks)
|
|
157
157
|
finally:
|
|
158
158
|
trainstream.unwrap(model)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@pytest.mark.parametrize("reentrant", [False, True])
|
|
162
|
+
def test_hugging_face_gradient_checkpointing_recomputes_with_the_same_backend(reentrant):
|
|
163
|
+
# Hugging Face runs a checkpointed layer again inside backward, outside the model's forward
|
|
164
|
+
# and the backend order it set: the layer must re-enter that order, or the recomputation picks
|
|
165
|
+
# PyTorch's default kernel and torch.utils.checkpoint refuses its differently shaped saved
|
|
166
|
+
# tensors (cuDNN's RNG state against the memory-efficient kernel's)
|
|
167
|
+
if "cudnn" not in time_backends(1, 4, 256, 64, torch.bfloat16, DEV):
|
|
168
|
+
pytest.skip("no cuDNN attention here")
|
|
169
|
+
base = tiny_llama()
|
|
170
|
+
losses = {}
|
|
171
|
+
for gc in (False, True):
|
|
172
|
+
m = copy.deepcopy(base)
|
|
173
|
+
if gc:
|
|
174
|
+
m.gradient_checkpointing_enable(gradient_checkpointing_kwargs={"use_reentrant": reentrant})
|
|
175
|
+
m.train()
|
|
176
|
+
m, opt = trainstream.wrap(m, torch.optim.AdamW(m.parameters(), lr=1e-3), offload=True, attention="cudnn",
|
|
177
|
+
profile=False)
|
|
178
|
+
try:
|
|
179
|
+
losses[gc] = [step(m, opt, x) for x in ids(3)]
|
|
180
|
+
finally:
|
|
181
|
+
trainstream.unwrap(m)
|
|
182
|
+
assert losses[True] == pytest.approx(losses[False], rel=1e-3)
|