streamft 0.2.4__tar.gz → 0.2.5__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.
- {streamft-0.2.4 → streamft-0.2.5}/PKG-INFO +1 -1
- {streamft-0.2.4 → streamft-0.2.5}/pyproject.toml +1 -1
- {streamft-0.2.4 → streamft-0.2.5}/streamft/cli.py +13 -2
- {streamft-0.2.4 → streamft-0.2.5}/streamft.egg-info/PKG-INFO +1 -1
- {streamft-0.2.4 → streamft-0.2.5}/tests/test_streamft_smoke.py +39 -0
- {streamft-0.2.4 → streamft-0.2.5}/LICENSE +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/README.md +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/setup.cfg +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/__init__.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/__main__.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/autotune.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/data.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/disk_quant_store.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/doctor.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/fit.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/lora.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/metrics.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/stream_quant_lora.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft/stream_train.py +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft.egg-info/SOURCES.txt +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft.egg-info/dependency_links.txt +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft.egg-info/entry_points.txt +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft.egg-info/requires.txt +0 -0
- {streamft-0.2.4 → streamft-0.2.5}/streamft.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "streamft"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.5"
|
|
8
8
|
description = "Fine-tune models that do not fit: stream NF4 weights from disk, one transformer block at a time."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -133,6 +133,17 @@ def _format_messages(row: dict) -> list[dict]:
|
|
|
133
133
|
]
|
|
134
134
|
|
|
135
135
|
|
|
136
|
+
def sft_schedule(rows, encode):
|
|
137
|
+
"""Split rows into trainable ones and a count of dropped ones.
|
|
138
|
+
|
|
139
|
+
The caller loops `for i in range(steps)` over the returned rows, so `--steps N`
|
|
140
|
+
always means N optimizer updates regardless of how many rows the prompt mask
|
|
141
|
+
rejects. Kept separate from the training loop so it can be tested without a GPU.
|
|
142
|
+
"""
|
|
143
|
+
valid = [r for r in rows if encode(r) is not None]
|
|
144
|
+
return valid, len(rows) - len(valid)
|
|
145
|
+
|
|
146
|
+
|
|
136
147
|
def _encode_chat(tokenizer, row: dict, seq: int):
|
|
137
148
|
"""Chat-template encode with the prompt tokens masked out of the loss."""
|
|
138
149
|
messages = _format_messages(row)
|
|
@@ -376,8 +387,8 @@ def main() -> int:
|
|
|
376
387
|
print(f"[eval] before loss={ce0:.4f}", flush=True)
|
|
377
388
|
# Filter once so `--steps N` means N optimizer updates, not "N attempts minus
|
|
378
389
|
# whatever the mask rejected". A silently short run is a lie about the budget.
|
|
379
|
-
valid_rows =
|
|
380
|
-
|
|
390
|
+
valid_rows, skipped_train = sft_schedule(
|
|
391
|
+
train_rows, lambda r: _encode_chat(tok, r, args.seq))
|
|
381
392
|
if not valid_rows:
|
|
382
393
|
raise SystemExit("[sft] no training row has a valid prompt mask; refusing to run")
|
|
383
394
|
if skipped_train:
|
|
@@ -8,6 +8,7 @@ They pin the things that broke silently during development:
|
|
|
8
8
|
|
|
9
9
|
import math
|
|
10
10
|
|
|
11
|
+
import pytest
|
|
11
12
|
import torch
|
|
12
13
|
import torch.nn as nn
|
|
13
14
|
import torch.nn.functional as F
|
|
@@ -209,3 +210,41 @@ def test_encode_chat_drops_rows_whose_prompt_is_not_a_prefix():
|
|
|
209
210
|
ids, labels = _encode_chat(_StubTokenizer([1, 2, 3, 4], [1, 2]), row, 32)
|
|
210
211
|
assert ids.tolist() == [[1, 2, 3, 4]]
|
|
211
212
|
assert labels.tolist() == [[-100, -100, 3, 4]]
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
# ------------------------------------------------ SFT step budget & empty eval
|
|
216
|
+
|
|
217
|
+
def test_sft_schedule_keeps_the_step_budget_with_mixed_rows():
|
|
218
|
+
from streamft.cli import sft_schedule
|
|
219
|
+
|
|
220
|
+
rows = list(range(10))
|
|
221
|
+
|
|
222
|
+
def encode(r):
|
|
223
|
+
return None if r % 3 == 0 else [r] # 4 of 10 are rejected
|
|
224
|
+
|
|
225
|
+
valid, dropped = sft_schedule(rows, encode)
|
|
226
|
+
assert dropped == 4 and len(valid) == 6
|
|
227
|
+
|
|
228
|
+
steps = 25
|
|
229
|
+
schedule = [valid[i % len(valid)] for i in range(steps)]
|
|
230
|
+
assert len(schedule) == steps # N updates even though 4 rows were dropped
|
|
231
|
+
assert all(v % 3 != 0 for v in schedule)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_masked_eval_raises_when_every_row_is_skipped(monkeypatch):
|
|
235
|
+
import types
|
|
236
|
+
|
|
237
|
+
from streamft import cli
|
|
238
|
+
|
|
239
|
+
class FakeTrainer:
|
|
240
|
+
def __init__(self):
|
|
241
|
+
self.model = types.SimpleNamespace(eval=lambda: None, train=lambda: None)
|
|
242
|
+
self.norm = nn.Identity()
|
|
243
|
+
self.lm_head = nn.Linear(4, 7, bias=False)
|
|
244
|
+
|
|
245
|
+
def _forward_cached(self, ids):
|
|
246
|
+
return torch.zeros(1, ids.shape[1], 4), None, None
|
|
247
|
+
|
|
248
|
+
monkeypatch.setattr(cli, "_encode_chat", lambda *a, **k: None)
|
|
249
|
+
with pytest.raises(RuntimeError, match="every row was skipped"):
|
|
250
|
+
cli._masked_eval(FakeTrainer(), [{"instruction": "x", "response": "y"}], object(), 8)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|