-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
07232af
feat(sdk): support inference_v3 config_file mount
V2arK 5b90163
fix(sdk): correct mount_path semantics in config_file example/helper
V2arK aa47d7e
docs(examples): add vLLM inference example with chat_template config_…
V2arK 608e3c4
style(examples): black-format create_inference.py
V2arK 2095ab5
docs(examples): drive vllm example via --config <yaml> (#136 review)
V2arK 82decf1
fix(examples): vllm example uses python3 + moves port into yaml
V2arK 009be9b
fix(sdk): address codex review feedback on #136
V2arK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| 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: | ||
| # newline="" disables universal-newline translation so CRLF/CR line | ||
| # endings reach the server byte-faithful instead of being normalized to \n. | ||
| with open(path, "r", encoding="utf-8", newline="") as f: | ||
| content = f.read() | ||
| return ConfigFileMount(filename=filename or os.path.basename(path), mount_path=mount_path, content=content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| 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 ./vllm_config.yaml at /etc/vllm/vllm_config.yaml and lets vLLM | ||
| # consume the whole config via --config. mount_path is the parent | ||
| # directory; filename defaults to os.path.basename(path) so the file | ||
| # lands at mount_path/filename. The sibling vllm_config.yaml in this | ||
| # directory shows a realistic Llama-3.1-8B + EAGLE3 speculative-decoding | ||
| # setup; edit it (model, dtype, tensor-parallel-size, speculative-config, | ||
| # etc.) to match the workload before deploying. | ||
| 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="python3 -m vllm.entrypoints.openai.api_server --config /etc/vllm/vllm_config.yaml", | ||
| config_file=load_config_file_mount(path="./vllm_config.yaml", mount_path="/etc/vllm"), | ||
| ) | ||
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| server { | ||
| listen 8080; | ||
| location / { | ||
| return 200 "hello from config_file\n"; | ||
| add_header Content-Type text/plain; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| port: 8000 | ||
| model: meta-llama/Llama-3.1-8B-Instruct | ||
| tokenizer: meta-llama/Llama-3.1-8B-Instruct | ||
| runner: generate | ||
| dtype: auto | ||
| gpu-memory-utilization: 0.9 | ||
| max-num-seqs: 2048 | ||
| tokenizer-mode: auto | ||
| seed: 0 | ||
| tensor-parallel-size: 1 | ||
| pipeline-parallel-size: 1 | ||
| block-size: 16 | ||
| attention-backend: FLASHINFER | ||
| distributed-executor-backend: uni | ||
| enable-prefix-caching: true | ||
| enable-chunked-prefill: true | ||
| max-num-batched-tokens: 1024 | ||
| speculative-config: | ||
| method: eagle3 | ||
| model: centml/EAGLE3-Llama3.1-8B-Instruct | ||
| num_speculative_tokens: 3 | ||
| draft_tensor_parallel_size: 1 | ||
| enable-auto-tool-choice: true | ||
| tool-call-parser: llama3_json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """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") | ||
|
|
||
|
|
||
| def test_preserves_crlf_line_endings(tmp_path): | ||
| # Windows-authored configs use \r\n; the helper must not silently | ||
| # normalize them to \n when uploading to the server. | ||
| src = tmp_path / "windows.conf" | ||
| src.write_bytes(b"line1\r\nline2\r\n") | ||
|
|
||
| mount = load_config_file_mount(str(src), "/etc/app") | ||
|
|
||
| assert mount.content == "line1\r\nline2\r\n" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
create_inference.pynow unconditionally callsload_config_file_mount("./default.conf", ...), but this repository does not includeexamples/sdk/default.conf, so the example raisesFileNotFoundErrorbefore any deployment call when run as-is. This makes the existing example non-runnable unless users discover and create an extra file manually.Useful? React with 👍 / 👎.