MCPcopy Index your code
hub / github.com/modelscope/modelscope / scan_cache_dir

Function scan_cache_dir

modelscope/hub/cache_manager.py:308–420  ·  view source on GitHub ↗

Scan the entire ModelScope cache-system and return a [`ModelScopeCacheInfo`] structure. Use `scan_cache_dir` to programmatically scan your cache-system. The cache will be scanned repo by repo. If a repo is corrupted, a [`~CorruptedCacheException`] will be thrown internally but captured

(
        cache_dir: Optional[Union[str, Path]] = None)

Source from the content-addressed store, hash-verified

306
307
308def scan_cache_dir(
309 cache_dir: Optional[Union[str, Path]] = None) -> ModelScopeCacheInfo:
310 """Scan the entire ModelScope cache-system and return a [`ModelScopeCacheInfo`] structure.
311
312 Use `scan_cache_dir` to programmatically scan your cache-system. The cache
313 will be scanned repo by repo. If a repo is corrupted, a [`~CorruptedCacheException`]
314 will be thrown internally but captured and returned in the [`~ModelScopeCacheInfo`]
315 structure. Only valid repos get a proper report.
316
317 ```py
318 >>> from modelscope.hub.utils import scan_cache_dir
319
320 >>> ms_cache_info = scan_cache_dir()
321 ModelScopeCacheInfo(
322 size_on_disk=3398085269,
323 repos=frozenset({
324 CachedRepoInfo(
325 repo_id='damo/t5-small',
326 repo_type='model',
327 repo_path=PosixPath(...),
328 size_on_disk=970726914,
329 nb_files=11,
330 revisions=frozenset({
331 CachedRevisionInfo(
332 commit_hash='master',
333 size_on_disk=970726339,
334 snapshot_path=PosixPath(...),
335 files=frozenset({
336 CachedFileInfo(
337 file_name='config.json',
338 size_on_disk=1197
339 file_path=PosixPath(...),
340 blob_path=PosixPath(...),
341 ),
342 CachedFileInfo(...),
343 ...
344 }),
345 ),
346 CachedRevisionInfo(...),
347 ...
348 }),
349 ),
350 CachedRepoInfo(...),
351 ...
352 }),
353 warnings=[
354 CorruptedCacheException("Snapshots dir doesn't exist in cached repo: ..."),
355 CorruptedCacheException(...),
356 ...
357 ],
358 )
359 ```
360
361 Args:
362 cache_dir (`str` or `Path`, `optional`):
363 Cache directory to scan. Defaults to the default ModelScope cache directory.
364
365 Raises:

Callers 3

test_scan_default_dirMethod · 0.90
test_scan_given_dirMethod · 0.90

Calls 6

get_modelscope_cache_dirFunction · 0.90
_scan_dirFunction · 0.85
ModelScopeCacheInfoClass · 0.85
existsMethod · 0.45
updateMethod · 0.45
extendMethod · 0.45

Tested by 3

test_scan_default_dirMethod · 0.72
test_scan_given_dirMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…