Repository navigation
Add optional Telys connector example #372
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
Open
0xamlab
wants to merge
4
commits into
runpod-workers:main
Choose a base branch
from
0xamlab:feature/telys-connector-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,27 @@ | ||
| FROM runpod/worker-v1-vllm:v2.30.3 | ||
|
|
||
| ARG TELYS_VLLM_COMMIT=2f0c20ccec56afcb613973e296281f51e23cbe26 | ||
| RUN python3 - "$TELYS_VLLM_COMMIT" <<'PY' | ||
| import re | ||
| import sys | ||
|
|
||
| commit = sys.argv[1] | ||
| if re.fullmatch(r"[0-9a-f]{40}", commit) is None: | ||
| raise SystemExit( | ||
| "TELYS_VLLM_COMMIT must be a full 40-character lowercase SHA; " | ||
| "branches, tags, short SHAs, and other revision forms are not accepted" | ||
| ) | ||
| PY | ||
|
|
||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends git \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| RUN python3 -m pip install --no-cache-dir "telys==0.1.15" \ | ||
| && python3 -m pip install --no-cache-dir --no-deps \ | ||
| "telys-vllm @ git+https://github.com/thyn-ai/telys-vllm.git@${TELYS_VLLM_COMMIT}" \ | ||
| && python3 -c 'from importlib.metadata import version; vllm_version = version("vllm"); assert vllm_version == "0.32.0", f"expected vllm==0.32.0, found {vllm_version}"; telys_version = version("telys"); assert telys_version == "0.1.15", f"expected telys==0.1.15, found {telys_version}"; connector_version = version("telys-vllm"); assert connector_version == "0.1.6", f"expected telys-vllm==0.1.6, found {connector_version}"; from telys_vllm.connector import TelysKVConnector' | ||
|
|
||
| COPY --chmod=0755 examples/telys/entrypoint.sh /usr/local/bin/telys-vllm-entrypoint | ||
|
|
||
| ENTRYPOINT ["/usr/local/bin/telys-vllm-entrypoint"] |
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,135 @@ | ||
| # Optional Telys KV connector example | ||
|
|
||
| This derived image adds the [Telys vLLM connector](https://github.com/thyn-ai/telys-vllm) | ||
| to the stock `runpod/worker-v1-vllm:v2.30.3` image (vLLM 0.32.0). The upstream worker's | ||
| `/src/main.py` startup path remains unchanged. Telys is disabled unless | ||
| `TELYS_ENABLED=true` is set explicitly. | ||
|
|
||
| ## Build | ||
|
|
||
| `TELYS_VLLM_COMMIT` defaults to | ||
| `2f0c20ccec56afcb613973e296281f51e23cbe26`, the source commit for connector `v0.1.6`. | ||
| The Dockerfile installs from the immutable `git+https` source at that commit. Overrides | ||
| must use a full 40-character lowercase SHA; branches, tags, short SHAs, and uppercase | ||
| SHAs are rejected. | ||
|
|
||
| Build from the worker repository root: | ||
|
|
||
| ```bash | ||
| docker build --platform=linux/amd64 \ | ||
| --file examples/telys/Dockerfile \ | ||
| --build-arg TELYS_VLLM_COMMIT=2f0c20ccec56afcb613973e296281f51e23cbe26 \ | ||
| --tag your-dockerhub-user/telys-worker-vllm:VERSION . | ||
| ``` | ||
|
|
||
| The build installs `telys==0.1.15`, installs the connector directly from the pinned | ||
| commit with `--no-deps`, and checks that vLLM remains exactly 0.32.0, the connector | ||
| distribution is 0.1.6, and `TelysKVConnector` imports. It does not bake in a model, | ||
| Telys credentials, or a signed Telys runtime. Publishing the resulting image is a | ||
| separate operation. | ||
|
|
||
| The stable `telys-vllm==0.1.6` and `telys==0.1.15` packages are public on PyPI. The | ||
| connector project's stable GHCR release image is also public and can be pulled without | ||
| registry credentials at | ||
| `ghcr.io/thyn-ai/telys-worker-vllm@sha256:1b02b3cdac471064e8b9968fe2ab87f99da2d455e04d9cffea6b74b745a4218f`. | ||
| The build above uses the immutable connector source commit rather than that prebuilt | ||
| image. | ||
|
|
||
| ## Stock behavior (default) | ||
|
|
||
| Leave `TELYS_ENABLED` unset or set it to `false`. The entrypoint immediately executes | ||
| `python3 /src/main.py` with the original arguments and environment. Non-Telys vLLM | ||
| configuration, including another `KV_TRANSFER_CONFIG` connector such as the stock | ||
| filesystem offloader, is passed through unchanged. | ||
|
|
||
| To prevent an accidental partial configuration, the disabled path rejects nonempty | ||
| `TELYS_API_KEY` or `TELYS_OAUTH_TOKEN`, and rejects a `KV_TRANSFER_CONFIG` that names | ||
| `TelysKVConnector` or `telys_vllm.connector`. It never provisions Telys in this mode. | ||
| `TELYS_ENABLED` accepts exactly `true` or `false`. | ||
|
|
||
| In both modes, the entrypoint rejects `--kv-transfer-config` in `VLLM_EXTRA_ARGS`, | ||
| including both `--kv-transfer-config value` and `--kv-transfer-config=value` forms, | ||
| instead of letting it bypass the connector checks. Set `KV_TRANSFER_CONFIG` instead. | ||
| Other extra arguments pass through unchanged. | ||
|
|
||
| ## Enable Telys | ||
|
|
||
| Attach a network volume at `/runpod-volume`. A minimal endpoint configuration is: | ||
|
|
||
| ```bash | ||
| TELYS_ENABLED=true | ||
| TELYS_HOME=/runpod-volume/telys-home | ||
| TELYS_PATH=/runpod-volume/telys-data | ||
| MODEL_NAME=Qwen/Qwen2.5-7B-Instruct | ||
| ENABLE_PREFIX_CACHING=false | ||
| VLLM_ENABLE_V1_MULTIPROCESSING=0 | ||
| # HF_TOKEN=<only for a gated/private model; configure it as a secret> | ||
| ``` | ||
|
|
||
| When enabled, the entrypoint supplies this connector configuration unless one is | ||
| already present: | ||
|
|
||
| ```bash | ||
| KV_TRANSFER_CONFIG={"kv_connector":"TelysKVConnector","kv_connector_module_path":"telys_vllm.connector","kv_role":"kv_both"} | ||
| ``` | ||
|
|
||
| A custom `KV_TRANSFER_CONFIG` must be valid JSON with those same connector, module, | ||
| and role values. `kv_connector_extra_config` may contain supported Telys settings. Do | ||
| not configure another KV connector on the same endpoint. Disabling native prefix | ||
| caching and V1 multiprocessing matches the connector-only validation setup; choose | ||
| those settings deliberately for other workloads. | ||
|
|
||
| The entrypoint sets `TELYS_VLLM_LOAD_ASYNC=0`. Asynchronous KV loading is unsupported | ||
| in this connector revision. Startup fails if the environment or | ||
| `kv_connector_extra_config.telys_load_async` attempts to enable it. | ||
|
|
||
| `TELYS_HOME` holds the SDK runtime and login state. Embedded engine data uses | ||
| `TELYS_PATH`; BlobStore payloads use `TELYS_PATH` with `_blobs` appended, and the | ||
| fallback slab defaults to `TELYS_PATH` with `_kv.slab` appended. Set | ||
| `TELYS_VLLM_SLAB_PATH` explicitly when using a remote engine with the slab fallback. | ||
| Keep runtime state, metadata, and payloads on persistent storage, use separate cache | ||
| namespaces for incompatible model/KV configurations, and restrict access to the volume. | ||
|
|
||
| ## Provision the Telys runtime | ||
|
|
||
| For a runtime that is not installed yet, configure exactly one credential as a Runpod | ||
| secret: | ||
|
|
||
| - `TELYS_API_KEY`: direct API-key provisioning. The entrypoint registers the device, | ||
| atomically writes `login_license.jwt` under `TELYS_HOME` with mode `0600`, and calls | ||
| the SDK installer. An API key is not an OAuth token. | ||
| - `TELYS_OAUTH_TOKEN`: OAuth-only provisioning through | ||
| `telys login --token ... --no-browser --plan telys_developer`. | ||
|
|
||
| If both are present, API-key provisioning takes precedence; there is no fallback from | ||
| a failed API-key attempt to OAuth. Any provisioning failure stops startup. After | ||
| success, both credential variables are removed from the worker environment before the | ||
| upstream entrypoint runs. Do not put credentials in the Dockerfile, `ENV`, | ||
| `KV_TRANSFER_CONFIG`, or `VLLM_EXTRA_ARGS`. | ||
|
|
||
| After the signed runtime and login state are installed on the volume, remove both | ||
| credential variables. The entrypoint skips login when both are empty and uses the | ||
| existing runtime. Perform initial provisioning with one worker before allowing | ||
| concurrent workers to initialize the same `TELYS_HOME`. | ||
|
|
||
| ## Checks and required acceptance | ||
|
|
||
| The CPU-only checks exercise the entrypoint with fake SDK/CLI boundaries, inspect the | ||
| Dockerfile, and execute its commit validator: | ||
|
|
||
| ```bash | ||
| python3 -m pytest tests/test_telys_example.py -v | ||
| ``` | ||
|
|
||
| They do not pull the base image, install the connector, download a model, access a GPU, | ||
| or contact Telys or Runpod. They are not remote acceptance evidence. | ||
|
|
||
| Before production use, complete all of the following with the selected final commit: | ||
|
|
||
| - Build the `linux/amd64` image and confirm its vLLM, SDK, and connector import checks. | ||
| - Verify the default path with the normal worker smoke test and a non-Telys connector. | ||
| - Provision the signed runtime and start a real endpoint with the target model, GPU, | ||
| network volume, and model/KV settings. | ||
| - Check cold misses, warm hits from a fresh worker, output equivalence against an | ||
| uncached reference, persistence drain, disk use, and restart behavior. | ||
| - Validate multi-writer or multi-group topologies separately rather than assuming them. |
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,133 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| set +x | ||
|
|
||
| readonly DEFAULT_KV_TRANSFER_CONFIG='{"kv_connector":"TelysKVConnector","kv_connector_module_path":"telys_vllm.connector","kv_role":"kv_both"}' | ||
|
|
||
| fail() { | ||
| printf 'telys-vllm entrypoint: %s\n' "$1" >&2 | ||
| exit 64 | ||
| } | ||
|
|
||
| python3 - <<'PY' | ||
| import os | ||
| import shlex | ||
| import sys | ||
|
|
||
| extra_args = shlex.split(os.environ.get("VLLM_EXTRA_ARGS", "")) | ||
| if any( | ||
| arg == "--kv-transfer-config" or arg.startswith("--kv-transfer-config=") | ||
| for arg in extra_args | ||
| ): | ||
| print( | ||
| "telys-vllm entrypoint: --kv-transfer-config is not allowed in " | ||
| "VLLM_EXTRA_ARGS; set KV_TRANSFER_CONFIG instead", | ||
| file=sys.stderr, | ||
| ) | ||
| raise SystemExit(64) | ||
| PY | ||
|
|
||
| case "${TELYS_ENABLED:-false}" in | ||
| false) | ||
| if [[ -n "${TELYS_API_KEY:-}" || -n "${TELYS_OAUTH_TOKEN:-}" ]]; then | ||
| fail "Telys credentials require TELYS_ENABLED=true" | ||
| fi | ||
| if [[ "${KV_TRANSFER_CONFIG:-}" == *"TelysKVConnector"* || "${KV_TRANSFER_CONFIG:-}" == *"telys_vllm.connector"* ]]; then | ||
| fail "the Telys connector requires TELYS_ENABLED=true" | ||
| fi | ||
| exec python3 /src/main.py "$@" | ||
| ;; | ||
| true) | ||
| ;; | ||
| *) | ||
| fail "TELYS_ENABLED must be exactly 'true' or 'false'" | ||
| ;; | ||
| esac | ||
|
|
||
| export KV_TRANSFER_CONFIG="${KV_TRANSFER_CONFIG:-$DEFAULT_KV_TRANSFER_CONFIG}" | ||
| python3 - <<'PY' | ||
| import json | ||
| import os | ||
|
|
||
| FALSE_VALUES = {"0", "false", "no", "off"} | ||
| EXPECTED = { | ||
| "kv_connector": "TelysKVConnector", | ||
| "kv_connector_module_path": "telys_vllm.connector", | ||
| "kv_role": "kv_both", | ||
| } | ||
|
|
||
|
|
||
| def require_false(value, source): | ||
| if isinstance(value, bool): | ||
| valid = not value | ||
| elif isinstance(value, str): | ||
| valid = value.strip().lower() in FALSE_VALUES | ||
| else: | ||
| valid = False | ||
| if not valid: | ||
| raise SystemExit( | ||
| f"telys-vllm entrypoint: {source} must be false; " | ||
| "asynchronous KV loading is unsupported" | ||
| ) | ||
|
|
||
|
|
||
| try: | ||
| config = json.loads(os.environ["KV_TRANSFER_CONFIG"]) | ||
| except json.JSONDecodeError as exc: | ||
| raise SystemExit( | ||
| "telys-vllm entrypoint: KV_TRANSFER_CONFIG must be valid JSON" | ||
| ) from exc | ||
|
|
||
| if not isinstance(config, dict): | ||
| raise SystemExit("telys-vllm entrypoint: KV_TRANSFER_CONFIG must be a JSON object") | ||
| if any(config.get(key) != value for key, value in EXPECTED.items()): | ||
| raise SystemExit( | ||
| "telys-vllm entrypoint: TELYS_ENABLED=true requires TelysKVConnector " | ||
| "from telys_vllm.connector with kv_role=kv_both" | ||
| ) | ||
|
|
||
| extra = config.get("kv_connector_extra_config", {}) | ||
| if not isinstance(extra, dict): | ||
| raise SystemExit( | ||
| "telys-vllm entrypoint: kv_connector_extra_config must be a JSON object" | ||
| ) | ||
| require_false(extra.get("telys_load_async", False), "telys_load_async") | ||
| if "TELYS_VLLM_LOAD_ASYNC" in os.environ: | ||
| require_false( | ||
| os.environ["TELYS_VLLM_LOAD_ASYNC"], "TELYS_VLLM_LOAD_ASYNC" | ||
| ) | ||
| PY | ||
| export TELYS_VLLM_LOAD_ASYNC=0 | ||
|
|
||
| if [[ -n "${TELYS_API_KEY:-}" ]]; then | ||
| python3 - <<'PY' | ||
| import os | ||
| import tempfile | ||
|
|
||
| import telys.installer | ||
| import telys.login | ||
| import telys.paths | ||
|
|
||
| key = os.environ["TELYS_API_KEY"] | ||
| home = telys.paths.telys_home() | ||
| os.makedirs(home, mode=0o700, exist_ok=True) | ||
| license_token = telys.login.register_device( | ||
| api=telys.paths.api_url(), api_key=key | ||
| ) | ||
| license_path = os.path.join(home, "login_license.jwt") | ||
| descriptor, temporary_path = tempfile.mkstemp(dir=home, prefix=".login_license.") | ||
| try: | ||
| with os.fdopen(descriptor, "w", encoding="utf-8") as license_file: | ||
| license_file.write(license_token) | ||
| os.replace(temporary_path, license_path) | ||
| finally: | ||
| if os.path.exists(temporary_path): | ||
| os.unlink(temporary_path) | ||
| telys.installer.install_from_host(token=key, license_path=license_path) | ||
| PY | ||
| elif [[ -n "${TELYS_OAUTH_TOKEN:-}" ]]; then | ||
| telys login --token "$TELYS_OAUTH_TOKEN" --no-browser --plan telys_developer | ||
| fi | ||
|
|
||
| unset TELYS_API_KEY TELYS_OAUTH_TOKEN | ||
| exec python3 /src/main.py "$@" | ||
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.
When an endpoint supplies
--kv-transfer-configthrough the supportedVLLM_EXTRA_ARGSsetting, this guard never examines it: withTELYS_ENABLEDunset orfalse, a Telys configuration reaches the stock entrypoint without being rejected. In enabled mode, the same setting can replace the validated Telys configuration with another connector, becausebuild_vllm_args()appends raw arguments last (docs/configuration.md:52-53explicitly documents them as “able to override anything above”). This bypasses the wrapper’s opt-in and exclusive-connector checks. Validate the effective connector configuration, or reject connector overrides in passthrough arguments, before either startup branch proceeds.Useful? React with 👍 / 👎.