A Python package to assist with ModelScope downloads
Project description
ModelScope IPv6 Download Assistant
简洁、稳定的 ModelScope 下载助手,专为 IPv6 网络环境优化,采用“两阶段”下载流程,支持并发与续传。
亮点特性
- 两阶段下载:先生成“计划”,再按计划高效下载
- IPv6 优化:可在下载阶段强制仅走 IPv6
- 并发与续传:多线程下载、跳过已存在或强制覆盖
- 灵活过滤:按通配符仅下载需要的文件
- 统一日志:进度条与彩色日志和谐共存
安装
# 生产环境(不包含 plan 依赖)
pip install .
# 开发环境(不包含 plan 依赖)
pip install -e ".[dev]"
# 如需使用 plan 子命令,请额外安装可选的 plan 依赖:
pip install -e ".[plan]" # 仅 plan 依赖
pip install -e ".[dev,plan]" # 开发依赖 + plan 依赖
快速开始
- 生成下载计划(plan)
# 模型
ms-ipv6 plan model Qwen/Qwen2-7B-Instruct
# 数据集
ms-ipv6 plan dataset AI-MO/NuminaMath-1.5
# 可选:指定输出 / 过滤 / token
ms-ipv6 plan model user/model \
--output my_plan.json \
--token $MODELSCOPE_API_TOKEN \
--allow-pattern "*.safetensors" \
--ignore-pattern "*.tmp"
计划文件默认命名为:{repo_type}__{repo_id}.json,其中 / 会替换为 __。
- 根据计划执行下载(download)
# 基本下载(plan 为位置参数)
ms-ipv6 download model__Qwen__Qwen2-7B-Instruct.json --local-dir ./models/
# 并发与覆盖控制
ms-ipv6 download my_plan.json --local-dir ./downloads/ --workers 8 --overwrite
# 超时设置(秒)
ms-ipv6 download my_plan.json --local-dir ./downloads/ --timeout 120
CLI 参考
提示:所有“全局选项”必须放在子命令之后使用。
-
全局:
--verbose, -v开启详细日志--version或子命令version显示版本
-
生成计划:
- 用法:
ms-ipv6 plan [model|dataset] <repo_id> [--output <file>] [--token <TOKEN>] [--allow-pattern PATTERN ...] [--ignore-pattern PATTERN ...] [-v] - 说明:
repo_id形如user/repo- 默认输出:
{repo_type}__{repo_id}.json --token可选,未提供时将从环境变量MODELSCOPE_API_TOKEN读取(当前版本暂未实际使用)
- 注意:未安装可选依赖
plan将无法执行plan子命令
- 用法:
-
执行下载:
- 用法:
ms-ipv6 download <plan.json> --local-dir <DIR> [--ipv6] [--workers N] [--overwrite] [--no-skip-existing] [--only-raw | --only-no-raw] [--timeout SEC] [-v] - 说明:
plan.json为位置参数--overwrite优先于--no-skip-existing--only-raw与--only-no-raw二选一,不建议同时使用
- 用法:
设计说明(为何仅下载阶段支持 IPv6)
- 计划生成(plan)阶段依赖 ModelScope 主站 API/SDK,当前不支持 IPv6 直连
- 下载(download)阶段由本工具自行发起 HTTP 请求,提供 IPv6 能力(
--ipv6)
示例场景
下载完整模型:
ms-ipv6 plan model Qwen/Qwen2-7B-Instruct
ms-ipv6 download model__Qwen__Qwen2-7B-Instruct.json --local-dir ./models/qwen2-7b/
仅下载权重:
ms-ipv6 plan model user/model --allow-pattern "*.safetensors" --allow-pattern "*.bin"
ms-ipv6 download model__user__model.json --local-dir ./weights/
IPv6 环境推荐:
ms-ipv6 plan model user/model
ms-ipv6 download --ipv6 model__user__model.json --local-dir ./downloads/ --only-raw -v
故障排查
- 无法连通 IPv6:确认本机/网络具备 IPv6 出口;可尝试去掉
--ipv6或仅测试--only-raw - 下载很慢/超时:适度调大
--timeout,增加--workers,或关闭--only-raw - 403/权限问题:确认目标仓库权限或登录要求
- 文件已存在:默认跳过;如需覆盖,添加
--overwrite
开发
环境要求:Python 3.8+(推荐 3.11),支持 IPv4/IPv6。
安装开发依赖:
pip install -e ".[dev]"
质量与测试:
ruff check . && ruff format .
mypy ms_ipv6/
pytest -q
许可证
MIT License
开发:打包与上传到 PyPI
本项目使用 PEP 517/518 风格打包。下面是常用脚本(位于 scripts/):
scripts/build.sh: 清理先前构建并使用python -m build生成dist/下的sdist和wheel。scripts/upload_pypi.sh: 使用twine将dist/*上传到 PyPI。支持通过环境变量TWINE_REPOSITORY_URL指定自定义仓库。scripts/release.sh: 先执行构建,然后可选择上传(可传--repository-url或--skip-upload)。
快速使用:
# 安装开发依赖(包含 build, twine)
pip install -e ".[dev]"
# 构建分发包
./scripts/build.sh
# 上传到 PyPI(或配置 ~/.pypirc),或使用环境变量:
TWINE_USERNAME=__token__ TWINE_PASSWORD=$PYPI_API_TOKEN ./scripts/upload_pypi.sh
# 一步发布(可指定 --repository-url 或 --skip-upload)
./scripts/release.sh --repository-url https://upload.pypi.org/legacy/
安全提示:建议使用 PyPI API 令牌(在 TWINE_USERNAME 中使用 __token__,在 TWINE_PASSWORD 中使用令牌),或配置安全的 ~/.pypirc 文件。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ms_ipv6-0.1.1.tar.gz.
File metadata
- Download URL: ms_ipv6-0.1.1.tar.gz
- Upload date:
- Size: 67.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42c6ee5f84c4451ebc010b3ecde67dc4a49b7d2a616b58561d82513fb073fc14
|
|
| MD5 |
16c043043857d0f760933f08ad0cb357
|
|
| BLAKE2b-256 |
c8d9ce57d07e410784aa2cf2251453060168f5679dbbae660e201cc49ced038c
|
File details
Details for the file ms_ipv6-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ms_ipv6-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e43d910d92f9689546b1415d3b7fbead21da591ba405dd3eb4aa4419d1ad262a
|
|
| MD5 |
245eef453774d594ef9335da4f3d852a
|
|
| BLAKE2b-256 |
5b85c17ea1590646140a727f702b322578bf9c9f0c40d4669026887776a3fc06
|