|
8 | 8 |
|
9 | 9 | # Step 1: Load environment variables from a .env file (e.g., API tokens) |
10 | 10 | import dotenv |
11 | | - |
12 | 11 | dotenv.load_dotenv('.env') |
13 | 12 |
|
14 | | -import os |
15 | | - |
16 | 13 | # Step 2: Initialize Tinker client before importing ServiceClient |
17 | | -from twinkle_client import init_tinker_client |
| 14 | +from twinkle import init_tinker_client |
18 | 15 |
|
19 | 16 | init_tinker_client() |
20 | 17 |
|
21 | 18 | # Step 3: Use ServiceClient directly from tinker |
22 | 19 | from tinker import ServiceClient |
23 | 20 |
|
24 | 21 | service_client = ServiceClient( |
25 | | - base_url='http://www.modelscope.cn/twinkle', |
26 | | - api_key=os.environ.get('MODELSCOPE_TOKEN') |
| 22 | + # BASE_URL can be a local server endpoint such as http://localhost:8000, or |
| 23 | + # points to a previously deployed remote server, or |
| 24 | + # modelscope server such as 'http://www.modelscope.cn/twinkle' |
| 25 | + base_url='<BASE_URL>', |
| 26 | + # API_KEY can be empty or a meaninful one according to sever configuration |
| 27 | + api_key='<API_KEY>' |
27 | 28 | ) |
28 | 29 |
|
29 | 30 | # Step 4: List models available on the server to verify the connection |
|
40 | 41 |
|
41 | 42 | # You can resume from either: |
42 | 43 | # 1. A twinkle path: "twinkle://.../<run_id>/weights/<checkpoint_name>" |
43 | | -# 2. A model id on hub: "<user>/<model_id>" |
| 44 | +# 2. A model id on ModelScope hub: "ms://<user>/<model_id>" |
| 45 | +# 3. A local path to a checkpoint directory |
44 | 46 | # Example: |
45 | 47 | # resume_path = "twinkle://20260131_170251-Qwen_Qwen2_5-0_5B-Instruct-7275126c/weights/pig-latin-lora-epoch-1" |
46 | | -# resume_path = "AlexEz/20260205_163645-Qwen_Qwen2_5-7B-Instruct-385d5c17_pig-latin-lora-epoch-1" |
| 48 | +# resume_path = "ms://AlexEz/20260205_163645-Qwen_Qwen2_5-7B-Instruct-385d5c17_pig-latin-lora-epoch-1" |
| 49 | +# resume_path = "/path/to/local/checkpoint/directory" |
47 | 50 | resume_path = '' |
48 | 51 |
|
49 | 52 | print(f'Found {len(response.training_runs)} training runs') |
|
85 | 88 | { |
86 | 89 | 'input': 'pickle jar', |
87 | 90 | 'output': 'ickle-pay ar-jay' |
88 | | - }, |
89 | | - { |
90 | | - 'input': 'space exploration', |
91 | | - 'output': 'ace-spay exploration-way' |
92 | | - }, |
93 | | - { |
94 | | - 'input': 'rubber duck', |
95 | | - 'output': 'ubber-ray uck-day' |
96 | | - }, |
97 | | - { |
98 | | - 'input': 'coding wizard', |
99 | | - 'output': 'oding-cay izard-way' |
100 | | - }, |
| 91 | + } |
101 | 92 | ] |
102 | 93 |
|
103 | 94 | from modelscope import AutoTokenizer |
@@ -181,6 +172,7 @@ def process_example(example: dict, tokenizer) -> types.Datum: |
181 | 172 |
|
182 | 173 | # Step 9: Publish the final checkpoint to ModelScope Hub. |
183 | 174 | # NOTE: Requires a valid ModelScope token set as api_key when initializing the client. |
184 | | -# The published model name will be: {run_id}_{checkpoint_name} |
| 175 | +# The model will be published under the owner of the supplied ModelScope token, |
| 176 | +# with model name formatted as: {run_id}_{checkpoint_name} |
185 | 177 | rest_client.publish_checkpoint_from_tinker_path(save_result.path).result() |
186 | 178 | print('Published checkpoint') |
0 commit comments