ms2hf 0.1.0__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.
- ms2hf-0.1.0/LICENSE +201 -0
- ms2hf-0.1.0/PKG-INFO +496 -0
- ms2hf-0.1.0/README.md +466 -0
- ms2hf-0.1.0/ms2hf.egg-info/PKG-INFO +496 -0
- ms2hf-0.1.0/ms2hf.egg-info/SOURCES.txt +10 -0
- ms2hf-0.1.0/ms2hf.egg-info/dependency_links.txt +1 -0
- ms2hf-0.1.0/ms2hf.egg-info/entry_points.txt +3 -0
- ms2hf-0.1.0/ms2hf.egg-info/requires.txt +3 -0
- ms2hf-0.1.0/ms2hf.egg-info/top_level.txt +1 -0
- ms2hf-0.1.0/ms2hf.py +754 -0
- ms2hf-0.1.0/pyproject.toml +44 -0
- ms2hf-0.1.0/setup.cfg +4 -0
ms2hf-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
ms2hf-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ms2hf
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sync models and datasets between ModelScope and Hugging Face one file at a time.
|
|
5
|
+
Author: pkufool
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/pkufool/ms2hf
|
|
8
|
+
Project-URL: Issues, https://github.com/pkufool/ms2hf/issues
|
|
9
|
+
Keywords: modelscope,huggingface,sync,models,datasets
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: huggingface_hub>=0.20.0
|
|
27
|
+
Requires-Dist: modelscope>=1.9.0
|
|
28
|
+
Requires-Dist: tqdm>=4.64.0
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# ms2hf
|
|
32
|
+
|
|
33
|
+
`ms2hf` 是一个用于在 [ModelScope 魔搭](https://modelscope.cn/) 和 [Hugging Face](https://huggingface.co/) 之间同步模型 / 数据集仓库的命令行工具。
|
|
34
|
+
|
|
35
|
+
它主要面向中文用户,尤其适合在 Google Colab、Gitpod、云服务器临时环境等「能访问 Hugging Face 和 ModelScope,但本地磁盘空间有限」的场景中使用。
|
|
36
|
+
|
|
37
|
+
和一次性 clone / 下载整个仓库不同,`ms2hf` 会按文件逐个执行:
|
|
38
|
+
|
|
39
|
+
1. 从源平台下载一个文件;
|
|
40
|
+
2. 上传到目标平台;
|
|
41
|
+
3. 上传成功后删除本地临时文件;
|
|
42
|
+
4. 继续处理下一个文件。
|
|
43
|
+
|
|
44
|
+
这样可以显著降低同步大模型或大数据集时对本地存储空间的要求。
|
|
45
|
+
|
|
46
|
+
## 功能特性
|
|
47
|
+
|
|
48
|
+
- 提供两个命令:
|
|
49
|
+
- `ms2hf`:从 ModelScope 同步到 Hugging Face;
|
|
50
|
+
- `hf2ms`:从 Hugging Face 同步到 ModelScope。
|
|
51
|
+
- 同时支持模型仓库和数据集仓库。
|
|
52
|
+
- 支持从环境变量读取 token:
|
|
53
|
+
- `HF_TOKEN`
|
|
54
|
+
- `MS_TOKEN`
|
|
55
|
+
- 也支持通过命令行参数传入 token。
|
|
56
|
+
- 默认逐个文件同步,适合低磁盘空间环境。
|
|
57
|
+
- 默认会检查目标仓库是否已有同路径文件,已存在则跳过。
|
|
58
|
+
- 支持 `--force` 强制重新上传已有文件。
|
|
59
|
+
- 支持 `--include-regex` 只同步匹配的文件。
|
|
60
|
+
- 支持 `--exclude-regex` 排除指定文件或文件夹。
|
|
61
|
+
- 支持 `--workers` 并发同步,提高传输效率。
|
|
62
|
+
- 支持 `--dry-run` 预览将要同步的文件,不实际下载 / 上传。
|
|
63
|
+
- 支持 `--create-target` 自动创建目标仓库。
|
|
64
|
+
- 同步过程中显示进度条。
|
|
65
|
+
- 同步完成后输出成功、跳过、失败数量。
|
|
66
|
+
|
|
67
|
+
## 安装
|
|
68
|
+
|
|
69
|
+
### 从 PyPI 安装
|
|
70
|
+
|
|
71
|
+
项目发布到 PyPI 后,可以直接安装:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install ms2hf
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
安装完成后会得到两个命令:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
ms2hf --help
|
|
81
|
+
hf2ms --help
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 从本地源码安装
|
|
85
|
+
|
|
86
|
+
在项目根目录执行:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pip install .
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Token 配置
|
|
93
|
+
|
|
94
|
+
### 方式一:通过环境变量配置,推荐
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
export HF_TOKEN="hf_xxx"
|
|
98
|
+
export MS_TOKEN="xxx"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
然后直接运行同步命令:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
ms2hf k2-fsa/OpenDialog your-hf-name/OpenDialog --repo-type dataset
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 方式二:通过命令行参数传入
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
ms2hf k2-fsa/OpenDialog your-hf-name/OpenDialog \
|
|
111
|
+
--repo-type dataset \
|
|
112
|
+
--hf-token "hf_xxx" \
|
|
113
|
+
--ms-token "xxx"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
> 注意:命令行参数可能会出现在 shell history 或进程列表中。如果在共享环境中使用,建议优先使用环境变量。
|
|
117
|
+
|
|
118
|
+
## 基本用法
|
|
119
|
+
|
|
120
|
+
命令格式:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
ms2hf SOURCE_REPO TARGET_REPO [OPTIONS]
|
|
124
|
+
hf2ms SOURCE_REPO TARGET_REPO [OPTIONS]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
其中:
|
|
128
|
+
|
|
129
|
+
- `SOURCE_REPO` 是源仓库 ID,例如 `k2-fsa/OpenDialog`;
|
|
130
|
+
- `TARGET_REPO` 是目标仓库 ID,例如 `your-name/OpenDialog`;
|
|
131
|
+
- 仓库类型通过 `--repo-type` 指定,可选值为:
|
|
132
|
+
- `model`
|
|
133
|
+
- `dataset`
|
|
134
|
+
|
|
135
|
+
## 使用示例
|
|
136
|
+
|
|
137
|
+
### 1. 从 ModelScope 同步数据集到 Hugging Face
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
ms2hf k2-fsa/OpenDialog your-hf-name/OpenDialog \
|
|
141
|
+
--repo-type dataset \
|
|
142
|
+
--source-revision master \
|
|
143
|
+
--create-target \
|
|
144
|
+
--work-dir /content/dataset_sync
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
说明:
|
|
148
|
+
|
|
149
|
+
- 从 ModelScope 的 `k2-fsa/OpenDialog` 数据集读取文件;
|
|
150
|
+
- 同步到 Hugging Face 的 `your-hf-name/OpenDialog` 数据集;
|
|
151
|
+
- 如果目标仓库不存在,使用 `--create-target` 创建;
|
|
152
|
+
- 临时文件存放在 `/content/dataset_sync`;
|
|
153
|
+
- 上传成功后默认删除本地临时文件。
|
|
154
|
+
|
|
155
|
+
### 2. 从 Hugging Face 同步模型到 ModelScope
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
hf2ms bert-base-uncased your-ms-name/bert-base-uncased \
|
|
159
|
+
--repo-type model \
|
|
160
|
+
--create-target
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 3. 只同步指定类型的文件
|
|
164
|
+
|
|
165
|
+
例如只同步 `data/` 目录下的 parquet 文件:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
ms2hf org/big-dataset your-name/big-dataset \
|
|
169
|
+
--repo-type dataset \
|
|
170
|
+
--include-regex '^data/.*\.parquet$'
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### 4. 排除指定目录
|
|
174
|
+
|
|
175
|
+
例如排除所有 `tmp` 目录:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
ms2hf org/big-dataset your-name/big-dataset \
|
|
179
|
+
--repo-type dataset \
|
|
180
|
+
--exclude-regex '(^|/)tmp/'
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 5. 同时使用 include 和 exclude
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
ms2hf org/big-dataset your-name/big-dataset \
|
|
187
|
+
--repo-type dataset \
|
|
188
|
+
--include-regex '^data/' \
|
|
189
|
+
--exclude-regex '(^|/)cache/' \
|
|
190
|
+
--exclude-regex '\.tmp$'
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
规则:
|
|
194
|
+
|
|
195
|
+
- 如果指定了 `--include-regex`,只有匹配 include 的文件会被考虑;
|
|
196
|
+
- 如果文件同时匹配 `--exclude-regex`,会被排除;
|
|
197
|
+
- 两个参数都可以重复使用。
|
|
198
|
+
|
|
199
|
+
### 6. 强制覆盖 / 重新上传
|
|
200
|
+
|
|
201
|
+
默认情况下,如果目标仓库已经存在同路径文件,工具会跳过该文件。
|
|
202
|
+
|
|
203
|
+
如果你希望重新上传,可以使用:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
ms2hf org/model your-name/model \
|
|
207
|
+
--repo-type model \
|
|
208
|
+
--force
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### 7. 预览同步计划,不实际执行
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
ms2hf org/dataset your-name/dataset \
|
|
215
|
+
--repo-type dataset \
|
|
216
|
+
--dry-run
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
这会列出将要同步、跳过的文件统计,但不会下载或上传任何文件。
|
|
220
|
+
|
|
221
|
+
### 8. 提高并发数
|
|
222
|
+
|
|
223
|
+
默认 `--workers 1`,也就是一次只处理一个文件,这样最省磁盘空间。
|
|
224
|
+
|
|
225
|
+
如果环境磁盘空间足够,可以提高并发数:
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
ms2hf org/dataset your-name/dataset \
|
|
229
|
+
--repo-type dataset \
|
|
230
|
+
--workers 4
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
> 注意:`--workers` 越大,同时保存在本地的临时文件越多,磁盘占用也可能越高。
|
|
234
|
+
|
|
235
|
+
### 9. 保留本地下载文件
|
|
236
|
+
|
|
237
|
+
默认上传成功后会删除本地临时文件。如果你希望保留下载的文件用于调试,可以使用:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
ms2hf org/dataset your-name/dataset \
|
|
241
|
+
--repo-type dataset \
|
|
242
|
+
--keep-local
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## 常用参数说明
|
|
246
|
+
|
|
247
|
+
| 参数 | 说明 |
|
|
248
|
+
| --- | --- |
|
|
249
|
+
| `source_repo` | 源仓库 ID,例如 `k2-fsa/OpenDialog` |
|
|
250
|
+
| `target_repo` | 目标仓库 ID,例如 `your-name/OpenDialog` |
|
|
251
|
+
| `--repo-type` / `--type` | 仓库类型,`model` 或 `dataset`,默认 `model` |
|
|
252
|
+
| `--source-revision` | 源仓库 revision,可以是分支、tag 或 commit |
|
|
253
|
+
| `--target-revision` | 目标仓库 revision;是否生效取决于目标平台 SDK 支持情况 |
|
|
254
|
+
| `--work-dir` | 本地工作目录,默认当前目录 |
|
|
255
|
+
| `--include-regex` | 只同步匹配该正则的文件,可重复指定 |
|
|
256
|
+
| `--exclude-regex` | 排除匹配该正则的文件,可重复指定 |
|
|
257
|
+
| `--force` | 即使目标已有同路径文件,也重新上传 |
|
|
258
|
+
| `--workers` | 并发同步文件数,默认 `1` |
|
|
259
|
+
| `--max-retries` | 每个下载 / 上传步骤的最大重试次数,默认 `3` |
|
|
260
|
+
| `--retry-sleep` | 重试间隔秒数,默认 `10` |
|
|
261
|
+
| `--hf-token` | Hugging Face token;默认读取 `HF_TOKEN` 环境变量 |
|
|
262
|
+
| `--ms-token` | ModelScope token;默认读取 `MS_TOKEN` 环境变量 |
|
|
263
|
+
| `--create-target` | 如果目标仓库不存在,尝试自动创建 |
|
|
264
|
+
| `--private` | 和 `--create-target` 一起使用,创建私有仓库 |
|
|
265
|
+
| `--dry-run` | 只预览,不实际同步 |
|
|
266
|
+
| `--keep-local` | 上传后保留本地临时文件 |
|
|
267
|
+
| `--commit-message-template` | 自定义每个文件上传时的 commit message 模板 |
|
|
268
|
+
|
|
269
|
+
## 在 Google Colab 中使用
|
|
270
|
+
|
|
271
|
+
示例:
|
|
272
|
+
|
|
273
|
+
```python
|
|
274
|
+
!pip install ms2hf
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
import os
|
|
279
|
+
os.environ["HF_TOKEN"] = "hf_xxx"
|
|
280
|
+
os.environ["MS_TOKEN"] = "xxx"
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
```python
|
|
284
|
+
!ms2hf k2-fsa/OpenDialog your-hf-name/OpenDialog \
|
|
285
|
+
--repo-type dataset \
|
|
286
|
+
--create-target \
|
|
287
|
+
--work-dir /content/dataset_sync
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## 在 Gitpod / 云服务器中使用
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
pip install ms2hf
|
|
294
|
+
|
|
295
|
+
export HF_TOKEN="hf_xxx"
|
|
296
|
+
export MS_TOKEN="xxx"
|
|
297
|
+
|
|
298
|
+
ms2hf k2-fsa/OpenDialog your-hf-name/OpenDialog \
|
|
299
|
+
--repo-type dataset \
|
|
300
|
+
--create-target \
|
|
301
|
+
--work-dir ./dataset_sync
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## 同步策略说明
|
|
305
|
+
|
|
306
|
+
### 为什么逐个文件同步?
|
|
307
|
+
|
|
308
|
+
很多模型和数据集非常大,如果一次性下载整个仓库,很容易耗尽 Colab、Gitpod 或临时云服务器的磁盘空间。
|
|
309
|
+
|
|
310
|
+
`ms2hf` 的策略是:
|
|
311
|
+
|
|
312
|
+
```text
|
|
313
|
+
下载单个文件 -> 上传单个文件 -> 删除本地文件 -> 处理下一个文件
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
这样本地磁盘通常只需要容纳一个文件,或在开启多线程时容纳少量文件。
|
|
317
|
+
|
|
318
|
+
### 如何判断文件是否已经同步?
|
|
319
|
+
|
|
320
|
+
目前工具默认按“目标仓库是否存在同路径文件”判断:
|
|
321
|
+
|
|
322
|
+
- 如果目标仓库已有同路径文件:跳过;
|
|
323
|
+
- 如果目标仓库没有该路径:下载并上传;
|
|
324
|
+
- 如果指定 `--force`:不检查跳过,直接重新上传。
|
|
325
|
+
|
|
326
|
+
这个策略比较保守,能避免重复传输,但不会跨平台比较 hash。如果你怀疑目标文件内容不是最新的,请使用 `--force`。
|
|
327
|
+
|
|
328
|
+
## 当前限制
|
|
329
|
+
|
|
330
|
+
- 目前“是否已存在”主要按文件路径判断,不做跨平台 hash 对比。
|
|
331
|
+
- 每个文件会单独上传并产生一次提交,适合低存储环境,但同步大量小文件时可能较慢。
|
|
332
|
+
- ModelScope 当前 SDK 的 `upload_file` 通常提交到默认分支,因此 `--target-revision` 在目标为 ModelScope 时可能不会生效。
|
|
333
|
+
- 不同平台对模型 / 数据集仓库的可见性、权限、分支、LFS 策略支持不完全一致,具体行为以平台 API 为准。
|
|
334
|
+
|
|
335
|
+
## 开发者说明
|
|
336
|
+
|
|
337
|
+
本项目的入口定义在 `pyproject.toml`:
|
|
338
|
+
|
|
339
|
+
```toml
|
|
340
|
+
[project.scripts]
|
|
341
|
+
ms2hf = "ms2hf:main_ms2hf"
|
|
342
|
+
hf2ms = "ms2hf:main_hf2ms"
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
本地检查:
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
python -m py_compile ms2hf.py
|
|
349
|
+
python ms2hf.py --help
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
本地安装测试:
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
pip install -e .
|
|
356
|
+
ms2hf --help
|
|
357
|
+
hf2ms --help
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## 许可证
|
|
361
|
+
|
|
362
|
+
Apache-2.0
|
|
363
|
+
|
|
364
|
+
## GitHub Actions
|
|
365
|
+
|
|
366
|
+
本项目内置了两个 GitHub Actions workflow,分别用于发布 PyPI 和在线触发同步任务。
|
|
367
|
+
|
|
368
|
+
### 1. 发布到 PyPI
|
|
369
|
+
|
|
370
|
+
Workflow 文件:
|
|
371
|
+
|
|
372
|
+
```text
|
|
373
|
+
.github/workflows/publish-pypi.yml
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
触发方式:
|
|
377
|
+
|
|
378
|
+
1. 推送版本 tag 到 GitHub,例如:
|
|
379
|
+
|
|
380
|
+
```bash
|
|
381
|
+
git tag v0.1.0
|
|
382
|
+
git push origin v0.1.0
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
2. 或者在 GitHub 网页端手动运行:
|
|
386
|
+
|
|
387
|
+
```text
|
|
388
|
+
Actions -> Publish to PyPI -> Run workflow
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
该 workflow 会自动:
|
|
392
|
+
|
|
393
|
+
- 检出代码;
|
|
394
|
+
- 安装构建工具;
|
|
395
|
+
- 执行 `python -m build`;
|
|
396
|
+
- 执行 `twine check`;
|
|
397
|
+
- 使用 `twine upload` 发布到 PyPI。
|
|
398
|
+
|
|
399
|
+
发布使用 PyPI API Token,不使用 Trusted Publisher。请先在 GitHub 仓库 Secrets 中配置:
|
|
400
|
+
|
|
401
|
+
```text
|
|
402
|
+
Settings -> Secrets and variables -> Actions -> New repository secret
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
Secret 名称必须是:
|
|
406
|
+
|
|
407
|
+
```text
|
|
408
|
+
PYPI_TOKEN
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
Secret 值填写 PyPI 上创建的 API Token,通常以 `pypi-` 开头。
|
|
412
|
+
|
|
413
|
+
### 2. 在 GitHub 网页端手动同步模型 / 数据集
|
|
414
|
+
|
|
415
|
+
Workflow 文件:
|
|
416
|
+
|
|
417
|
+
```text
|
|
418
|
+
.github/workflows/sync.yml
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
使用方式:
|
|
422
|
+
|
|
423
|
+
```text
|
|
424
|
+
GitHub 仓库页面 -> Actions -> 同步 ModelScope / Hugging Face -> Run workflow
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
网页端会要求输入:
|
|
428
|
+
|
|
429
|
+
- 同步方向:`ms2hf` 或 `hf2ms`;
|
|
430
|
+
- 仓库类型:`model` 或 `dataset`;
|
|
431
|
+
- 源仓库 ID;
|
|
432
|
+
- 目标仓库 ID;
|
|
433
|
+
- source revision;
|
|
434
|
+
- target revision;
|
|
435
|
+
- include 正则;
|
|
436
|
+
- exclude 正则;
|
|
437
|
+
- workers;
|
|
438
|
+
- 是否 force;
|
|
439
|
+
- 是否 create target;
|
|
440
|
+
- 是否 dry run;
|
|
441
|
+
- Hugging Face token;
|
|
442
|
+
- ModelScope token。
|
|
443
|
+
|
|
444
|
+
推荐先在仓库 Secrets 中配置 token:
|
|
445
|
+
|
|
446
|
+
```text
|
|
447
|
+
Settings -> Secrets and variables -> Actions -> New repository secret
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
建议添加:
|
|
451
|
+
|
|
452
|
+
```text
|
|
453
|
+
HF_TOKEN
|
|
454
|
+
MS_TOKEN
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
配置后,每次在网页端运行同步任务时就不需要手动输入 token。
|
|
458
|
+
|
|
459
|
+
如果没有配置 Secrets,也可以在 Run workflow 页面临时输入 `hf_token` 和 `ms_token`。workflow 会对 token 做日志 mask,但 GitHub Actions 输入本身不等同于 Secret;在多人协作仓库中,仍然更推荐使用 Secrets。
|
|
460
|
+
|
|
461
|
+
#### 网页端同步示例
|
|
462
|
+
|
|
463
|
+
从 ModelScope 同步数据集到 Hugging Face:
|
|
464
|
+
|
|
465
|
+
```text
|
|
466
|
+
direction: ms2hf
|
|
467
|
+
repo_type: dataset
|
|
468
|
+
source_repo: k2-fsa/OpenDialog
|
|
469
|
+
target_repo: your-hf-name/OpenDialog
|
|
470
|
+
source_revision: master
|
|
471
|
+
workers: 1
|
|
472
|
+
create_target: true
|
|
473
|
+
force: false
|
|
474
|
+
dry_run: false
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
从 Hugging Face 同步模型到 ModelScope:
|
|
478
|
+
|
|
479
|
+
```text
|
|
480
|
+
direction: hf2ms
|
|
481
|
+
repo_type: model
|
|
482
|
+
source_repo: bert-base-uncased
|
|
483
|
+
target_repo: your-ms-name/bert-base-uncased
|
|
484
|
+
workers: 1
|
|
485
|
+
create_target: true
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
#### 建议先 dry run
|
|
489
|
+
|
|
490
|
+
第一次同步前,建议先勾选:
|
|
491
|
+
|
|
492
|
+
```text
|
|
493
|
+
dry_run: true
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
确认源文件数量、过滤规则和跳过逻辑符合预期后,再正式执行同步。
|