tensorferry 0.1.0__tar.gz → 0.2.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.
- {tensorferry-0.1.0/src/tensorferry.egg-info → tensorferry-0.2.1}/PKG-INFO +1 -1
- {tensorferry-0.1.0 → tensorferry-0.2.1}/pyproject.toml +1 -1
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/store.py +29 -1
- {tensorferry-0.1.0 → tensorferry-0.2.1/src/tensorferry.egg-info}/PKG-INFO +1 -1
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/test_progress.py +83 -18
- {tensorferry-0.1.0 → tensorferry-0.2.1}/LICENSE +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/MANIFEST.in +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/README.md +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/scripts/bench_remote.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/setup.cfg +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/__init__.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/_pool.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/api.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/backend.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/cache.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/formats.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/jax.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/loader.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/plan.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/progress.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry/torch.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry.egg-info/SOURCES.txt +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry.egg-info/dependency_links.txt +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry.egg-info/requires.txt +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/src/tensorferry.egg-info/top_level.txt +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/__init__.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/_files.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/conftest.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/test_cache.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/test_formats.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/test_jax.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/test_loader.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/test_remote.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/test_store.py +0 -0
- {tensorferry-0.1.0 → tensorferry-0.2.1}/tests/test_torch.py +0 -0
|
@@ -11,7 +11,7 @@ from urllib.parse import quote, unquote
|
|
|
11
11
|
import numpy as np
|
|
12
12
|
import obstore.store
|
|
13
13
|
|
|
14
|
-
from tensorferry.progress import _record_read
|
|
14
|
+
from tensorferry.progress import _download, _record_read
|
|
15
15
|
|
|
16
16
|
__all__ = [
|
|
17
17
|
"Blob",
|
|
@@ -178,6 +178,10 @@ class CallbackStore:
|
|
|
178
178
|
return self.size_fn(name)
|
|
179
179
|
|
|
180
180
|
|
|
181
|
+
# Chunk size for obstore streaming reads when download progress is tracked (obstore's default is 10 MiB).
|
|
182
|
+
_PROGRESS_CHUNK_BYTES = 512 << 10
|
|
183
|
+
|
|
184
|
+
|
|
181
185
|
class ObjectStore:
|
|
182
186
|
"""Hub authentication uses the supplied token or the locally configured Hugging Face token."""
|
|
183
187
|
|
|
@@ -210,6 +214,30 @@ class ObjectStore:
|
|
|
210
214
|
def fetch(self, name: str, start: int, stop: int) -> Buffer:
|
|
211
215
|
if stop <= start:
|
|
212
216
|
return b""
|
|
217
|
+
if self._is_remote and _download.get() is not None:
|
|
218
|
+
result = obstore.get(self.store, name, options={"range": (start, stop)})
|
|
219
|
+
stream = result.stream(min_chunk_size=_PROGRESS_CHUNK_BYTES)
|
|
220
|
+
first = next(stream, None)
|
|
221
|
+
if first is None:
|
|
222
|
+
return b""
|
|
223
|
+
_record_read(first)
|
|
224
|
+
span = getattr(result, "range", None)
|
|
225
|
+
expected = stop - start if span is None else span[1] - span[0]
|
|
226
|
+
if len(first) >= expected:
|
|
227
|
+
return first
|
|
228
|
+
out = np.empty(expected, np.uint8)
|
|
229
|
+
at = len(first)
|
|
230
|
+
out[:at] = np.frombuffer(first, np.uint8)
|
|
231
|
+
for chunk in stream:
|
|
232
|
+
_record_read(chunk)
|
|
233
|
+
n = len(chunk)
|
|
234
|
+
if at + n > out.size:
|
|
235
|
+
grown = np.empty(at + n, np.uint8)
|
|
236
|
+
grown[:at] = out[:at]
|
|
237
|
+
out = grown
|
|
238
|
+
out[at : at + n] = np.frombuffer(chunk, np.uint8)
|
|
239
|
+
at += n
|
|
240
|
+
return out[:at]
|
|
213
241
|
data = obstore.get_range(self.store, name, start=start, end=stop)
|
|
214
242
|
if self._is_remote:
|
|
215
243
|
_record_read(data)
|
|
@@ -47,26 +47,29 @@ def test_download_progress_tracks_shards_cache_gaps_and_npz(monkeypatch, tmp_pat
|
|
|
47
47
|
shard_started, release_shard = threading.Event(), threading.Event()
|
|
48
48
|
npz_started, release_npz = threading.Event(), threading.Event()
|
|
49
49
|
received_npz = []
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
get = obstore.get
|
|
51
|
+
|
|
52
|
+
def fail_range(*args, **kwargs):
|
|
53
|
+
raise AssertionError("expected tracked reads to stream via obstore.get")
|
|
54
|
+
|
|
55
|
+
def read_get(store, name, *, options):
|
|
56
|
+
byte_range = options["range"]
|
|
57
|
+
if isinstance(byte_range, tuple):
|
|
58
|
+
if name == shard_name and byte_range[0] > 0:
|
|
59
|
+
shard_started.set()
|
|
60
|
+
assert release_shard.wait(10)
|
|
61
|
+
else:
|
|
62
|
+
assert name == npz_name
|
|
63
|
+
npz_started.set()
|
|
64
|
+
assert release_npz.wait(10)
|
|
65
|
+
result = get(store, name, options=options)
|
|
57
66
|
if name == npz_name:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def read_tail(store, name, *, options):
|
|
62
|
-
assert name == npz_name
|
|
63
|
-
npz_started.set()
|
|
64
|
-
assert release_npz.wait(10)
|
|
65
|
-
received_npz.append(min(options["range"]["suffix"], archive.getbuffer().nbytes))
|
|
66
|
-
return get(store, name, options=options)
|
|
67
|
+
start, stop = result.range
|
|
68
|
+
received_npz.append(stop - start)
|
|
69
|
+
return result
|
|
67
70
|
|
|
68
|
-
monkeypatch.setattr(obstore, "get_range",
|
|
69
|
-
monkeypatch.setattr(obstore, "get",
|
|
71
|
+
monkeypatch.setattr(obstore, "get_range", fail_range)
|
|
72
|
+
monkeypatch.setattr(obstore, "get", read_get)
|
|
70
73
|
|
|
71
74
|
try:
|
|
72
75
|
with tf.track_downloads() as progress:
|
|
@@ -140,3 +143,65 @@ def test_download_progress_excludes_local_object_store():
|
|
|
140
143
|
with tf.track_downloads() as progress:
|
|
141
144
|
tf.load_arrays("weights.safetensors", store=tf.ObjectStore(backing), cache=False).result()
|
|
142
145
|
assert progress.snapshot() == (0, 0)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_download_progress_streams_chunks_and_untracked_uses_get_range(monkeypatch, remote_store):
|
|
149
|
+
store, backing = remote_store
|
|
150
|
+
weights = np.arange(1 << 14, dtype=np.float32)
|
|
151
|
+
payload = safetensors_bytes({"weights": weights})
|
|
152
|
+
obstore.put(backing, "weights.safetensors", payload)
|
|
153
|
+
|
|
154
|
+
get, get_range = obstore.get, obstore.get_range
|
|
155
|
+
chunk1_recorded, release_chunk2 = threading.Event(), threading.Event()
|
|
156
|
+
split = weights.nbytes // 2
|
|
157
|
+
prefetched = []
|
|
158
|
+
stream_chunk_sizes: list[int] = []
|
|
159
|
+
|
|
160
|
+
def stream_get(backend, name, *, options):
|
|
161
|
+
result = get(backend, name, options=options)
|
|
162
|
+
byte_range = options["range"]
|
|
163
|
+
if isinstance(byte_range, tuple) and byte_range[0] > 0:
|
|
164
|
+
data = bytes(result.bytes())
|
|
165
|
+
|
|
166
|
+
class _FakeResult:
|
|
167
|
+
def stream(self, min_chunk_size: int = 10 << 20):
|
|
168
|
+
stream_chunk_sizes.append(min_chunk_size)
|
|
169
|
+
yield data[:split]
|
|
170
|
+
chunk1_recorded.set()
|
|
171
|
+
assert release_chunk2.wait(10)
|
|
172
|
+
yield data[split:]
|
|
173
|
+
|
|
174
|
+
return _FakeResult()
|
|
175
|
+
start, stop = result.range
|
|
176
|
+
prefetched.append(stop - start)
|
|
177
|
+
return result
|
|
178
|
+
|
|
179
|
+
monkeypatch.setattr(obstore, "get", stream_get)
|
|
180
|
+
try:
|
|
181
|
+
with tf.track_downloads() as progress:
|
|
182
|
+
pending = tf.load_arrays("weights.safetensors", store=store, cache=False)
|
|
183
|
+
assert chunk1_recorded.wait(10)
|
|
184
|
+
before = sum(prefetched)
|
|
185
|
+
assert progress.snapshot() == (before + split, before + weights.nbytes)
|
|
186
|
+
release_chunk2.set()
|
|
187
|
+
np.testing.assert_array_equal(pending.result(timeout=10)["weights"], weights)
|
|
188
|
+
assert progress.snapshot() == (before + weights.nbytes, before + weights.nbytes)
|
|
189
|
+
assert stream_chunk_sizes == [512 << 10]
|
|
190
|
+
finally:
|
|
191
|
+
release_chunk2.set()
|
|
192
|
+
|
|
193
|
+
# Without track_downloads(), fetch keeps using obstore.get_range.
|
|
194
|
+
range_calls = []
|
|
195
|
+
|
|
196
|
+
def fail_get(*args, **kwargs):
|
|
197
|
+
raise AssertionError("expected untracked fetch to use obstore.get_range")
|
|
198
|
+
|
|
199
|
+
def count_get_range(backend, name, *, start, end):
|
|
200
|
+
range_calls.append((name, start, end))
|
|
201
|
+
return get_range(backend, name, start=start, end=end)
|
|
202
|
+
|
|
203
|
+
monkeypatch.setattr(obstore, "get", fail_get)
|
|
204
|
+
monkeypatch.setattr(obstore, "get_range", count_get_range)
|
|
205
|
+
loaded = tf.load_arrays("weights.safetensors", store=store, cache=False).result(timeout=10)
|
|
206
|
+
np.testing.assert_array_equal(loaded["weights"], weights)
|
|
207
|
+
assert len(range_calls) >= 2
|
|
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
|
|
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
|