unsloth/studio/backend/utils/paths/__init__.py
Lee Jackson a29b4e23fd
studio: reuse HF cached repo casing to prevent duplicate downloads (#4822)
* fix(studio): reuse HF cached repo casing to prevent duplicate downloads

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Move cache case resolution tests to separate PR

Tests for resolve_cached_repo_id_case and get_model_config case resolution
belong in their own PR to keep this change focused on the runtime fix.

* fix(studio): debug-log HF_HUB_CACHE fallback in path_utils

* Fix stale memoization in resolve_cached_repo_id_case

- Check exact-case path before memo to ensure a newly-appeared exact
  match always wins over a previously memoized variant
- Validate memoized entries still exist on disk before returning them
  to prevent stale results when cache dirs are deleted/recreated

* Minor cleanups for cache case resolution

- Use .is_dir() instead of .exists() for exact-case cache check
  (cache entries are always directories)
- Remove redundant fallback in _detect_audio_from_tokenizer since
  get_cache_path already handles case resolution and returns None
  when the model is not cached

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <danielhanchen@gmail.com>
2026-04-03 05:48:24 -07:00

80 lines
1.9 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
"""
Path utilities for model and dataset handling
"""
from .path_utils import (
normalize_path,
is_local_path,
is_model_cached,
get_cache_path,
resolve_cached_repo_id_case,
get_cache_case_resolution_stats,
reset_cache_case_resolution_state,
)
from .storage_roots import (
studio_root,
assets_root,
datasets_root,
dataset_uploads_root,
recipe_datasets_root,
outputs_root,
exports_root,
auth_root,
auth_db_path,
studio_db_path,
tmp_root,
seed_uploads_root,
unstructured_seed_cache_root,
unstructured_uploads_root,
oxc_validator_tmp_root,
tensorboard_root,
legacy_hf_cache_dir,
hf_default_cache_dir,
lmstudio_model_dirs,
ensure_dir,
ensure_studio_directories,
resolve_under_root,
resolve_output_dir,
resolve_export_dir,
resolve_tensorboard_dir,
resolve_dataset_path,
)
__all__ = [
"normalize_path",
"is_local_path",
"is_model_cached",
"get_cache_path",
"resolve_cached_repo_id_case",
"get_cache_case_resolution_stats",
"reset_cache_case_resolution_state",
"studio_root",
"assets_root",
"datasets_root",
"dataset_uploads_root",
"recipe_datasets_root",
"outputs_root",
"exports_root",
"auth_root",
"auth_db_path",
"studio_db_path",
"tmp_root",
"seed_uploads_root",
"unstructured_seed_cache_root",
"unstructured_uploads_root",
"oxc_validator_tmp_root",
"tensorboard_root",
"legacy_hf_cache_dir",
"hf_default_cache_dir",
"lmstudio_model_dirs",
"ensure_dir",
"ensure_studio_directories",
"resolve_under_root",
"resolve_output_dir",
"resolve_export_dir",
"resolve_tensorboard_dir",
"resolve_dataset_path",
]