-
Notifications
You must be signed in to change notification settings - Fork 2
feat(sdk): support inference_v3 config_file mount #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
07232af
5b90163
aa47d7e
608e3c4
2095ab5
82decf1
009be9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import os | ||
| from typing import Optional | ||
|
|
||
| from platform_api_python_client import ConfigFileMount | ||
|
|
||
|
|
||
| # Load a file off disk into a ConfigFileMount. `mount_path` is the parent | ||
| # directory inside the container; the file lands at `mount_path/filename`. | ||
| # Field-level validation (size cap, filename charset, mount_path rules) is | ||
| # left to the API so SDK doesn't drift when server limits change. | ||
| def load_config_file_mount(path: str, mount_path: str, filename: Optional[str] = None) -> ConfigFileMount: | ||
| with open(path, "r", encoding="utf-8") as f: | ||
| content = f.read() | ||
| return ConfigFileMount(filename=filename or os.path.basename(path), mount_path=mount_path, content=content) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import centml | ||
| from centml.sdk.api import get_centml_client | ||
| from centml.sdk import DeploymentType, CreateInferenceV3DeploymentRequest, UserVaultType | ||
| from centml.sdk.utils.config_file import load_config_file_mount | ||
|
|
||
|
|
||
| def main(): | ||
|
|
@@ -22,6 +23,12 @@ def main(): | |
| max_unavailable=0, # Keep all pods available during updates | ||
| healthcheck="/", | ||
| concurrency=10, | ||
| # Mounts ./default.conf at /etc/nginx/conf.d/default.conf. mount_path | ||
| # is the parent directory; filename defaults to os.path.basename(path) | ||
| # so the resulting file lands at mount_path/filename. Pass an inline | ||
| # ConfigFileMount(filename=..., mount_path=..., content=...) if the | ||
| # content is already in memory. | ||
| config_file=load_config_file_mount(path="./default.conf", mount_path="/etc/nginx/conf.d"), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| ) | ||
| response = cclient.create_inference(request) | ||
| print("Create deployment response: ", response) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import centml | ||
| from centml.sdk.api import get_centml_client | ||
| from centml.sdk import CreateInferenceV3DeploymentRequest | ||
| from centml.sdk.utils.config_file import load_config_file_mount | ||
|
|
||
|
|
||
| def main(): | ||
| with get_centml_client() as cclient: | ||
| # Mounts ./chat_template.jinja at /etc/vllm/chat_template.jinja and | ||
| # tells vLLM to use it via --chat-template. mount_path is the parent | ||
| # directory; filename defaults to os.path.basename(path). | ||
| request = CreateInferenceV3DeploymentRequest( | ||
| name="vllm-llama", | ||
| cluster_id=1000, | ||
| hardware_instance_id=1001, # GPU instance | ||
| image_url="vllm/vllm-openai:latest", | ||
| port=8000, | ||
| min_replicas=1, | ||
| max_replicas=1, | ||
| initial_replicas=1, | ||
| max_surge=1, | ||
| max_unavailable=0, | ||
| healthcheck="/health", | ||
| concurrency=10, | ||
| env_vars={"HF_TOKEN": "<your-hf-token>"}, | ||
| command=( | ||
| "python -m vllm.entrypoints.openai.api_server " | ||
| "--model meta-llama/Llama-3.2-3B-Instruct " | ||
| "--port 8000 " | ||
| "--chat-template /etc/vllm/chat_template.jinja" | ||
| ), | ||
| config_file=load_config_file_mount(path="./chat_template.jinja", mount_path="/etc/vllm"), | ||
|
michaelshin marked this conversation as resolved.
Outdated
|
||
| ) | ||
| response = cclient.create_inference(request) | ||
| print("Create deployment response: ", response) | ||
|
|
||
| deployment = cclient.get_inference(response.id) | ||
| print("Deployment details: ", deployment) | ||
|
|
||
| ''' | ||
| ### Pause the deployment | ||
| cclient.pause(deployment.id) | ||
|
|
||
| ### Delete the deployment | ||
| cclient.delete(deployment.id) | ||
| ''' | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Tests for centml.sdk.utils.config_file.load_config_file_mount.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from centml.sdk.utils.config_file import load_config_file_mount | ||
|
|
||
|
|
||
| def test_default_filename_from_basename(tmp_path): | ||
| src = tmp_path / "nginx.conf" | ||
| src.write_text("server { listen 80; }\n") | ||
|
|
||
| mount = load_config_file_mount(str(src), "/etc/nginx/conf.d") | ||
|
|
||
| assert mount.filename == "nginx.conf" | ||
| assert mount.mount_path == "/etc/nginx/conf.d" | ||
| assert mount.content == "server { listen 80; }\n" | ||
|
|
||
|
|
||
| def test_explicit_filename_overrides_basename(tmp_path): | ||
| src = tmp_path / "local.txt" | ||
| src.write_text("payload") | ||
|
|
||
| mount = load_config_file_mount(str(src), "/app/etc", filename="remote.conf") | ||
|
|
||
| assert mount.filename == "remote.conf" | ||
| assert mount.mount_path == "/app/etc" | ||
| assert mount.content == "payload" | ||
|
|
||
|
|
||
| def test_utf8_multibyte_content_roundtrips(tmp_path): | ||
| src = tmp_path / "i18n.conf" | ||
| src.write_text("配置内容 = 测试\n", encoding="utf-8") | ||
|
|
||
| mount = load_config_file_mount(str(src), "/etc/app") | ||
|
|
||
| assert mount.content == "配置内容 = 测试\n" | ||
|
|
||
|
|
||
| def test_missing_file_raises_filenotfound(tmp_path): | ||
| with pytest.raises(FileNotFoundError): | ||
| load_config_file_mount(str(tmp_path / "does-not-exist.conf"), "/etc/x") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading with
open(path, "r", encoding="utf-8")uses universal-newline translation, so files with\r\nor\rline endings are normalized to\nbefore upload. In environments where config line endings are significant (for example Windows-authored configs consumed byte-sensitively), this silently alters the mounted content.Useful? React with 👍 / 👎.