modelscope-hub 0.7.1__tar.gz → 0.7.2__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.
- {modelscope_hub-0.7.1/src/modelscope_hub.egg-info → modelscope_hub-0.7.2}/PKG-INFO +56 -6
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/README.md +55 -5
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/pyproject.toml +1 -1
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_download.py +47 -5
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_download_state.py +35 -4
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_resilient_download.py +6 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/api.py +11 -2
- modelscope_hub-0.7.2/src/modelscope_hub/cli/kernels.py +131 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/main.py +2 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/compat/hub_api.py +5 -4
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/kernels/__init__.py +2 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/kernels/_hub.py +38 -7
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/kernels/_load.py +66 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/version.py +1 -1
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2/src/modelscope_hub.egg-info}/PKG-INFO +56 -6
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub.egg-info/SOURCES.txt +4 -0
- modelscope_hub-0.7.2/tests/test_cli_kernels.py +114 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_download_integrity.py +31 -3
- modelscope_hub-0.7.2/tests/test_download_snapshot_identifier.py +454 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_kernels.py +146 -0
- modelscope_hub-0.7.2/tests/test_modelscope_download_compatibility.py +231 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/LICENSE +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/setup.cfg +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/__init__.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_cache_manager.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_download_control.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_git.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_legacy_api.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_openapi.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_repository.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/_upload.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/agent/__init__.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/agent/_api.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/agent/_plugin.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/agent_idp.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/__init__.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/agent.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/agent_idp.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/base.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/cache.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/compat.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/deploy.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/download.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/login.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/mcp.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/repo.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/secret.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/studio.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/cli/upload.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/compat/__init__.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/compat/constants.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/compat/file_download.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/compat/snapshot_download.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/config.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/constants.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/errors.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/kernels/_patch.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/py.typed +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/types.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/utils/__init__.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/utils/file_utils.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/utils/format.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/utils/logger.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/utils/media.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/utils/patterns.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub/utils/time_utils.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub.egg-info/dependency_links.txt +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub.egg-info/entry_points.txt +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub.egg-info/requires.txt +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/src/modelscope_hub.egg-info/top_level.txt +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_agent_idp.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_agent_idp_keys.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_agent_plugin.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_cache_hotfix.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_cache_verification.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_commit_action_limit.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_compat_constants_completeness.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_compat_delete_files.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_compat_get_model_files.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_compat_snapshot_download.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_compat_studio.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_config_token.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_create_repo_routing.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_credential_lifecycle.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_dataset_category.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_download_corruption.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_download_lock_path.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_download_report.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_errors_openapi_codes.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_legacy_cache_detection.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_login_failure_paths.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_login_scoped_token.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_model_category.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_model_detail_fields.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_model_options.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_openapi_coverage.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_openapi_delete_files.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_repo_files_truncation.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_repo_info_visibility.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_repo_tree_page_retry.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_upload_batching.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_upload_blob_dedup.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_upload_config.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_upload_lfs_gate.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_user_agent.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_user_info.py +0 -0
- {modelscope_hub-0.7.1 → modelscope_hub-0.7.2}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: modelscope-hub
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: The official Python client to connect with ModelScope Hub.
|
|
5
5
|
Author: ModelScope team
|
|
6
6
|
Author-email: contact@modelscope.cn
|
|
@@ -69,12 +69,60 @@ The official Python SDK & CLI for [ModelScope Hub](https://modelscope.cn) — do
|
|
|
69
69
|
|
|
70
70
|
## News
|
|
71
71
|
|
|
72
|
+
**v0.7.2** (2026-11-24)
|
|
73
|
+
- **Fix**: download counting — a snapshot download (`download_repo`, `snapshot_download`, `ms-hub download`, report mode) sends one `snapshot-identifier` per task, shared by every file, retry, resumed transfer and range part, instead of a new one per file; a resumed report-mode task keeps its identifier. Standalone file downloads (`download_file`, `model_file_download`, `dataset_file_download`, CLI file arguments) no longer send one, so the Hub counts them per file. Cached dataset meta files no longer trigger a download request
|
|
74
|
+
|
|
75
|
+
**v0.7.1** (2026-11-10)
|
|
76
|
+
- **Fix**: the intra-cloud region probe is bounded per hop by `MODELSCOPE_DOWNLOAD_REGION_PROBE_TIMEOUT_SECONDS` (default `1`), so a slow probe falls back to the default route instead of stalling the download
|
|
77
|
+
|
|
78
|
+
**v0.7.0** (2026-11-09)
|
|
79
|
+
- **Feature**: `modelscope_hub.kernels` loads optimized kernels from ModelScope (`kernels` extra); `modelscope_hub.compat.hf_hub_patcher` redirects `huggingface_hub` calls to ModelScope (`hf` extra); uploads route through the commit API instead of a git clone + push
|
|
80
|
+
- **Enhance**: offline cache compatibility — `resolve_cached_snapshot` and `local_files_only` resolve standard and legacy cache layouts without network access or writes, legacy model-root links keep pre-snapshot paths valid, `ms-hub cache clear` validates scope and supports `--dry-run`, and `MODELSCOPE_CACHE` takes precedence over the `MS_CACHE_HOME` alias
|
|
81
|
+
|
|
82
|
+
<details>
|
|
83
|
+
<summary>v0.6.1 and older</summary>
|
|
84
|
+
|
|
72
85
|
**v0.6.1** (2026-10-30)
|
|
73
86
|
- **Feature**: `ms-hub download --total-timeout` (and `HubApi(download_total_timeout=...)`) sets a per-file time budget that overrides the environment variable; `0` means no limit
|
|
74
87
|
- **Behaviour**: a transfer that keeps making progress is no longer capped by default — `MODELSCOPE_DOWNLOAD_TOTAL_TIMEOUT` now defaults to `0` (was `3600`), while idle timeouts, the low-speed watchdog and bounded retries still apply; set a positive value to restore a cap
|
|
75
88
|
- **Fix**: a stop caused by an expired budget keeps its partial data and is reported as pending, so a plain re-run resumes it instead of requiring `--retry-failed`; trickling response headers stay bounded by the idle timeout when no overall budget is set
|
|
76
89
|
- **Quality**: budget and cancellation messages are English and name both the budget and the variable that relaxes it
|
|
77
90
|
|
|
91
|
+
**v0.6.0** (2026-10-29)
|
|
92
|
+
- **Feature**: model and dataset writes moved to OpenAPI — repository creation, category set/update, detail reads, model option lists and repository settings; `get_model`/`get_dataset` keep the historical `Visibility` enum, while `gated_mode=True/False` is the separate application switch
|
|
93
|
+
- **Breaking**: `approval_mode`, the `gated` request parameter and `--approval-mode` are removed; passing them through `**kwargs` raises `TypeError` before any request
|
|
94
|
+
- **Enhance**: creation keeps the v0.5.1 legacy request format when `gated_mode` is explicit, and category/zone and set-only fields are validated before sending
|
|
95
|
+
|
|
96
|
+
**v0.5.1** (2026-10-26)
|
|
97
|
+
- **Feature**: `HubApi.download_repo_report` and `ms-hub download --continue-on-error` continue past isolated file failures and return a `COMPLETE`/`PARTIAL` report; `--retry-failed` reruns them and exit code `3` means partial. `download_repo` and `snapshot_download` stay strict
|
|
98
|
+
- **Enhance**: recovery hints live in one hidden JSON per task (no embedded database), state is advisory and re-validated against actual size/hash, failed pages are isolated, and listings stream with bounded queues
|
|
99
|
+
|
|
100
|
+
**v0.5.0** (2026-10-24)
|
|
101
|
+
- **Feature**: downloads verify size and SHA-256 before replacing files, with safe resume, bounded retries, idle and total timeouts, low-speed detection, cancellation and per-file locks; an incomplete snapshot raises `FileDownloadError` (CLI exit code `1`) and keeps completed files
|
|
102
|
+
- **Enhance**: every request sends the same `modelscope_hub/<version>` User-Agent, with custom information appended and CLI/compat markers propagated; errors name the next step
|
|
103
|
+
- **Behaviour**: downloads and listings honour the new `MODELSCOPE_DOWNLOAD_*` and `MODELSCOPE_REPO_TREE_PAGE_*` variables listed in the environment-variable table
|
|
104
|
+
|
|
105
|
+
**v0.4.6** (2026-10-09)
|
|
106
|
+
- **Fix**: cross-region downloads cache a confirmed OSS-internal resolution per storage route (repository, revision and redirect endpoint) and probe routes in parallel, so a metadata route miss no longer suppresses the LFS probe or stalls the transfer
|
|
107
|
+
|
|
108
|
+
**v0.4.5** (2026-09-21)
|
|
109
|
+
- **Feature**: `ms agent install -r owner/name` installs an agent through a framework plugin published as a model repository, gated three times — explicit `--plugin-repo`/`MODELSCOPE_AGENT_PLUGIN_REPO`, a case-sensitive owner allow-list checked before any request, and a non-persisted trust prompt showing the manifest digest
|
|
110
|
+
- **Enhance**: upload recovery retries commit-only failures without re-uploading blobs, splits policy rejections down to single files, aborts after three fully failed batches with a resumable tracker, and only warns about capacity limits
|
|
111
|
+
- **Fix**: an `HTTP 200` create-commit answer carrying `Success:false` is reported as an error instead of a silent success
|
|
112
|
+
|
|
113
|
+
**v0.4.4** (2026-09-20)
|
|
114
|
+
- **Feature**: commit batching — at most `UPLOAD_COMMIT_BATCH_MAX_OPERATIONS` (256) actions and an 8 MiB estimated request body per commit, clamped to the server's 2000-action ceiling, with LFS pointers excluded from the body budget; oversized inline files get their own batch, and `path_in_repo` is normalised consistently below the API layer
|
|
115
|
+
- **Fix**: a repository tree page answering `403` mid-enumeration is retried instead of aborting a listing that spans hundreds of requests
|
|
116
|
+
|
|
117
|
+
**v0.4.3** (2026-09-15)
|
|
118
|
+
- **Fix**: an agent list answering `200` with `OperationNotAllowed` is reported as a permission error instead of an empty result; MCP list replies with legacy `200` + `success:false` envelopes are decoded as errors
|
|
119
|
+
|
|
120
|
+
**v0.4.2** (2026-09-10)
|
|
121
|
+
- **Feature**: `delete_files` on `HubApi` and the compat `HubApi` deletes explicit paths or glob patterns resolved against the remote file list, applied as commit `delete` actions
|
|
122
|
+
|
|
123
|
+
**v0.4.1** (2026-09-09)
|
|
124
|
+
- **Feature**: deletions go through the commit path like uploads (`delete_files` on the commit manager), because the direct repository DELETE endpoint rejects API-token authentication
|
|
125
|
+
|
|
78
126
|
**v0.4.0** (2026-09-01)
|
|
79
127
|
- **Feature**: complete OpenAPI coverage for Agent-IDP, MCP, and Studios — Agent Ed25519 identities, OIDC discovery/JWKS and signed JWT issuance (`HubApi`, `ms-hub agent-idp`); Studio lists, variables and configuration options; hosted MCP discovery; protected visibility and runtime metadata; read-only tokens can log in and rejected writes name the required tier. Agent private JWKs are only written to an explicitly requested owner-only file.
|
|
80
128
|
- **Fix**: Studio compat calls no longer leak connection options or API tokens, or drop cover images; errors distinguish permission, quota and conflicts; anonymous Studio info and log pagination work
|
|
@@ -89,9 +137,6 @@ The official Python SDK & CLI for [ModelScope Hub](https://modelscope.cn) — do
|
|
|
89
137
|
- **Feature**: this package owns all four console scripts (`modelscope`, `ms`, `modelscope-hub`, `ms-hub`), adds `HubApi.get_current_username()`, and supports both agent visibility wire formats
|
|
90
138
|
- **Fix**: large `repo/files` listings are re-enumerated when the server silently truncates results
|
|
91
139
|
|
|
92
|
-
<details>
|
|
93
|
-
<summary>Older releases</summary>
|
|
94
|
-
|
|
95
140
|
**v0.2.0** (2026-08-01)
|
|
96
141
|
- **Breaking**: `HubApi.login()` now raises `NetworkError` / `ServerError` / `RequestTimeoutError` for non-authentication failures instead of always raising `AuthenticationError` — widen `except AuthenticationError` to `HubError` if you catch *any* login failure
|
|
97
142
|
- **Fix**: network, timeout and 5xx errors during login are no longer misreported as an invalid token; a failed login no longer deletes stored credentials; bare and upper-case endpoints are accepted (e.g. `--endpoint modelscope.ai`)
|
|
@@ -255,6 +300,10 @@ path = api.download_file("Qwen/Qwen3-0.6B", "model", "config.json", local_files_
|
|
|
255
300
|
|
|
256
301
|
Downloads validate available size and SHA-256 metadata before replacing files, with safe resume, bounded retries, timeouts, and cancellation. Incomplete snapshots raise `FileDownloadError` (CLI exit code `1`), preserving completed files for subsequent retries.
|
|
257
302
|
|
|
303
|
+
Download counting: each `download_repo` / `snapshot_download` call is one snapshot download. Every file request it makes, including retries, resumed transfers and range parts, carries the same `snapshot-identifier`. The dataset service deduplicates this identifier for two hours; standalone `download_file` calls send no identifier and use fractional per-file counting. Cached files issue no download requests.
|
|
304
|
+
|
|
305
|
+
The dataset count is recorded at the first eligible file request, not when the whole download succeeds; filtered snapshots can count as one download, and cancellation does not roll it back. The server's asynchronous updates and two-hour deduplication TTL do not provide exactly-once counting for arbitrary task durations. Model and archive counting use separate server logic.
|
|
306
|
+
|
|
258
307
|
### Load kernels (`modelscope_hub.kernels`)
|
|
259
308
|
|
|
260
309
|
`modelscope_hub.kernels` is a drop-in wrapper around the [`kernels`](https://github.com/huggingface/kernels) library that downloads optimized compute kernels from ModelScope instead of the Hugging Face Hub. A kernel repository is an ordinary ModelScope model repository mirroring the HF kernel layout (`build/<variant>/...` plus `v1`-style version branches or tags):
|
|
@@ -270,13 +319,13 @@ from modelscope_hub.kernels import get_kernel
|
|
|
270
319
|
activation = get_kernel("kernels-community/activation", version=1)
|
|
271
320
|
```
|
|
272
321
|
|
|
273
|
-
Also available: `has_kernel()` (environment compatibility check), `get_kernel_variants()` (build-variant decisions), `get_local_kernel()` (load from a local path, dependencies from ModelScope), `install_kernel()` (download to the local cache without importing — CI pre-installation / offline preparation), `install_kernel_all_variants()` (download every build variant plus the dependency tree), `get_locked_kernel()` (load a kernel pinned by a lockfile, downloading missing pieces), and `load_kernel()` (import an already-installed locked kernel; never downloads). Under `patch_kernels_hub()` every other networked `kernels` entry point (the `layer`/`kernelize` APIs, benchmarks, etc.) is redirected the same way, because the whole library routes through one Hub API factory.
|
|
322
|
+
Also available: `has_kernel()` (environment compatibility check), `get_kernel_variants()` (build-variant decisions), `get_local_kernel()` (load from a local path, dependencies from ModelScope), `install_kernel()` (download to the local cache without importing — CI pre-installation / offline preparation), `install_kernel_all_variants()` (download every build variant plus the dependency tree), `lock_kernels()` (resolve the dependency tree against ModelScope and write a `kernels.lock` file — the in-process equivalent of `kernels lock`), `get_locked_kernel()` (load a kernel pinned by a lockfile, downloading missing pieces), and `load_kernel()` (import an already-installed locked kernel; never downloads). The same lockfile can be created from the command line with `ms-hub kernels lock [project_dir]`, which reads `[tool.kernels.dependencies]` from `pyproject.toml`. Under `patch_kernels_hub()` every other networked `kernels` entry point (the `layer`/`kernelize` APIs, benchmarks, etc.) is redirected the same way, because the whole library routes through one Hub API factory. The upstream `kernels lock` console script runs in its own process and therefore cannot pick up the in-process patch; use `lock_kernels()` or `ms-hub kernels lock` instead.
|
|
274
323
|
|
|
275
324
|
Notes:
|
|
276
325
|
|
|
277
326
|
- The kernel loading, variant resolution, and dependency logic of `kernels` are reused unchanged — only its Hub API factory is swapped for a ModelScope-backed shim while a `modelscope_hub.kernels` call is in flight, so a plain `import kernels` elsewhere keeps using the Hugging Face Hub. `patch_kernels_hub()` / `unpatch_kernels_hub()` / `patch_scope()` switch this explicitly if you need it globally; the `modelscope` package's `patch_hub()` builds on the same implementation.
|
|
278
327
|
- `version=N` resolves against the repository's `v<N>` branches/tags. A mirror that only carries `master` exposes it as kernel version `v1` automatically.
|
|
279
|
-
- Kernel lockfiles record hub-specific commit hashes: a lockfile created against the Hugging Face Hub cannot resolve on ModelScope (the two hubs have different git histories). Create the lockfile in the ModelScope environment (`
|
|
328
|
+
- Kernel lockfiles record hub-specific commit hashes: a lockfile created against the Hugging Face Hub cannot resolve on ModelScope (the two hubs have different git histories). Create the lockfile in the ModelScope environment (`lock_kernels()`, `install_kernel_all_variants`, or `ms-hub kernels lock`) so it records ModelScope commits; a commit-hash revision that cannot be found raises with a note explaining this.
|
|
280
329
|
- ModelScope has no trusted-publisher flag, so untrusted publishers are rejected by default: only `kernels-community` is trusted out of the box. Extend the allowlist with `MS_KERNELS_TRUSTED_PUBLISHERS` (comma-separated), or allow specific repositories / all repositories through the trust parameters of `get_kernel` (its docstring mirrors the kernel library's API).
|
|
281
330
|
- The mirror must contain kernels built for your exact Torch version and platform (`kernels` selects `build/torchXY-...-<cpu>-<os>/`); a repository whose builds predate `kernels` 0.17 metadata cannot be loaded until it is rebuilt with a current `kernel-builder`.
|
|
282
331
|
|
|
@@ -301,6 +350,7 @@ report.close() # Release temporary per-file results after consumption.
|
|
|
301
350
|
|
|
302
351
|
- Recovery defaults: at most **2 extra retries per file**, shared by range parts and integrity recovery; failed-request inactivity and waits have a **60-second cumulative budget**. Idle/header waits are limited to **15 seconds**, low-speed checks use a **10-second window**, and cooldowns longer than **5 seconds** defer the file instead of tying up a worker. Size/hash mismatches get at most one full re-download. Healthy transfer time is **not** capped by default: a transfer that keeps making progress runs to completion, and `MODELSCOPE_DOWNLOAD_TOTAL_TIMEOUT` only applies when set to a positive value.
|
|
303
352
|
- Each task uses **one hidden JSON file** outside downloaded contents (`cache_dir/.download_state/.ms_download_<key>.json` by default), with no embedded database dependency. It combines sparse failures, recovery budgets, failed pages, and the latest call's summary under `report`; `report.report_path` equals `report.tracker_path`. Reruns and batches replace the same file, without extra report JSON or JSONL files. Successful files have no persistent per-file records; a healthy run writes only its scope header and final summary, not an update per file. Its scope is endpoint/repository/revision/output, independent of batch filters. Standard reusable lock files remain separate from JSON metadata.
|
|
353
|
+
- The same JSON keeps the task's `snapshot-identifier`: reruns of an unfinished task (`PARTIAL` or `CANCELLED`) reuse it, so the dataset service can deduplicate resumed requests within its two-hour window; the run after a `COMPLETE` one starts a new task. Keeping it adds no writes beyond the scope header, exceptional records and the final summary.
|
|
304
354
|
- State is advisory, never the sole evidence of success. Every rerun validates actual files against current size/hash metadata, even if hints say `FAILED` or `DEFERRED`; a repaired valid file clears its stale hint without network IO. Otherwise failures remain isolated until metadata changes or `retry_failed=True`. Missing or corrupt hints allow bounded fresh recovery; load/write problems are logged and exposed in `report.state_warnings`, not treated as data corruption or success. A crash during recovery preserves its budget if hints were saved; healthy in-flight files need no markers and resume from actual partial files. Old database-format trackers are not read or migrated: select a new JSON path; existing correct data is reused through validation.
|
|
305
355
|
- Dataset pages are streamed with bounded queues. Failed pages are recorded and isolated across calls; later pages/roots can continue. Two consecutive failed pages stop that root, and `listing_complete=False` prevents false success. The next run can use `retry_failed=True` or an authoritative `file_list` iterable to recover incomplete enumeration. Model listings that hit an unrecoverable server cap also return a partial report.
|
|
306
356
|
- Counts and `report.iter_files()` cover **this call's selection**. Per-file results stream from an anonymous temporary spool owned by the live report, so earlier report objects remain independent of later batches without permanent manifests or an in-memory list of every file. Call `report.close()` after consumption; garbage collection also releases its spool. `results_path` is empty. The single JSON retains only the latest summary, not historical reports or a verified-file manifest: reconstructing a report from it cannot provide per-file results; rerun actual-file validation instead. Aggregate batch counts for the whole migration. Only `VERIFIED` entries may be uploaded; changed files must be checked again before use, and partial reports must not authorize deleting source data. A pinned revision or authoritative manifest is recommended. Reuse the same tracker and output across ten-file batches; a tracker cannot be shared by simultaneous writers.
|
|
@@ -33,12 +33,60 @@ The official Python SDK & CLI for [ModelScope Hub](https://modelscope.cn) — do
|
|
|
33
33
|
|
|
34
34
|
## News
|
|
35
35
|
|
|
36
|
+
**v0.7.2** (2026-11-24)
|
|
37
|
+
- **Fix**: download counting — a snapshot download (`download_repo`, `snapshot_download`, `ms-hub download`, report mode) sends one `snapshot-identifier` per task, shared by every file, retry, resumed transfer and range part, instead of a new one per file; a resumed report-mode task keeps its identifier. Standalone file downloads (`download_file`, `model_file_download`, `dataset_file_download`, CLI file arguments) no longer send one, so the Hub counts them per file. Cached dataset meta files no longer trigger a download request
|
|
38
|
+
|
|
39
|
+
**v0.7.1** (2026-11-10)
|
|
40
|
+
- **Fix**: the intra-cloud region probe is bounded per hop by `MODELSCOPE_DOWNLOAD_REGION_PROBE_TIMEOUT_SECONDS` (default `1`), so a slow probe falls back to the default route instead of stalling the download
|
|
41
|
+
|
|
42
|
+
**v0.7.0** (2026-11-09)
|
|
43
|
+
- **Feature**: `modelscope_hub.kernels` loads optimized kernels from ModelScope (`kernels` extra); `modelscope_hub.compat.hf_hub_patcher` redirects `huggingface_hub` calls to ModelScope (`hf` extra); uploads route through the commit API instead of a git clone + push
|
|
44
|
+
- **Enhance**: offline cache compatibility — `resolve_cached_snapshot` and `local_files_only` resolve standard and legacy cache layouts without network access or writes, legacy model-root links keep pre-snapshot paths valid, `ms-hub cache clear` validates scope and supports `--dry-run`, and `MODELSCOPE_CACHE` takes precedence over the `MS_CACHE_HOME` alias
|
|
45
|
+
|
|
46
|
+
<details>
|
|
47
|
+
<summary>v0.6.1 and older</summary>
|
|
48
|
+
|
|
36
49
|
**v0.6.1** (2026-10-30)
|
|
37
50
|
- **Feature**: `ms-hub download --total-timeout` (and `HubApi(download_total_timeout=...)`) sets a per-file time budget that overrides the environment variable; `0` means no limit
|
|
38
51
|
- **Behaviour**: a transfer that keeps making progress is no longer capped by default — `MODELSCOPE_DOWNLOAD_TOTAL_TIMEOUT` now defaults to `0` (was `3600`), while idle timeouts, the low-speed watchdog and bounded retries still apply; set a positive value to restore a cap
|
|
39
52
|
- **Fix**: a stop caused by an expired budget keeps its partial data and is reported as pending, so a plain re-run resumes it instead of requiring `--retry-failed`; trickling response headers stay bounded by the idle timeout when no overall budget is set
|
|
40
53
|
- **Quality**: budget and cancellation messages are English and name both the budget and the variable that relaxes it
|
|
41
54
|
|
|
55
|
+
**v0.6.0** (2026-10-29)
|
|
56
|
+
- **Feature**: model and dataset writes moved to OpenAPI — repository creation, category set/update, detail reads, model option lists and repository settings; `get_model`/`get_dataset` keep the historical `Visibility` enum, while `gated_mode=True/False` is the separate application switch
|
|
57
|
+
- **Breaking**: `approval_mode`, the `gated` request parameter and `--approval-mode` are removed; passing them through `**kwargs` raises `TypeError` before any request
|
|
58
|
+
- **Enhance**: creation keeps the v0.5.1 legacy request format when `gated_mode` is explicit, and category/zone and set-only fields are validated before sending
|
|
59
|
+
|
|
60
|
+
**v0.5.1** (2026-10-26)
|
|
61
|
+
- **Feature**: `HubApi.download_repo_report` and `ms-hub download --continue-on-error` continue past isolated file failures and return a `COMPLETE`/`PARTIAL` report; `--retry-failed` reruns them and exit code `3` means partial. `download_repo` and `snapshot_download` stay strict
|
|
62
|
+
- **Enhance**: recovery hints live in one hidden JSON per task (no embedded database), state is advisory and re-validated against actual size/hash, failed pages are isolated, and listings stream with bounded queues
|
|
63
|
+
|
|
64
|
+
**v0.5.0** (2026-10-24)
|
|
65
|
+
- **Feature**: downloads verify size and SHA-256 before replacing files, with safe resume, bounded retries, idle and total timeouts, low-speed detection, cancellation and per-file locks; an incomplete snapshot raises `FileDownloadError` (CLI exit code `1`) and keeps completed files
|
|
66
|
+
- **Enhance**: every request sends the same `modelscope_hub/<version>` User-Agent, with custom information appended and CLI/compat markers propagated; errors name the next step
|
|
67
|
+
- **Behaviour**: downloads and listings honour the new `MODELSCOPE_DOWNLOAD_*` and `MODELSCOPE_REPO_TREE_PAGE_*` variables listed in the environment-variable table
|
|
68
|
+
|
|
69
|
+
**v0.4.6** (2026-10-09)
|
|
70
|
+
- **Fix**: cross-region downloads cache a confirmed OSS-internal resolution per storage route (repository, revision and redirect endpoint) and probe routes in parallel, so a metadata route miss no longer suppresses the LFS probe or stalls the transfer
|
|
71
|
+
|
|
72
|
+
**v0.4.5** (2026-09-21)
|
|
73
|
+
- **Feature**: `ms agent install -r owner/name` installs an agent through a framework plugin published as a model repository, gated three times — explicit `--plugin-repo`/`MODELSCOPE_AGENT_PLUGIN_REPO`, a case-sensitive owner allow-list checked before any request, and a non-persisted trust prompt showing the manifest digest
|
|
74
|
+
- **Enhance**: upload recovery retries commit-only failures without re-uploading blobs, splits policy rejections down to single files, aborts after three fully failed batches with a resumable tracker, and only warns about capacity limits
|
|
75
|
+
- **Fix**: an `HTTP 200` create-commit answer carrying `Success:false` is reported as an error instead of a silent success
|
|
76
|
+
|
|
77
|
+
**v0.4.4** (2026-09-20)
|
|
78
|
+
- **Feature**: commit batching — at most `UPLOAD_COMMIT_BATCH_MAX_OPERATIONS` (256) actions and an 8 MiB estimated request body per commit, clamped to the server's 2000-action ceiling, with LFS pointers excluded from the body budget; oversized inline files get their own batch, and `path_in_repo` is normalised consistently below the API layer
|
|
79
|
+
- **Fix**: a repository tree page answering `403` mid-enumeration is retried instead of aborting a listing that spans hundreds of requests
|
|
80
|
+
|
|
81
|
+
**v0.4.3** (2026-09-15)
|
|
82
|
+
- **Fix**: an agent list answering `200` with `OperationNotAllowed` is reported as a permission error instead of an empty result; MCP list replies with legacy `200` + `success:false` envelopes are decoded as errors
|
|
83
|
+
|
|
84
|
+
**v0.4.2** (2026-09-10)
|
|
85
|
+
- **Feature**: `delete_files` on `HubApi` and the compat `HubApi` deletes explicit paths or glob patterns resolved against the remote file list, applied as commit `delete` actions
|
|
86
|
+
|
|
87
|
+
**v0.4.1** (2026-09-09)
|
|
88
|
+
- **Feature**: deletions go through the commit path like uploads (`delete_files` on the commit manager), because the direct repository DELETE endpoint rejects API-token authentication
|
|
89
|
+
|
|
42
90
|
**v0.4.0** (2026-09-01)
|
|
43
91
|
- **Feature**: complete OpenAPI coverage for Agent-IDP, MCP, and Studios — Agent Ed25519 identities, OIDC discovery/JWKS and signed JWT issuance (`HubApi`, `ms-hub agent-idp`); Studio lists, variables and configuration options; hosted MCP discovery; protected visibility and runtime metadata; read-only tokens can log in and rejected writes name the required tier. Agent private JWKs are only written to an explicitly requested owner-only file.
|
|
44
92
|
- **Fix**: Studio compat calls no longer leak connection options or API tokens, or drop cover images; errors distinguish permission, quota and conflicts; anonymous Studio info and log pagination work
|
|
@@ -53,9 +101,6 @@ The official Python SDK & CLI for [ModelScope Hub](https://modelscope.cn) — do
|
|
|
53
101
|
- **Feature**: this package owns all four console scripts (`modelscope`, `ms`, `modelscope-hub`, `ms-hub`), adds `HubApi.get_current_username()`, and supports both agent visibility wire formats
|
|
54
102
|
- **Fix**: large `repo/files` listings are re-enumerated when the server silently truncates results
|
|
55
103
|
|
|
56
|
-
<details>
|
|
57
|
-
<summary>Older releases</summary>
|
|
58
|
-
|
|
59
104
|
**v0.2.0** (2026-08-01)
|
|
60
105
|
- **Breaking**: `HubApi.login()` now raises `NetworkError` / `ServerError` / `RequestTimeoutError` for non-authentication failures instead of always raising `AuthenticationError` — widen `except AuthenticationError` to `HubError` if you catch *any* login failure
|
|
61
106
|
- **Fix**: network, timeout and 5xx errors during login are no longer misreported as an invalid token; a failed login no longer deletes stored credentials; bare and upper-case endpoints are accepted (e.g. `--endpoint modelscope.ai`)
|
|
@@ -219,6 +264,10 @@ path = api.download_file("Qwen/Qwen3-0.6B", "model", "config.json", local_files_
|
|
|
219
264
|
|
|
220
265
|
Downloads validate available size and SHA-256 metadata before replacing files, with safe resume, bounded retries, timeouts, and cancellation. Incomplete snapshots raise `FileDownloadError` (CLI exit code `1`), preserving completed files for subsequent retries.
|
|
221
266
|
|
|
267
|
+
Download counting: each `download_repo` / `snapshot_download` call is one snapshot download. Every file request it makes, including retries, resumed transfers and range parts, carries the same `snapshot-identifier`. The dataset service deduplicates this identifier for two hours; standalone `download_file` calls send no identifier and use fractional per-file counting. Cached files issue no download requests.
|
|
268
|
+
|
|
269
|
+
The dataset count is recorded at the first eligible file request, not when the whole download succeeds; filtered snapshots can count as one download, and cancellation does not roll it back. The server's asynchronous updates and two-hour deduplication TTL do not provide exactly-once counting for arbitrary task durations. Model and archive counting use separate server logic.
|
|
270
|
+
|
|
222
271
|
### Load kernels (`modelscope_hub.kernels`)
|
|
223
272
|
|
|
224
273
|
`modelscope_hub.kernels` is a drop-in wrapper around the [`kernels`](https://github.com/huggingface/kernels) library that downloads optimized compute kernels from ModelScope instead of the Hugging Face Hub. A kernel repository is an ordinary ModelScope model repository mirroring the HF kernel layout (`build/<variant>/...` plus `v1`-style version branches or tags):
|
|
@@ -234,13 +283,13 @@ from modelscope_hub.kernels import get_kernel
|
|
|
234
283
|
activation = get_kernel("kernels-community/activation", version=1)
|
|
235
284
|
```
|
|
236
285
|
|
|
237
|
-
Also available: `has_kernel()` (environment compatibility check), `get_kernel_variants()` (build-variant decisions), `get_local_kernel()` (load from a local path, dependencies from ModelScope), `install_kernel()` (download to the local cache without importing — CI pre-installation / offline preparation), `install_kernel_all_variants()` (download every build variant plus the dependency tree), `get_locked_kernel()` (load a kernel pinned by a lockfile, downloading missing pieces), and `load_kernel()` (import an already-installed locked kernel; never downloads). Under `patch_kernels_hub()` every other networked `kernels` entry point (the `layer`/`kernelize` APIs, benchmarks, etc.) is redirected the same way, because the whole library routes through one Hub API factory.
|
|
286
|
+
Also available: `has_kernel()` (environment compatibility check), `get_kernel_variants()` (build-variant decisions), `get_local_kernel()` (load from a local path, dependencies from ModelScope), `install_kernel()` (download to the local cache without importing — CI pre-installation / offline preparation), `install_kernel_all_variants()` (download every build variant plus the dependency tree), `lock_kernels()` (resolve the dependency tree against ModelScope and write a `kernels.lock` file — the in-process equivalent of `kernels lock`), `get_locked_kernel()` (load a kernel pinned by a lockfile, downloading missing pieces), and `load_kernel()` (import an already-installed locked kernel; never downloads). The same lockfile can be created from the command line with `ms-hub kernels lock [project_dir]`, which reads `[tool.kernels.dependencies]` from `pyproject.toml`. Under `patch_kernels_hub()` every other networked `kernels` entry point (the `layer`/`kernelize` APIs, benchmarks, etc.) is redirected the same way, because the whole library routes through one Hub API factory. The upstream `kernels lock` console script runs in its own process and therefore cannot pick up the in-process patch; use `lock_kernels()` or `ms-hub kernels lock` instead.
|
|
238
287
|
|
|
239
288
|
Notes:
|
|
240
289
|
|
|
241
290
|
- The kernel loading, variant resolution, and dependency logic of `kernels` are reused unchanged — only its Hub API factory is swapped for a ModelScope-backed shim while a `modelscope_hub.kernels` call is in flight, so a plain `import kernels` elsewhere keeps using the Hugging Face Hub. `patch_kernels_hub()` / `unpatch_kernels_hub()` / `patch_scope()` switch this explicitly if you need it globally; the `modelscope` package's `patch_hub()` builds on the same implementation.
|
|
242
291
|
- `version=N` resolves against the repository's `v<N>` branches/tags. A mirror that only carries `master` exposes it as kernel version `v1` automatically.
|
|
243
|
-
- Kernel lockfiles record hub-specific commit hashes: a lockfile created against the Hugging Face Hub cannot resolve on ModelScope (the two hubs have different git histories). Create the lockfile in the ModelScope environment (`
|
|
292
|
+
- Kernel lockfiles record hub-specific commit hashes: a lockfile created against the Hugging Face Hub cannot resolve on ModelScope (the two hubs have different git histories). Create the lockfile in the ModelScope environment (`lock_kernels()`, `install_kernel_all_variants`, or `ms-hub kernels lock`) so it records ModelScope commits; a commit-hash revision that cannot be found raises with a note explaining this.
|
|
244
293
|
- ModelScope has no trusted-publisher flag, so untrusted publishers are rejected by default: only `kernels-community` is trusted out of the box. Extend the allowlist with `MS_KERNELS_TRUSTED_PUBLISHERS` (comma-separated), or allow specific repositories / all repositories through the trust parameters of `get_kernel` (its docstring mirrors the kernel library's API).
|
|
245
294
|
- The mirror must contain kernels built for your exact Torch version and platform (`kernels` selects `build/torchXY-...-<cpu>-<os>/`); a repository whose builds predate `kernels` 0.17 metadata cannot be loaded until it is rebuilt with a current `kernel-builder`.
|
|
246
295
|
|
|
@@ -265,6 +314,7 @@ report.close() # Release temporary per-file results after consumption.
|
|
|
265
314
|
|
|
266
315
|
- Recovery defaults: at most **2 extra retries per file**, shared by range parts and integrity recovery; failed-request inactivity and waits have a **60-second cumulative budget**. Idle/header waits are limited to **15 seconds**, low-speed checks use a **10-second window**, and cooldowns longer than **5 seconds** defer the file instead of tying up a worker. Size/hash mismatches get at most one full re-download. Healthy transfer time is **not** capped by default: a transfer that keeps making progress runs to completion, and `MODELSCOPE_DOWNLOAD_TOTAL_TIMEOUT` only applies when set to a positive value.
|
|
267
316
|
- Each task uses **one hidden JSON file** outside downloaded contents (`cache_dir/.download_state/.ms_download_<key>.json` by default), with no embedded database dependency. It combines sparse failures, recovery budgets, failed pages, and the latest call's summary under `report`; `report.report_path` equals `report.tracker_path`. Reruns and batches replace the same file, without extra report JSON or JSONL files. Successful files have no persistent per-file records; a healthy run writes only its scope header and final summary, not an update per file. Its scope is endpoint/repository/revision/output, independent of batch filters. Standard reusable lock files remain separate from JSON metadata.
|
|
317
|
+
- The same JSON keeps the task's `snapshot-identifier`: reruns of an unfinished task (`PARTIAL` or `CANCELLED`) reuse it, so the dataset service can deduplicate resumed requests within its two-hour window; the run after a `COMPLETE` one starts a new task. Keeping it adds no writes beyond the scope header, exceptional records and the final summary.
|
|
268
318
|
- State is advisory, never the sole evidence of success. Every rerun validates actual files against current size/hash metadata, even if hints say `FAILED` or `DEFERRED`; a repaired valid file clears its stale hint without network IO. Otherwise failures remain isolated until metadata changes or `retry_failed=True`. Missing or corrupt hints allow bounded fresh recovery; load/write problems are logged and exposed in `report.state_warnings`, not treated as data corruption or success. A crash during recovery preserves its budget if hints were saved; healthy in-flight files need no markers and resume from actual partial files. Old database-format trackers are not read or migrated: select a new JSON path; existing correct data is reused through validation.
|
|
269
319
|
- Dataset pages are streamed with bounded queues. Failed pages are recorded and isolated across calls; later pages/roots can continue. Two consecutive failed pages stop that root, and `listing_complete=False` prevents false success. The next run can use `retry_failed=True` or an authoritative `file_list` iterable to recover incomplete enumeration. Model listings that hit an unrecoverable server cap also return a partial report.
|
|
270
320
|
- Counts and `report.iter_files()` cover **this call's selection**. Per-file results stream from an anonymous temporary spool owned by the live report, so earlier report objects remain independent of later batches without permanent manifests or an in-memory list of every file. Call `report.close()` after consumption; garbage collection also releases its spool. `results_path` is empty. The single JSON retains only the latest summary, not historical reports or a verified-file manifest: reconstructing a report from it cannot provide per-file results; rerun actual-file validation instead. Aggregate batch counts for the whole migration. Only `VERIFIED` entries may be uploaded; changed files must be checked again before use, and partial reports must not authorize deleting source data. A pinned revision or authoritative manifest is recommended. Reuse the same tracker and output across ten-file batches; a tracker cannot be shared by simultaneous writers.
|
|
@@ -105,5 +105,5 @@ strict = false
|
|
|
105
105
|
warn_return_any = false
|
|
106
106
|
|
|
107
107
|
[[tool.mypy.overrides]]
|
|
108
|
-
module = ["tqdm.*", "modelscope.*", "kernels.*", "huggingface_hub.*"]
|
|
108
|
+
module = ["tqdm.*", "modelscope.*", "kernels.*", "huggingface_hub.*", "tomllib", "tomli"]
|
|
109
109
|
ignore_missing_imports = true
|
|
@@ -8,7 +8,7 @@ Supports single-file and whole-repo (snapshot) downloads with:
|
|
|
8
8
|
- Parallel range download (split large files into parts)
|
|
9
9
|
- Per-file download retry with backoff
|
|
10
10
|
- File lock for multiprocess safety
|
|
11
|
-
- User-agent
|
|
11
|
+
- User-agent headers and a task-scoped snapshot identifier
|
|
12
12
|
- Intra-cloud acceleration
|
|
13
13
|
- Local-files-only (offline) mode
|
|
14
14
|
- Custom progress callbacks
|
|
@@ -103,6 +103,15 @@ DOWNLOAD_INTEGRITY_RETRY_BACKOFF = 1.0
|
|
|
103
103
|
_DIAGNOSTIC_HEADERS = ("x-oss-request-id", "x-request-id", "eagleid", "x-cache", "x-linked-etag")
|
|
104
104
|
_CONTENT_RANGE_RE = re.compile(r"bytes\s+(\d+)-(\d+)/(\d+|\*)", re.IGNORECASE)
|
|
105
105
|
|
|
106
|
+
# Groups the file requests of one logical repository snapshot download so the Hub
|
|
107
|
+
# counts the task once. Standalone file downloads never send it.
|
|
108
|
+
_SNAPSHOT_IDENTIFIER_HEADER = "snapshot-identifier"
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _new_snapshot_id() -> str:
|
|
112
|
+
"""Return a fresh identifier for one logical repository snapshot download."""
|
|
113
|
+
return uuid.uuid4().hex
|
|
114
|
+
|
|
106
115
|
|
|
107
116
|
# ---------------------------------------------------------------------------
|
|
108
117
|
# Progress callback system
|
|
@@ -867,14 +876,22 @@ class DownloadManager:
|
|
|
867
876
|
user_agent: dict | str | None = None,
|
|
868
877
|
*,
|
|
869
878
|
accelerate: bool = True,
|
|
879
|
+
snapshot_id: str | None = None,
|
|
870
880
|
) -> dict[str, str]:
|
|
881
|
+
"""Build the headers shared by every attempt of one file transfer.
|
|
882
|
+
|
|
883
|
+
*snapshot_id* identifies the snapshot download the file belongs to and is
|
|
884
|
+
sent verbatim when non-blank. It is never generated here: standalone file
|
|
885
|
+
downloads pass ``None`` and send no snapshot identifier.
|
|
886
|
+
"""
|
|
871
887
|
from .constants import _env, _env_bool
|
|
872
888
|
|
|
873
889
|
headers: dict[str, str] = {
|
|
874
890
|
"user-agent": self._build_user_agent(user_agent),
|
|
875
|
-
"snapshot-identifier": uuid.uuid4().hex,
|
|
876
891
|
"Accept-Encoding": "identity",
|
|
877
892
|
}
|
|
893
|
+
if snapshot_id and snapshot_id.strip():
|
|
894
|
+
headers[_SNAPSHOT_IDENTIFIER_HEADER] = snapshot_id
|
|
878
895
|
if accelerate and _env_bool(ENV_INTRA_CLOUD_ACCELERATION, True):
|
|
879
896
|
region = (_env(ENV_INTRA_CLOUD_REGION, "INTRA_CLOUD_ACCELERATION_REGION") or "").strip()
|
|
880
897
|
if not region:
|
|
@@ -905,8 +922,13 @@ class DownloadManager:
|
|
|
905
922
|
progress_callbacks: list[type[ProgressCallback]] | None = None,
|
|
906
923
|
_cancel_event: threading.Event | None = None,
|
|
907
924
|
_recovery: _RecoveryBudget | None = None,
|
|
925
|
+
_snapshot_id: str | None = None,
|
|
908
926
|
) -> Path:
|
|
909
|
-
"""Download one file with cache-first lookup and a shared budget for locks, probes, and retries.
|
|
927
|
+
"""Download one file with cache-first lookup and a shared budget for locks, probes, and retries.
|
|
928
|
+
|
|
929
|
+
*_snapshot_id* is supplied only by snapshot downloads. A standalone call
|
|
930
|
+
sends no snapshot identifier, so the Hub counts it per file.
|
|
931
|
+
"""
|
|
910
932
|
with _DownloadControl(
|
|
911
933
|
total_timeout=DOWNLOAD_TOTAL_TIMEOUT if self._total_timeout is None else self._total_timeout,
|
|
912
934
|
cancel_event=_cancel_event,
|
|
@@ -934,6 +956,7 @@ class DownloadManager:
|
|
|
934
956
|
user_agent,
|
|
935
957
|
progress_callbacks,
|
|
936
958
|
_control=control,
|
|
959
|
+
_snapshot_id=_snapshot_id,
|
|
937
960
|
)
|
|
938
961
|
|
|
939
962
|
def _download_file(
|
|
@@ -952,6 +975,7 @@ class DownloadManager:
|
|
|
952
975
|
progress_callbacks: list[type[ProgressCallback]] | None = None,
|
|
953
976
|
*,
|
|
954
977
|
_control: _DownloadControl,
|
|
978
|
+
_snapshot_id: str | None = None,
|
|
955
979
|
) -> Path:
|
|
956
980
|
"""Download a single file from a repository.
|
|
957
981
|
|
|
@@ -992,6 +1016,9 @@ class DownloadManager:
|
|
|
992
1016
|
progress_callbacks:
|
|
993
1017
|
List of :class:`ProgressCallback` *classes* (not instances).
|
|
994
1018
|
Each class is instantiated per-file with ``(filename, file_size)``.
|
|
1019
|
+
_snapshot_id:
|
|
1020
|
+
Identifier of the enclosing snapshot download, reused by every
|
|
1021
|
+
attempt including integrity retries. ``None`` for standalone downloads.
|
|
995
1022
|
|
|
996
1023
|
Returns
|
|
997
1024
|
-------
|
|
@@ -1070,6 +1097,7 @@ class DownloadManager:
|
|
|
1070
1097
|
prefer_default_route=prefer_default_route,
|
|
1071
1098
|
control=_control,
|
|
1072
1099
|
expected_sha256=expected_sha256,
|
|
1100
|
+
snapshot_id=_snapshot_id,
|
|
1073
1101
|
)
|
|
1074
1102
|
break
|
|
1075
1103
|
except FileIntegrityError as exc:
|
|
@@ -1155,9 +1183,16 @@ class DownloadManager:
|
|
|
1155
1183
|
user_agent: dict | str | None = None,
|
|
1156
1184
|
progress_callbacks: list[type[ProgressCallback]] | None = None,
|
|
1157
1185
|
file_list: list[dict] | None = None,
|
|
1186
|
+
_snapshot_id: str | None = None,
|
|
1158
1187
|
) -> Path:
|
|
1159
1188
|
"""Download an entire repository (snapshot download).
|
|
1160
1189
|
|
|
1190
|
+
Each call is one logical snapshot download: every file request it issues,
|
|
1191
|
+
including retries, resumed transfers and range parts, carries the same
|
|
1192
|
+
``snapshot-identifier`` for server-side dataset deduplication. A non-blank
|
|
1193
|
+
caller-supplied *_snapshot_id* is preserved; otherwise a fresh one is generated.
|
|
1194
|
+
Files that are already cached issue no requests.
|
|
1195
|
+
|
|
1161
1196
|
Parameters
|
|
1162
1197
|
----------
|
|
1163
1198
|
repo_id:
|
|
@@ -1289,6 +1324,8 @@ class DownloadManager:
|
|
|
1289
1324
|
logger.info("No files to download for %s@%s", repo_id, effective_revision)
|
|
1290
1325
|
return output_dir
|
|
1291
1326
|
|
|
1327
|
+
snapshot_id = _snapshot_id if _snapshot_id and _snapshot_id.strip() else _new_snapshot_id()
|
|
1328
|
+
logger.debug("Snapshot download %s of %s@%s", snapshot_id, repo_id, effective_revision)
|
|
1292
1329
|
logger.info("Downloading %d files from %s@%s", len(download_items), repo_id, effective_revision)
|
|
1293
1330
|
|
|
1294
1331
|
failures: dict[str, BaseException] = {}
|
|
@@ -1314,6 +1351,7 @@ class DownloadManager:
|
|
|
1314
1351
|
user_agent=user_agent,
|
|
1315
1352
|
progress_callbacks=progress_callbacks,
|
|
1316
1353
|
_cancel_event=cancel_event,
|
|
1354
|
+
_snapshot_id=snapshot_id,
|
|
1317
1355
|
)
|
|
1318
1356
|
futures[future] = fp
|
|
1319
1357
|
|
|
@@ -1806,6 +1844,7 @@ class DownloadManager:
|
|
|
1806
1844
|
prefer_default_route: bool = False,
|
|
1807
1845
|
control: _DownloadControl,
|
|
1808
1846
|
expected_sha256: str | None = None,
|
|
1847
|
+
snapshot_id: str | None = None,
|
|
1809
1848
|
) -> Path:
|
|
1810
1849
|
"""Download a file with HTTP Range resume support and retry.
|
|
1811
1850
|
|
|
@@ -1815,11 +1854,14 @@ class DownloadManager:
|
|
|
1815
1854
|
body whose size contradicts the listing raises
|
|
1816
1855
|
:class:`~.errors.FileSizeMismatchError` and leaves no partial file.
|
|
1817
1856
|
*prefer_default_route* skips intra-cloud and peer-region routing so a
|
|
1818
|
-
retry can avoid a replica that served bad content.
|
|
1857
|
+
retry can avoid a replica that served bad content. *snapshot_id* is
|
|
1858
|
+
carried by every attempt, range part and route probe of this file.
|
|
1819
1859
|
"""
|
|
1820
1860
|
use_parallel = file_size is not None and file_size > DOWNLOAD_PARALLEL_THRESHOLD and DOWNLOAD_PARALLELS > 1
|
|
1821
1861
|
|
|
1822
|
-
download_headers = self._build_download_headers(
|
|
1862
|
+
download_headers = self._build_download_headers(
|
|
1863
|
+
user_agent, accelerate=not prefer_default_route, snapshot_id=snapshot_id
|
|
1864
|
+
)
|
|
1823
1865
|
|
|
1824
1866
|
# Inter-region acceleration: first discover the file's storage route,
|
|
1825
1867
|
# then cache only a confirmed internal resolution for that exact route.
|
|
@@ -14,12 +14,15 @@ from pathlib import Path
|
|
|
14
14
|
from typing import TextIO
|
|
15
15
|
from urllib.parse import urlsplit, urlunsplit
|
|
16
16
|
|
|
17
|
+
from ._download import _new_snapshot_id
|
|
17
18
|
from .errors import InvalidParameter
|
|
18
19
|
from .types import DownloadFileResult, DownloadReport
|
|
19
20
|
from .utils.logger import get_logger
|
|
20
21
|
|
|
21
22
|
logger = get_logger("download")
|
|
22
23
|
|
|
24
|
+
_SNAPSHOT_ID_RE = re.compile(r"[0-9a-f]{32}")
|
|
25
|
+
|
|
23
26
|
|
|
24
27
|
def safe_error(error: BaseException) -> str:
|
|
25
28
|
"""Keep diagnostics without persisting credentials or presigned queries."""
|
|
@@ -36,10 +39,17 @@ def safe_error(error: BaseException) -> str:
|
|
|
36
39
|
class _DownloadState:
|
|
37
40
|
"""Sparse JSON recovery hints, never an authority for file completeness.
|
|
38
41
|
|
|
39
|
-
Persist exceptional files, failed pages,
|
|
40
|
-
Per-file results stay in an anonymous spool
|
|
41
|
-
no permanent JSONL or per-run summary files
|
|
42
|
-
do not rewrite the tracker; actual partial
|
|
42
|
+
Persist exceptional files, failed pages, the latest summary and the task's
|
|
43
|
+
snapshot identifier together. Per-file results stay in an anonymous spool
|
|
44
|
+
owned by the returned report; no permanent JSONL or per-run summary files
|
|
45
|
+
are created. Healthy transfers do not rewrite the tracker; actual partial
|
|
46
|
+
files suffice after a crash.
|
|
47
|
+
|
|
48
|
+
The snapshot identifier stays open while the task is unfinished, so a rerun
|
|
49
|
+
after a PARTIAL or CANCELLED run (or a crash) keeps counting as the same
|
|
50
|
+
snapshot download. A COMPLETE run closes it and the next run starts a new
|
|
51
|
+
task. It is written only alongside the scope header of a new tracker, an
|
|
52
|
+
exceptional record or the final summary, never as an extra write.
|
|
43
53
|
"""
|
|
44
54
|
|
|
45
55
|
def __init__(self, path: Path, identity: dict[str, str]) -> None:
|
|
@@ -55,15 +65,24 @@ class _DownloadState:
|
|
|
55
65
|
self._spool: TextIO | None = tempfile.TemporaryFile(mode="w+t", encoding="utf-8")
|
|
56
66
|
self._counts: dict[str, int] = {}
|
|
57
67
|
self._summary: dict | None = None
|
|
68
|
+
self._snapshot: dict | None = None
|
|
58
69
|
self.warnings: list[str] = []
|
|
59
70
|
try:
|
|
60
71
|
self._load()
|
|
72
|
+
if self._snapshot is None:
|
|
73
|
+
self._snapshot = {"id": _new_snapshot_id(), "open": True}
|
|
61
74
|
if not path.exists():
|
|
62
75
|
self._save()
|
|
63
76
|
except BaseException:
|
|
64
77
|
self.close()
|
|
65
78
|
raise
|
|
66
79
|
|
|
80
|
+
@property
|
|
81
|
+
def snapshot_id(self) -> str:
|
|
82
|
+
"""Identifier shared by every file request of this download task."""
|
|
83
|
+
assert self._snapshot is not None
|
|
84
|
+
return str(self._snapshot["id"])
|
|
85
|
+
|
|
67
86
|
def _warn(self, message: str) -> None:
|
|
68
87
|
if message not in self.warnings and len(self.warnings) < 10:
|
|
69
88
|
self.warnings.append(message)
|
|
@@ -80,6 +99,14 @@ class _DownloadState:
|
|
|
80
99
|
raise InvalidParameter(
|
|
81
100
|
"Download tracker belongs to a different endpoint/repository/revision/output directory"
|
|
82
101
|
)
|
|
102
|
+
snapshot = data.get("snapshot")
|
|
103
|
+
if (
|
|
104
|
+
isinstance(snapshot, dict)
|
|
105
|
+
and snapshot.get("open") is True
|
|
106
|
+
and isinstance(snapshot.get("id"), str)
|
|
107
|
+
and _SNAPSHOT_ID_RE.fullmatch(snapshot["id"])
|
|
108
|
+
):
|
|
109
|
+
self._snapshot = {"id": snapshot["id"], "open": True}
|
|
83
110
|
files, pages = data.get("files", {}), data.get("pages", {})
|
|
84
111
|
if not isinstance(files, dict) or not isinstance(pages, dict):
|
|
85
112
|
raise ValueError("Invalid recovery records")
|
|
@@ -121,6 +148,7 @@ class _DownloadState:
|
|
|
121
148
|
except (ValueError, UnicodeError, OSError):
|
|
122
149
|
self._exceptions.clear()
|
|
123
150
|
self._pages.clear()
|
|
151
|
+
self._snapshot = None
|
|
124
152
|
self._warn(
|
|
125
153
|
"Cannot load download recovery hints; continuing with actual-file validation and bounded retries"
|
|
126
154
|
)
|
|
@@ -144,6 +172,7 @@ class _DownloadState:
|
|
|
144
172
|
"files": {path: asdict(result) for path, result in self._exceptions.items()},
|
|
145
173
|
"pages": self._pages,
|
|
146
174
|
"report": self._summary,
|
|
175
|
+
"snapshot": self._snapshot,
|
|
147
176
|
},
|
|
148
177
|
stream,
|
|
149
178
|
ensure_ascii=False,
|
|
@@ -256,6 +285,8 @@ class _DownloadState:
|
|
|
256
285
|
report._attach_file_results(self._spool)
|
|
257
286
|
self._spool = None
|
|
258
287
|
self._summary = {**asdict(report), "run_id": run}
|
|
288
|
+
if self._snapshot is not None:
|
|
289
|
+
self._snapshot["open"] = report.status != "COMPLETE"
|
|
259
290
|
self._save()
|
|
260
291
|
report.state_warnings = list(self.warnings)
|
|
261
292
|
return report
|
|
@@ -81,6 +81,9 @@ def download_repo_report(
|
|
|
81
81
|
A tracker is scoped to endpoint, repo, revision and output, not include
|
|
82
82
|
patterns, so repeated ten-file batches share quarantine and retry budgets.
|
|
83
83
|
retry_failed is an explicit operator-authorized reset, never automatic.
|
|
84
|
+
Every file request of the task carries the snapshot identifier kept in the
|
|
85
|
+
tracker: reruns of an unfinished task reuse it, and the run after a
|
|
86
|
+
COMPLETE one starts a new task.
|
|
84
87
|
"""
|
|
85
88
|
if not repo_id or max_workers < 1:
|
|
86
89
|
raise InvalidParameter("repo_id and a positive max_workers are required")
|
|
@@ -160,6 +163,8 @@ def _run(
|
|
|
160
163
|
cache_dir: Path | None,
|
|
161
164
|
) -> DownloadReport:
|
|
162
165
|
run = uuid.uuid4().hex
|
|
166
|
+
snapshot_id = state.snapshot_id
|
|
167
|
+
logger.debug("Snapshot download %s of %s@%s", snapshot_id, repo_id, revision)
|
|
163
168
|
report = DownloadReport(repo_id=repo_id, revision=revision, output_dir=str(output), tracker_path=str(state.path))
|
|
164
169
|
stop = threading.Event()
|
|
165
170
|
incoming: queue.Queue[tuple[dict | None, str | None]] = queue.Queue(maxsize=workers * 4)
|
|
@@ -273,6 +278,7 @@ def _run(
|
|
|
273
278
|
progress_callbacks=callbacks,
|
|
274
279
|
_cancel_event=stop,
|
|
275
280
|
_recovery=recovery,
|
|
281
|
+
_snapshot_id=snapshot_id,
|
|
276
282
|
)
|
|
277
283
|
except _DownloadCancelledError:
|
|
278
284
|
state.finish(result.path, result.status if result.status in ("FAILED", "DEFERRED") else "PENDING")
|
|
@@ -2291,7 +2291,9 @@ class HubApi:
|
|
|
2291
2291
|
|
|
2292
2292
|
The file is fetched into the local cache and a path pointing at the
|
|
2293
2293
|
cached blob is returned. Subsequent calls reuse the cached copy
|
|
2294
|
-
unless ``force=True``.
|
|
2294
|
+
unless ``force=True``. A standalone file download sends no
|
|
2295
|
+
``snapshot-identifier``; the dataset service uses fractional per-file
|
|
2296
|
+
counting for these requests. Model counting uses separate server logic.
|
|
2295
2297
|
|
|
2296
2298
|
Parameters
|
|
2297
2299
|
----------
|
|
@@ -2404,6 +2406,9 @@ class HubApi:
|
|
|
2404
2406
|
its JSON has the latest summary under 'report', without per-run files.
|
|
2405
2407
|
iter_files streams temporary results owned by the live report; call
|
|
2406
2408
|
report.close() after consumption. Persisted hints cannot prove success.
|
|
2409
|
+
Every file request of a task carries one ``snapshot-identifier`` kept in
|
|
2410
|
+
the same JSON: reruns of an unfinished task (PARTIAL or CANCELLED) reuse
|
|
2411
|
+
it, and the run after a COMPLETE one starts a new task.
|
|
2407
2412
|
"""
|
|
2408
2413
|
return self.downloader.download_repo_report(
|
|
2409
2414
|
repo_id,
|
|
@@ -2441,7 +2446,11 @@ class HubApi:
|
|
|
2441
2446
|
"""Download an entire repository snapshot.
|
|
2442
2447
|
|
|
2443
2448
|
All files at the given ``revision`` are fetched into the local cache
|
|
2444
|
-
in parallel. The returned path is the snapshot root directory.
|
|
2449
|
+
in parallel. The returned path is the snapshot root directory. Each
|
|
2450
|
+
call is one logical snapshot download: all of its file requests,
|
|
2451
|
+
including retries, resumed transfers and range parts, carry the same
|
|
2452
|
+
``snapshot-identifier`` for dataset counting within the server's
|
|
2453
|
+
two-hour deduplication window. Cached files issue no download requests.
|
|
2445
2454
|
|
|
2446
2455
|
Parameters
|
|
2447
2456
|
----------
|