gmicloud 0.1.6__tar.gz → 0.1.7__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.
- {gmicloud-0.1.6 → gmicloud-0.1.7}/PKG-INFO +97 -7
- {gmicloud-0.1.6 → gmicloud-0.1.7}/README.md +94 -4
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/__init__.py +2 -2
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_client/_artifact_client.py +40 -7
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_client/_file_upload_client.py +10 -7
- gmicloud-0.1.7/gmicloud/_internal/_config.py +9 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_manager/_artifact_manager.py +116 -18
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_manager/_task_manager.py +32 -27
- gmicloud-0.1.7/gmicloud/_internal/_manager/serve_command_utils.py +121 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_models.py +135 -31
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/tests/test_artifacts.py +6 -22
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud.egg-info/PKG-INFO +97 -7
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud.egg-info/SOURCES.txt +1 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud.egg-info/top_level.txt +1 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/pyproject.toml +7 -2
- gmicloud-0.1.6/gmicloud/_internal/_config.py +0 -3
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/__init__.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_client/__init__.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_client/_decorator.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_client/_http_client.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_client/_iam_client.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_client/_task_client.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_constants.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_enums.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_exceptions.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_manager/__init__.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/_internal/_manager/_iam_manager.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/client.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/tests/__init__.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/tests/test_tasks.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud/utils/uninstall_packages.py +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/gmicloud.egg-info/dependency_links.txt +0 -0
- {gmicloud-0.1.6 → gmicloud-0.1.7}/setup.cfg +0 -0
@@ -1,8 +1,8 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: gmicloud
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.7
|
4
4
|
Summary: GMI Cloud Python SDK
|
5
|
-
Author-email: GMI <
|
5
|
+
Author-email: GMI <gmi@gmitec.net>
|
6
6
|
License: MIT
|
7
7
|
Classifier: Programming Language :: Python :: 3
|
8
8
|
Classifier: License :: OSI Approved :: MIT License
|
@@ -10,7 +10,7 @@ Classifier: Operating System :: OS Independent
|
|
10
10
|
Requires-Python: >=3.6
|
11
11
|
Description-Content-Type: text/markdown
|
12
12
|
|
13
|
-
# GMICloud SDK
|
13
|
+
# GMICloud SDK
|
14
14
|
|
15
15
|
## Overview
|
16
16
|
Before you start: Our service and GPU resource is currenly invite-only so please contact our team (getstarted@gmicloud.ai) to get invited if you don't have one yet.
|
@@ -45,7 +45,7 @@ There are two ways to configure the SDK:
|
|
45
45
|
Set the following environment variables:
|
46
46
|
|
47
47
|
```shell
|
48
|
-
export GMI_CLOUD_CLIENT_ID=<YOUR_CLIENT_ID>
|
48
|
+
export GMI_CLOUD_CLIENT_ID=<YOUR_CLIENT_ID> # Pick what every ID you need.
|
49
49
|
export GMI_CLOUD_EMAIL=<YOUR_EMAIL>
|
50
50
|
export GMI_CLOUD_PASSWORD=<YOUR_PASSWORD>
|
51
51
|
```
|
@@ -73,7 +73,7 @@ pip install -r requirements.txt
|
|
73
73
|
python -m examples.create_task_from_artifact_template.py
|
74
74
|
```
|
75
75
|
|
76
|
-
### 2.
|
76
|
+
### 2. Example of create an inference task from an artifact template
|
77
77
|
|
78
78
|
This is the simplest example to deploy an inference task using an existing artifact template:
|
79
79
|
|
@@ -119,6 +119,97 @@ print(call_chat_completion(cli, task.task_id))
|
|
119
119
|
|
120
120
|
```
|
121
121
|
|
122
|
+
### 3. Example of creating an inference task based on custom model with local vllm / SGLang serve command
|
123
|
+
* Full example is available at [examples/inference_task_with_custom_model.py](https://github.com/GMISWE/python-sdk/blob/main/examples/inference_task_with_custom_model.py)
|
124
|
+
|
125
|
+
1. Prepare custom model checkpoint (using a model downloaded from HF as an example)
|
126
|
+
|
127
|
+
```python
|
128
|
+
# Download model from huggingface
|
129
|
+
from huggingface_hub import snapshot_download
|
130
|
+
|
131
|
+
model_name = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
|
132
|
+
model_checkpoint_save_dir = "files/model_garden"
|
133
|
+
snapshot_download(repo_id=model_name, local_dir=model_checkpoint_save_dir)
|
134
|
+
```
|
135
|
+
|
136
|
+
2. Find a template of specific SGLang version
|
137
|
+
|
138
|
+
```python
|
139
|
+
# export GMI_CLOUD_CLIENT_ID=<YOUR_CLIENT_ID>
|
140
|
+
# export GMI_CLOUD_EMAIL=<YOUR_EMAIL>
|
141
|
+
# export GMI_CLOUD_PASSWORD=<YOUR_PASSWORD>
|
142
|
+
cli = Client()
|
143
|
+
|
144
|
+
# List templates offered by GMI cloud
|
145
|
+
templates = cli.artifact_manager.list_public_template_names()
|
146
|
+
print(f"Found {len(templates)} templates: {templates}")
|
147
|
+
```
|
148
|
+
|
149
|
+
3. Pick a template (e.g. SGLang 0.4.5) and prepare a local serve command
|
150
|
+
|
151
|
+
```python
|
152
|
+
# Example for vllm server
|
153
|
+
picked_template_name = "gmi_vllm_0.8.4"
|
154
|
+
serve_command = "vllm serve deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --trust-remote-code --gpu-memory-utilization 0.8"
|
155
|
+
|
156
|
+
# Example for sglang server
|
157
|
+
picked_template_name = "gmi_sglang_0.4.5.post1"
|
158
|
+
serve_command = "python3 -m sglang.launch_server --model-path deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --trust-remote-code --mem-fraction-static 0.8 --tp 2"
|
159
|
+
```
|
160
|
+
|
161
|
+
4. Create an artifact and upload custom model. The artifact can be reused to create inference tasks later. Artifact also suggests recommended resources for each inference server replica
|
162
|
+
|
163
|
+
```python
|
164
|
+
artifact_id, recommended_replica_resources = cli.artifact_manager.create_artifact_from_template_name(
|
165
|
+
artifact_template_name=picked_template_name,
|
166
|
+
env_parameters={
|
167
|
+
"SERVER_COMMAND": serve_command,
|
168
|
+
"GPU_TYPE": "H100",
|
169
|
+
}
|
170
|
+
)
|
171
|
+
print(f"Created artifact {artifact_id} with recommended resources: {recommended_replica_resources}")
|
172
|
+
|
173
|
+
# Upload model files to artifact
|
174
|
+
cli.artifact_manager.upload_model_files_to_artifact(artifact_id, model_checkpoint_save_dir)
|
175
|
+
```
|
176
|
+
|
177
|
+
5. Create Inference task (defining min/max inference replica), start and wait
|
178
|
+
|
179
|
+
```python
|
180
|
+
new_task = Task(
|
181
|
+
config=TaskConfig(
|
182
|
+
ray_task_config=RayTaskConfig(
|
183
|
+
artifact_id=artifact_id,
|
184
|
+
file_path="serve",
|
185
|
+
deployment_name="app",
|
186
|
+
replica_resource=recommended_replica_resources,
|
187
|
+
),
|
188
|
+
task_scheduling = TaskScheduling(
|
189
|
+
scheduling_oneoff=OneOffScheduling(
|
190
|
+
trigger_timestamp=int(datetime.now().timestamp()),
|
191
|
+
min_replicas=1,
|
192
|
+
max_replicas=4,
|
193
|
+
)
|
194
|
+
),
|
195
|
+
),
|
196
|
+
)
|
197
|
+
task = cli.task_manager.create_task(new_task)
|
198
|
+
task_id = task.task_id
|
199
|
+
task = cli.task_manager.get_task(task_id)
|
200
|
+
print(f"Task created: {task.config.task_name}. You can check details at https://inference-engine.gmicloud.ai/user-console/task")
|
201
|
+
|
202
|
+
# Start Task and wait for it to be ready
|
203
|
+
cli.task_manager.start_task_and_wait(task_id)
|
204
|
+
```
|
205
|
+
|
206
|
+
6. Test with sample chat completion request
|
207
|
+
|
208
|
+
```python
|
209
|
+
print(call_chat_completion(cli, task_id))
|
210
|
+
```
|
211
|
+
|
212
|
+
|
122
213
|
## API Reference
|
123
214
|
|
124
215
|
### Client
|
@@ -144,4 +235,3 @@ password: Optional[str] = ""
|
|
144
235
|
* get_task(task_id: str): Retrieve the status and details of a specific task.
|
145
236
|
|
146
237
|
## Notes & Troubleshooting
|
147
|
-
k
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# GMICloud SDK
|
1
|
+
# GMICloud SDK
|
2
2
|
|
3
3
|
## Overview
|
4
4
|
Before you start: Our service and GPU resource is currenly invite-only so please contact our team (getstarted@gmicloud.ai) to get invited if you don't have one yet.
|
@@ -33,7 +33,7 @@ There are two ways to configure the SDK:
|
|
33
33
|
Set the following environment variables:
|
34
34
|
|
35
35
|
```shell
|
36
|
-
export GMI_CLOUD_CLIENT_ID=<YOUR_CLIENT_ID>
|
36
|
+
export GMI_CLOUD_CLIENT_ID=<YOUR_CLIENT_ID> # Pick what every ID you need.
|
37
37
|
export GMI_CLOUD_EMAIL=<YOUR_EMAIL>
|
38
38
|
export GMI_CLOUD_PASSWORD=<YOUR_PASSWORD>
|
39
39
|
```
|
@@ -61,7 +61,7 @@ pip install -r requirements.txt
|
|
61
61
|
python -m examples.create_task_from_artifact_template.py
|
62
62
|
```
|
63
63
|
|
64
|
-
### 2.
|
64
|
+
### 2. Example of create an inference task from an artifact template
|
65
65
|
|
66
66
|
This is the simplest example to deploy an inference task using an existing artifact template:
|
67
67
|
|
@@ -107,6 +107,97 @@ print(call_chat_completion(cli, task.task_id))
|
|
107
107
|
|
108
108
|
```
|
109
109
|
|
110
|
+
### 3. Example of creating an inference task based on custom model with local vllm / SGLang serve command
|
111
|
+
* Full example is available at [examples/inference_task_with_custom_model.py](https://github.com/GMISWE/python-sdk/blob/main/examples/inference_task_with_custom_model.py)
|
112
|
+
|
113
|
+
1. Prepare custom model checkpoint (using a model downloaded from HF as an example)
|
114
|
+
|
115
|
+
```python
|
116
|
+
# Download model from huggingface
|
117
|
+
from huggingface_hub import snapshot_download
|
118
|
+
|
119
|
+
model_name = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
|
120
|
+
model_checkpoint_save_dir = "files/model_garden"
|
121
|
+
snapshot_download(repo_id=model_name, local_dir=model_checkpoint_save_dir)
|
122
|
+
```
|
123
|
+
|
124
|
+
2. Find a template of specific SGLang version
|
125
|
+
|
126
|
+
```python
|
127
|
+
# export GMI_CLOUD_CLIENT_ID=<YOUR_CLIENT_ID>
|
128
|
+
# export GMI_CLOUD_EMAIL=<YOUR_EMAIL>
|
129
|
+
# export GMI_CLOUD_PASSWORD=<YOUR_PASSWORD>
|
130
|
+
cli = Client()
|
131
|
+
|
132
|
+
# List templates offered by GMI cloud
|
133
|
+
templates = cli.artifact_manager.list_public_template_names()
|
134
|
+
print(f"Found {len(templates)} templates: {templates}")
|
135
|
+
```
|
136
|
+
|
137
|
+
3. Pick a template (e.g. SGLang 0.4.5) and prepare a local serve command
|
138
|
+
|
139
|
+
```python
|
140
|
+
# Example for vllm server
|
141
|
+
picked_template_name = "gmi_vllm_0.8.4"
|
142
|
+
serve_command = "vllm serve deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --trust-remote-code --gpu-memory-utilization 0.8"
|
143
|
+
|
144
|
+
# Example for sglang server
|
145
|
+
picked_template_name = "gmi_sglang_0.4.5.post1"
|
146
|
+
serve_command = "python3 -m sglang.launch_server --model-path deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --trust-remote-code --mem-fraction-static 0.8 --tp 2"
|
147
|
+
```
|
148
|
+
|
149
|
+
4. Create an artifact and upload custom model. The artifact can be reused to create inference tasks later. Artifact also suggests recommended resources for each inference server replica
|
150
|
+
|
151
|
+
```python
|
152
|
+
artifact_id, recommended_replica_resources = cli.artifact_manager.create_artifact_from_template_name(
|
153
|
+
artifact_template_name=picked_template_name,
|
154
|
+
env_parameters={
|
155
|
+
"SERVER_COMMAND": serve_command,
|
156
|
+
"GPU_TYPE": "H100",
|
157
|
+
}
|
158
|
+
)
|
159
|
+
print(f"Created artifact {artifact_id} with recommended resources: {recommended_replica_resources}")
|
160
|
+
|
161
|
+
# Upload model files to artifact
|
162
|
+
cli.artifact_manager.upload_model_files_to_artifact(artifact_id, model_checkpoint_save_dir)
|
163
|
+
```
|
164
|
+
|
165
|
+
5. Create Inference task (defining min/max inference replica), start and wait
|
166
|
+
|
167
|
+
```python
|
168
|
+
new_task = Task(
|
169
|
+
config=TaskConfig(
|
170
|
+
ray_task_config=RayTaskConfig(
|
171
|
+
artifact_id=artifact_id,
|
172
|
+
file_path="serve",
|
173
|
+
deployment_name="app",
|
174
|
+
replica_resource=recommended_replica_resources,
|
175
|
+
),
|
176
|
+
task_scheduling = TaskScheduling(
|
177
|
+
scheduling_oneoff=OneOffScheduling(
|
178
|
+
trigger_timestamp=int(datetime.now().timestamp()),
|
179
|
+
min_replicas=1,
|
180
|
+
max_replicas=4,
|
181
|
+
)
|
182
|
+
),
|
183
|
+
),
|
184
|
+
)
|
185
|
+
task = cli.task_manager.create_task(new_task)
|
186
|
+
task_id = task.task_id
|
187
|
+
task = cli.task_manager.get_task(task_id)
|
188
|
+
print(f"Task created: {task.config.task_name}. You can check details at https://inference-engine.gmicloud.ai/user-console/task")
|
189
|
+
|
190
|
+
# Start Task and wait for it to be ready
|
191
|
+
cli.task_manager.start_task_and_wait(task_id)
|
192
|
+
```
|
193
|
+
|
194
|
+
6. Test with sample chat completion request
|
195
|
+
|
196
|
+
```python
|
197
|
+
print(call_chat_completion(cli, task_id))
|
198
|
+
```
|
199
|
+
|
200
|
+
|
110
201
|
## API Reference
|
111
202
|
|
112
203
|
### Client
|
@@ -132,4 +223,3 @@ password: Optional[str] = ""
|
|
132
223
|
* get_task(task_id: str): Retrieve the status and details of a specific task.
|
133
224
|
|
134
225
|
## Notes & Troubleshooting
|
135
|
-
k
|
@@ -15,7 +15,7 @@ from ._internal._models import (
|
|
15
15
|
OneOffScheduling,
|
16
16
|
DailyScheduling,
|
17
17
|
DailyTrigger,
|
18
|
-
|
18
|
+
Template,
|
19
19
|
)
|
20
20
|
from ._internal._enums import (
|
21
21
|
BuildStatus,
|
@@ -39,7 +39,7 @@ __all__ = [
|
|
39
39
|
"OneOffScheduling",
|
40
40
|
"DailyScheduling",
|
41
41
|
"DailyTrigger",
|
42
|
-
"
|
42
|
+
"Template",
|
43
43
|
"BuildStatus",
|
44
44
|
"TaskEndpointStatus",
|
45
45
|
]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from typing import List
|
2
2
|
import logging
|
3
3
|
from requests.exceptions import RequestException
|
4
|
-
|
4
|
+
import json
|
5
5
|
from ._http_client import HTTPClient
|
6
6
|
from ._iam_client import IAMClient
|
7
7
|
from ._decorator import handle_refresh_token
|
@@ -120,6 +120,39 @@ class ArtifactClient:
|
|
120
120
|
logger.error(f"Failed to rebuild artifact {artifact_id}: {e}")
|
121
121
|
return None
|
122
122
|
|
123
|
+
@handle_refresh_token
|
124
|
+
def add_env_parameters_to_artifact(self, artifact_id: str, env_parameters: dict[str, str]) -> None:
|
125
|
+
"""
|
126
|
+
Updates an artifact by its ID.
|
127
|
+
|
128
|
+
:param artifact_id: The ID of the artifact to update.
|
129
|
+
:param request: The request object containing the updated artifact details.
|
130
|
+
"""
|
131
|
+
try:
|
132
|
+
old_artifact = self.get_artifact(artifact_id)
|
133
|
+
if not old_artifact:
|
134
|
+
logger.error(f"Artifact {artifact_id} not found")
|
135
|
+
return
|
136
|
+
request = UpdateArtifactRequestBody(
|
137
|
+
artifact_description=old_artifact.artifact_metadata.artifact_description,
|
138
|
+
artifact_name=old_artifact.artifact_metadata.artifact_name,
|
139
|
+
artifact_tags=old_artifact.artifact_metadata.artifact_tags,
|
140
|
+
env_parameters=old_artifact.artifact_parameters.env_parameters,
|
141
|
+
model_parameters=old_artifact.artifact_parameters.model_parameters
|
142
|
+
)
|
143
|
+
new_env_parameters = [EnvParameter(key=k, value=v) for k, v in env_parameters.items()]
|
144
|
+
if not request.env_parameters:
|
145
|
+
request.env_parameters = []
|
146
|
+
request.env_parameters.extend(new_env_parameters)
|
147
|
+
response = self.client.put(
|
148
|
+
f"/update_artifact?artifact_id={artifact_id}",
|
149
|
+
self.iam_client.get_custom_headers(),
|
150
|
+
request.model_dump()
|
151
|
+
)
|
152
|
+
except (RequestException, ValueError) as e:
|
153
|
+
logger.error(f"Failed to add env parameters to artifact {artifact_id}: {e}")
|
154
|
+
return
|
155
|
+
|
123
156
|
@handle_refresh_token
|
124
157
|
def delete_artifact(self, artifact_id: str) -> Optional[DeleteArtifactResponse]:
|
125
158
|
"""
|
@@ -140,7 +173,7 @@ class ArtifactClient:
|
|
140
173
|
return None
|
141
174
|
|
142
175
|
@handle_refresh_token
|
143
|
-
def get_bigfile_upload_url(self, request:
|
176
|
+
def get_bigfile_upload_url(self, request: ResumableUploadLinkRequest) -> Optional[ResumableUploadLinkResponse]:
|
144
177
|
"""
|
145
178
|
Generates a pre-signed URL for uploading a large file.
|
146
179
|
|
@@ -156,7 +189,7 @@ class ArtifactClient:
|
|
156
189
|
logger.error("Empty response from /get_bigfile_upload_url")
|
157
190
|
return None
|
158
191
|
|
159
|
-
return
|
192
|
+
return ResumableUploadLinkResponse.model_validate(response)
|
160
193
|
|
161
194
|
except (RequestException, ValueError) as e:
|
162
195
|
logger.error(f"Failed to generate upload URL: {e}")
|
@@ -186,12 +219,12 @@ class ArtifactClient:
|
|
186
219
|
return None
|
187
220
|
|
188
221
|
@handle_refresh_token
|
189
|
-
def get_public_templates(self) -> List[
|
222
|
+
def get_public_templates(self) -> List[Template]:
|
190
223
|
"""
|
191
224
|
Fetches all artifact templates.
|
192
225
|
|
193
|
-
:return: A list of
|
194
|
-
:rtype: List[
|
226
|
+
:return: A list of Template objects.
|
227
|
+
:rtype: List[Template]
|
195
228
|
"""
|
196
229
|
try:
|
197
230
|
response = self.client.get("/get_public_templates", self.iam_client.get_custom_headers())
|
@@ -201,7 +234,7 @@ class ArtifactClient:
|
|
201
234
|
return []
|
202
235
|
|
203
236
|
try:
|
204
|
-
result =
|
237
|
+
result = GetTemplatesResponse.model_validate(response)
|
205
238
|
return result.artifact_templates
|
206
239
|
except ValueError as ve:
|
207
240
|
logger.error(f"Failed to validate response data: {ve}")
|
@@ -1,8 +1,10 @@
|
|
1
1
|
import os
|
2
2
|
import requests
|
3
|
+
import logging
|
3
4
|
|
4
5
|
from .._exceptions import UploadFileError
|
5
6
|
|
7
|
+
logger = logging.getLogger()
|
6
8
|
|
7
9
|
class FileUploadClient:
|
8
10
|
CHUNK_SIZE = 10 * 1024 * 1024 # 10MB Default Chunk Size
|
@@ -45,13 +47,13 @@ class FileUploadClient:
|
|
45
47
|
"""
|
46
48
|
try:
|
47
49
|
file_size = os.path.getsize(file_path)
|
48
|
-
|
50
|
+
logger.info(f"File {file_path} size: {file_size} bytes")
|
49
51
|
|
50
52
|
start_byte = 0
|
51
53
|
uploaded_range = FileUploadClient._check_file_status(upload_url, file_size)
|
52
54
|
if uploaded_range:
|
53
55
|
start_byte = int(uploaded_range.split("-")[1]) + 1
|
54
|
-
|
56
|
+
logger.info(f"Resuming uploading {file_path} from {start_byte} bytes")
|
55
57
|
|
56
58
|
with open(file_path, "rb") as file:
|
57
59
|
while start_byte < file_size:
|
@@ -74,14 +76,15 @@ class FileUploadClient:
|
|
74
76
|
# Ensure upload is successful for this chunk
|
75
77
|
if resp.status_code not in (200, 201, 308):
|
76
78
|
raise UploadFileError(
|
77
|
-
f"Failed to upload file, code:{resp.status_code} ,message: {resp.text}")
|
79
|
+
f"Failed to upload file {file_path}, code:{resp.status_code} ,message: {resp.text}")
|
78
80
|
|
79
81
|
start_byte = end_byte + 1
|
80
|
-
|
82
|
+
percentage = (start_byte / file_size) * 100
|
83
|
+
logger.info(f"File {file_path} uploaded {end_byte + 1:,}/{file_size:,} bytes ({percentage:.2f}%)")
|
81
84
|
|
82
|
-
|
85
|
+
logger.info(f"File {file_path} uploaded successfully.")
|
83
86
|
except Exception as e:
|
84
|
-
raise UploadFileError(f"Failed to upload file: {str(e)}")
|
87
|
+
raise UploadFileError(f"Failed to upload file {file_path}, got error: {str(e)}")
|
85
88
|
|
86
89
|
@staticmethod
|
87
90
|
def _check_file_status(upload_url: str, file_size: int) -> str:
|
@@ -104,7 +107,7 @@ class FileUploadClient:
|
|
104
107
|
if resp.status_code == 308:
|
105
108
|
range_header = resp.headers.get("Range")
|
106
109
|
if range_header:
|
107
|
-
|
110
|
+
logger.info(f"Server reports partial upload range: {range_header}")
|
108
111
|
return range_header
|
109
112
|
|
110
113
|
if resp.status_code in (200, 201):
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Dev environment
|
2
|
+
# ARTIFACT_SERVICE_BASE_URL = "https://ce-tot.gmicloud-dev.com/api/v1/ie/artifact"
|
3
|
+
# TASK_SERVICE_BASE_URL = "https://ce-tot.gmicloud-dev.com/api/v1/ie/task"
|
4
|
+
# IAM_SERVICE_BASE_URL = "https://ce-tot.gmicloud-dev.com/api/v1"
|
5
|
+
|
6
|
+
# Prod environment
|
7
|
+
ARTIFACT_SERVICE_BASE_URL = "https://inference-engine.gmicloud.ai/api/v1/ie/artifact"
|
8
|
+
TASK_SERVICE_BASE_URL = "https://inference-engine.gmicloud.ai/api/v1/ie/task"
|
9
|
+
IAM_SERVICE_BASE_URL = "https://inference-engine.gmicloud.ai/api/v1"
|
@@ -2,11 +2,16 @@ import os
|
|
2
2
|
import time
|
3
3
|
from typing import List
|
4
4
|
import mimetypes
|
5
|
+
import concurrent.futures
|
6
|
+
import re
|
7
|
+
from tqdm import tqdm
|
8
|
+
from tqdm.contrib.logging import logging_redirect_tqdm
|
5
9
|
|
6
10
|
from .._client._iam_client import IAMClient
|
7
11
|
from .._client._artifact_client import ArtifactClient
|
8
12
|
from .._client._file_upload_client import FileUploadClient
|
9
13
|
from .._models import *
|
14
|
+
from .._manager.serve_command_utils import parse_server_command, extract_gpu_num_from_serve_command
|
10
15
|
|
11
16
|
import logging
|
12
17
|
|
@@ -53,7 +58,12 @@ class ArtifactManager:
|
|
53
58
|
self,
|
54
59
|
artifact_name: str,
|
55
60
|
description: Optional[str] = "",
|
56
|
-
tags: Optional[List[str]] = None
|
61
|
+
tags: Optional[List[str]] = None,
|
62
|
+
deployment_type: Optional[str] = "",
|
63
|
+
template_id: Optional[str] = "",
|
64
|
+
env_parameters: Optional[List["EnvParameter"]] = None,
|
65
|
+
model_description: Optional[str] = "",
|
66
|
+
model_parameters: Optional[List["ModelParameter"]] = None,
|
57
67
|
) -> CreateArtifactResponse:
|
58
68
|
"""
|
59
69
|
Create a new artifact for a user.
|
@@ -69,11 +79,16 @@ class ArtifactManager:
|
|
69
79
|
|
70
80
|
req = CreateArtifactRequest(artifact_name=artifact_name,
|
71
81
|
artifact_description=description,
|
72
|
-
artifact_tags=tags,
|
82
|
+
artifact_tags=tags,
|
83
|
+
deployment_type=deployment_type,
|
84
|
+
template_id=template_id,
|
85
|
+
env_parameters=env_parameters,
|
86
|
+
model_description=model_description,
|
87
|
+
model_parameters=model_parameters)
|
73
88
|
|
74
89
|
return self.artifact_client.create_artifact(req)
|
75
90
|
|
76
|
-
def create_artifact_from_template(self, artifact_template_id: str) -> str:
|
91
|
+
def create_artifact_from_template(self, artifact_template_id: str, env_parameters: Optional[dict[str, str]] = None) -> str:
|
77
92
|
"""
|
78
93
|
Create a new artifact for a user using a template.
|
79
94
|
|
@@ -85,11 +100,16 @@ class ArtifactManager:
|
|
85
100
|
if not artifact_template_id or not artifact_template_id.strip():
|
86
101
|
raise ValueError("Artifact template ID is required and cannot be empty.")
|
87
102
|
|
103
|
+
|
88
104
|
resp = self.artifact_client.create_artifact_from_template(artifact_template_id)
|
89
105
|
if not resp or not resp.artifact_id:
|
90
106
|
raise ValueError("Failed to create artifact from template.")
|
91
107
|
|
108
|
+
if env_parameters:
|
109
|
+
self.artifact_client.add_env_parameters_to_artifact(resp.artifact_id, env_parameters)
|
110
|
+
|
92
111
|
return resp.artifact_id
|
112
|
+
|
93
113
|
|
94
114
|
def create_artifact_from_template_name(self, artifact_template_name: str) -> tuple[str, ReplicaResource]:
|
95
115
|
"""
|
@@ -125,6 +145,56 @@ class ArtifactManager:
|
|
125
145
|
except Exception as e:
|
126
146
|
logger.error(f"Failed to create artifact from template, Error: {e}")
|
127
147
|
raise e
|
148
|
+
|
149
|
+
def create_artifact_for_serve_command_and_custom_model(self, template_name: str, artifact_name: str, serve_command: str, gpu_type: str, artifact_description: str = "") -> tuple[str, ReplicaResource]:
|
150
|
+
"""
|
151
|
+
Create an artifact from a template and support custom model.
|
152
|
+
:param artifact_template_name: The name of the template to use.
|
153
|
+
:return: A tuple containing the artifact ID and the recommended replica resources.
|
154
|
+
:rtype: tuple[str, ReplicaResource]
|
155
|
+
"""
|
156
|
+
|
157
|
+
recommended_replica_resources = None
|
158
|
+
picked_template = None
|
159
|
+
try:
|
160
|
+
templates = self.get_public_templates()
|
161
|
+
except Exception as e:
|
162
|
+
logger.error(f"Failed to get artifact templates, Error: {e}")
|
163
|
+
for template in templates:
|
164
|
+
if template.template_data and template.template_data.name == template_name:
|
165
|
+
picked_template = template
|
166
|
+
break
|
167
|
+
if not picked_template:
|
168
|
+
raise ValueError(f"Template with name {template_name} not found.")
|
169
|
+
|
170
|
+
try:
|
171
|
+
if gpu_type not in ["H100", "H200"]:
|
172
|
+
raise ValueError("Only support A100 and H100 for now")
|
173
|
+
|
174
|
+
type, env_vars, serve_args_dict = parse_server_command(serve_command)
|
175
|
+
if type.lower() not in template_name.lower():
|
176
|
+
raise ValueError(f"Template {template_name} does not support inference with {type}.")
|
177
|
+
num_gpus = extract_gpu_num_from_serve_command(serve_args_dict)
|
178
|
+
recommended_replica_resources = ReplicaResource(
|
179
|
+
cpu=num_gpus * 16,
|
180
|
+
ram_gb=num_gpus * 100,
|
181
|
+
gpu=num_gpus,
|
182
|
+
gpu_name=gpu_type,
|
183
|
+
)
|
184
|
+
except Exception as e:
|
185
|
+
raise ValueError(f"Failed to parse serve command, Error: {e}")
|
186
|
+
|
187
|
+
try:
|
188
|
+
env_vars = [
|
189
|
+
EnvParameter(key="SERVE_COMMAND", value=serve_command),
|
190
|
+
EnvParameter(key="GPU_TYPE", value=gpu_type),
|
191
|
+
]
|
192
|
+
resp = self.create_artifact(artifact_name, artifact_description, deployment_type="template", template_id=picked_template.template_id, env_parameters=env_vars)
|
193
|
+
# Assume Artifact is already with BuildStatus.SUCCESS status
|
194
|
+
return resp.artifact_id, recommended_replica_resources
|
195
|
+
except Exception as e:
|
196
|
+
logger.error(f"Failed to create artifact from template, Error: {e}")
|
197
|
+
raise e
|
128
198
|
|
129
199
|
def rebuild_artifact(self, artifact_id: str) -> RebuildArtifactResponse:
|
130
200
|
"""
|
@@ -211,7 +281,7 @@ class ArtifactManager:
|
|
211
281
|
model_file_name = os.path.basename(model_file_path)
|
212
282
|
model_file_type = mimetypes.guess_type(model_file_path)[0]
|
213
283
|
|
214
|
-
req =
|
284
|
+
req = ResumableUploadLinkRequest(artifact_id=artifact_id, file_name=model_file_name, file_type=model_file_type)
|
215
285
|
|
216
286
|
resp = self.artifact_client.get_bigfile_upload_url(req)
|
217
287
|
if not resp or not resp.upload_link:
|
@@ -250,36 +320,64 @@ class ArtifactManager:
|
|
250
320
|
|
251
321
|
FileUploadClient.upload_large_file(upload_link, file_path)
|
252
322
|
|
323
|
+
|
324
|
+
def upload_model_files_to_artifact(self, artifact_id: str, model_directory: str) -> None:
|
325
|
+
"""
|
326
|
+
Upload model files to an existing artifact.
|
327
|
+
|
328
|
+
:param artifact_id: The ID of the artifact to upload the model files to.
|
329
|
+
:param model_directory: The path to the model directory.
|
330
|
+
"""
|
331
|
+
|
332
|
+
# List all files in the model directory recursively
|
333
|
+
model_file_paths = []
|
334
|
+
for root, _, files in os.walk(model_directory):
|
335
|
+
for file in files:
|
336
|
+
model_file_paths.append(os.path.join(root, file))
|
337
|
+
|
338
|
+
def upload_file(model_file_path):
|
339
|
+
self._validate_file_path(model_file_path)
|
340
|
+
bigfile_upload_url_resp = self.artifact_client.get_bigfile_upload_url(
|
341
|
+
ResumableUploadLinkRequest(artifact_id=artifact_id, file_name=os.path.basename(model_file_path))
|
342
|
+
)
|
343
|
+
FileUploadClient.upload_large_file(bigfile_upload_url_resp.upload_link, model_file_path)
|
344
|
+
|
345
|
+
# Upload files in parallel with progress bar
|
346
|
+
with tqdm(total=len(model_file_paths), desc="Uploading model files") as progress_bar:
|
347
|
+
with logging_redirect_tqdm():
|
348
|
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
349
|
+
futures = {executor.submit(upload_file, path): path for path in model_file_paths}
|
350
|
+
for future in concurrent.futures.as_completed(futures):
|
351
|
+
try:
|
352
|
+
future.result()
|
353
|
+
except Exception as e:
|
354
|
+
logger.error(f"Failed to upload file {futures[future]}, Error: {e}")
|
355
|
+
progress_bar.update(1)
|
356
|
+
|
253
357
|
def create_artifact_with_model_files(
|
254
358
|
self,
|
255
359
|
artifact_name: str,
|
256
360
|
artifact_file_path: str,
|
257
|
-
|
361
|
+
model_directory: str,
|
258
362
|
description: Optional[str] = "",
|
259
363
|
tags: Optional[str] = None
|
260
364
|
) -> str:
|
261
365
|
"""
|
262
366
|
Create a new artifact for a user and upload model files associated with the artifact.
|
263
|
-
|
264
367
|
:param artifact_name: The name of the artifact.
|
265
368
|
:param artifact_file_path: The path to the artifact file(Dockerfile+serve.py).
|
266
|
-
:param
|
369
|
+
:param model_directory: The path to the model directory.
|
267
370
|
:param description: An optional description for the artifact.
|
268
371
|
:param tags: Optional tags associated with the artifact, as a comma-separated string.
|
269
372
|
:return: The `artifact_id` of the created artifact.
|
270
|
-
:raises FileNotFoundError: If the provided `file_path` does not exist.
|
271
373
|
"""
|
272
374
|
artifact_id = self.create_artifact_with_file(artifact_name, artifact_file_path, description, tags)
|
375
|
+
logger.info(f"Artifact created: {artifact_id}")
|
273
376
|
|
274
|
-
|
275
|
-
self._validate_file_path(model_file_path)
|
276
|
-
bigfile_upload_url_resp = self.artifact_client.get_bigfile_upload_url(
|
277
|
-
GetBigFileUploadUrlRequest(artifact_id=artifact_id, model_file_path=model_file_path)
|
278
|
-
)
|
279
|
-
FileUploadClient.upload_large_file(bigfile_upload_url_resp.upload_link, model_file_path)
|
377
|
+
self.upload_model_files_to_artifact(artifact_id, model_directory)
|
280
378
|
|
281
379
|
return artifact_id
|
282
|
-
|
380
|
+
|
283
381
|
|
284
382
|
def wait_for_artifact_ready(self, artifact_id: str, timeout_s: int = 900) -> None:
|
285
383
|
"""
|
@@ -304,12 +402,12 @@ class ArtifactManager:
|
|
304
402
|
time.sleep(10)
|
305
403
|
|
306
404
|
|
307
|
-
def get_public_templates(self) -> List[
|
405
|
+
def get_public_templates(self) -> List[Template]:
|
308
406
|
"""
|
309
407
|
Fetch all artifact templates.
|
310
408
|
|
311
|
-
:return: A list of
|
312
|
-
:rtype: List[
|
409
|
+
:return: A list of Template objects.
|
410
|
+
:rtype: List[Template]
|
313
411
|
"""
|
314
412
|
return self.artifact_client.get_public_templates()
|
315
413
|
|