Skip to content

Commit 62de08d

Browse files
committed
fix(hub): correctness pass on inventory, GGUF sizing, and dataset split matching
- inventory_scan: defer snapshot resolve in is_snapshot_partial so the cheap cancel-marker check short-circuits first (restores cheapest-first ordering) - datasets/cache_inventory: dedupe hardlink-shared blobs in the size_on_disk fallback to stop 2-5x dataset size over-reporting - gguf: include the mmproj companion in offline partial download size so vision GGUFs don't change size on offline->online toggle - dataset_cache/formatting: share one alias-aware split matcher so cached and remote file selection agree (validation/valid/val, eval) - gguf: rename _GGUF_SPLIT_RE -> _GGUF_SPLIT_SUFFIX_RE to end the name collision with inventory_scan's distinct two-group regex
1 parent bb93a06 commit 62de08d

6 files changed

Lines changed: 45 additions & 27 deletions

File tree

‎studio/backend/hub/services/datasets/cache_inventory.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,18 @@ def _scan_hf_dataset_caches() -> list[dict]:
297297
continue
298298
total_size = int(getattr(repo_info, "size_on_disk", 0) or 0)
299299
if total_size == 0:
300-
total_size = sum(
301-
int(f.size_on_disk or 0)
302-
for rev in repo_info.revisions
303-
for f in rev.files
304-
)
300+
unique_blobs: dict[str, int] = {}
301+
for rev in repo_info.revisions:
302+
rev_id = getattr(rev, "commit_hash", None) or str(id(rev))
303+
for f in rev.files:
304+
blob_path = getattr(f, "blob_path", None)
305+
key = (
306+
str(blob_path)
307+
if blob_path
308+
else f"{rev_id}:{f.file_name}"
309+
)
310+
unique_blobs[key] = int(f.size_on_disk or 0)
311+
total_size = sum(unique_blobs.values())
305312
key = repo_info.repo_id.lower()
306313
existing = seen_lower.get(key)
307314
cache_dir = Path(repo_info.repo_path)

‎studio/backend/hub/services/datasets/formatting.py‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from hub.utils.dataset_cache import (
3131
cached_dataset_candidates as _shared_cached_dataset_candidates,
3232
latest_cached_dataset_snapshot as _shared_latest_cached_dataset_snapshot,
33+
split_label_matches as _split_label_matches,
3334
)
3435
from hub.utils import download_registry
3536
from hub.utils.dataset_format import check_dataset_format, format_dataset_preview
@@ -168,14 +169,6 @@ def _cached_dataset_candidates(
168169
)
169170

170171

171-
_SPLIT_ALIASES = {
172-
"validation": frozenset({"validation", "valid", "val"}),
173-
"valid": frozenset({"validation", "valid", "val"}),
174-
"val": frozenset({"validation", "valid", "val"}),
175-
"eval": frozenset({"eval", "validation", "valid", "val"}),
176-
}
177-
178-
179172
def _repo_file_label_tokens(path: str) -> set[str]:
180173
return {token for token in re.split(r"[^a-z0-9]+", path.lower()) if token}
181174

@@ -185,10 +178,7 @@ def _repo_file_matches_label(path: str, label: str) -> bool:
185178

186179

187180
def _repo_file_matches_split(path: str, split: str) -> bool:
188-
normalized = split.strip().lower()
189-
labels = _SPLIT_ALIASES.get(normalized, frozenset({normalized}))
190-
tokens = _repo_file_label_tokens(path)
191-
return bool(labels.intersection(tokens))
181+
return _split_label_matches(path, split)
192182

193183

194184
def _select_tier1_repo_file(

‎studio/backend/hub/services/models/gguf_variants.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def _partial_local_response(
417417
quant = v.quant,
418418
display_label = v.display_label,
419419
size_bytes = v.size_bytes,
420-
download_size_bytes = v.size_bytes,
420+
download_size_bytes = v.download_size_bytes or v.size_bytes,
421421
downloaded = False,
422422
partial = True,
423423
partial_transport = _partial_transport_for_variant(

‎studio/backend/hub/utils/dataset_cache.py‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@ def _rel_lower(snapshot: Path, path: Path) -> str:
1515
return path.relative_to(snapshot).as_posix().lower()
1616

1717

18+
_SPLIT_ALIASES = {
19+
"validation": frozenset({"validation", "valid", "val"}),
20+
"valid": frozenset({"validation", "valid", "val"}),
21+
"val": frozenset({"validation", "valid", "val"}),
22+
"eval": frozenset({"eval", "validation", "valid", "val"}),
23+
}
24+
25+
26+
def _label_tokens(text: str) -> set[str]:
27+
return {token for token in re.split(r"[^a-z0-9]+", text.lower()) if token}
28+
29+
30+
def split_label_matches(text: str, split: str) -> bool:
31+
"""Match a split name against a file path's tokens, expanding split aliases
32+
(validation/valid/val, eval) so cached and remote selection agree."""
33+
normalized = split.strip().lower()
34+
if not normalized:
35+
return False
36+
labels = _SPLIT_ALIASES.get(normalized, frozenset({normalized}))
37+
return bool(labels.intersection(_label_tokens(text)))
38+
39+
1840
def _matches_label(snapshot: Path, path: Path, label: str) -> bool:
1941
label = label.strip().lower()
2042
if not label:
@@ -114,7 +136,7 @@ def score(path: Path) -> tuple[int, int, str]:
114136
subset_match = bool(
115137
subset_lower and _matches_label(snapshot, path, subset_lower)
116138
)
117-
split_match = bool(split_lower and _matches_label(snapshot, path, split_lower))
139+
split_match = bool(split_lower and split_label_matches(rel, split_lower))
118140
location_rank = 3
119141
if split_match and (not subset_lower or subset_match):
120142
location_rank = 0

‎studio/backend/hub/utils/gguf.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class GgufVariantInfo:
2323
quant: str
2424
size_bytes: int
2525
display_label: Optional[str] = None
26+
download_size_bytes: int = 0
2627

2728

2829
GGUF_QUANT_PREFERENCE = [
@@ -64,7 +65,7 @@ class GgufVariantInfo:
6465
"F32",
6566
]
6667

67-
_GGUF_SPLIT_RE = re.compile(r"-\d{3,}-of-\d{3,}", re.IGNORECASE)
68+
_GGUF_SPLIT_SUFFIX_RE = re.compile(r"-\d{3,}-of-\d{3,}", re.IGNORECASE)
6869
_GGUF_QUANT_RE = re.compile(
6970
r"(UD-)?"
7071
r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"
@@ -136,7 +137,7 @@ def pick_best_gguf(filenames: list[str]) -> Optional[str]:
136137

137138
def _gguf_stem(filename: str) -> str:
138139
basename = filename.rsplit("/", 1)[-1]
139-
return _GGUF_SPLIT_RE.sub("", basename.rsplit(".", 1)[0]).strip()
140+
return _GGUF_SPLIT_SUFFIX_RE.sub("", basename.rsplit(".", 1)[0]).strip()
140141

141142

142143
def extract_quant_token(filename: str) -> Optional[str]:
@@ -254,12 +255,14 @@ def list_partial_gguf_variants_from_state(
254255
manifest = download_manifest.read_manifest("model", repo_id, variant)
255256
main_filename: Optional[str] = None
256257
size_bytes = 0
258+
companion_bytes = 0
257259
if manifest is not None:
258260
for expected in manifest.expected_files:
259261
if not is_gguf_filename(expected.path):
260262
continue
261263
if is_mmproj_filename(expected.path):
262264
has_vision = True
265+
companion_bytes += max(0, int(expected.size or 0))
263266
continue
264267
if main_filename is None:
265268
main_filename = expected.path
@@ -271,6 +274,7 @@ def list_partial_gguf_variants_from_state(
271274
filename = main_filename,
272275
quant = variant,
273276
size_bytes = size_bytes,
277+
download_size_bytes = size_bytes + companion_bytes,
274278
)
275279
)
276280

‎studio/backend/hub/utils/inventory_scan.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,6 @@ def is_snapshot_partial(
404404
from hub.utils import download_manifest
405405

406406
state_applies = _state_applies_to_repo_cache_dir(repo_cache_dir)
407-
snapshot_dir = resolve_snapshot_dir_for_scan(
408-
repo_type,
409-
repo_id,
410-
repo_cache_dir,
411-
)
412407
return _compose_partial(
413408
lambda: state_applies
414409
and download_manifest.has_cancel_marker(repo_type, repo_id, None),
@@ -417,7 +412,7 @@ def is_snapshot_partial(
417412
repo_type,
418413
repo_id,
419414
None,
420-
snapshot_dir,
415+
None,
421416
repo_cache_dir,
422417
),
423418
)

0 commit comments

Comments
 (0)