From 1f347f5003c20f7bc44f209d6dc4c1f254c0d7c1 Mon Sep 17 00:00:00 2001 From: kwisniewski98 Date: Mon, 30 Nov 2026 13:18:09 +0100 Subject: [PATCH 1/2] feat(model-manager): add cpu-pinning-operator CPU policy intel/cpu-pinning-operator runs the NRI balloons plugin and pins model pods from its admission webhook. Under this policy model-manager renders no balloon annotation and runs no placement pre-flight; the operator's capacity check applies. Auto-detection picks it when the cluster has BalloonsClusterConfig/cluster. llm_services validate warns when the policy is set but the operator is not installed. Toolkit Manager sets the policy with kubernetes_cpu_policy: cpu-pinning-operator. Signed-off-by: kwisniewski98 --- config.yaml | 1 + docs/configuration/configuration.md | 3 ++- docs/reference/cpu-pinning.md | 16 ++++++++++++++-- model_manager/core/cli.py | 9 +++++++-- model_manager/core/policy.py | 15 ++++++++++++--- model_manager/tests/test_parity.py | 26 +++++++++++++++++++++----- model_manager/tests/test_units.py | 16 ++++++++++++++++ roles/llm_services/defaults/main.yaml | 1 + roles/llm_services/tasks/validate.yaml | 12 ++++++++++++ roles/llm_services/vars/main.yaml | 2 +- 10 files changed, 87 insertions(+), 14 deletions(-) diff --git a/config.yaml b/config.yaml index 09840500..353e8b26 100644 --- a/config.yaml +++ b/config.yaml @@ -57,6 +57,7 @@ envoy_ai_gateway_namespace: "envoy-ai-gateway-system" # All dependent settings (NRI install, kubelet flags, model annotations) are # auto-derived from this value. # nri-balloons (default) NRI balloons resource policy — NUMA-aware pinning +# cpu-pinning-operator the same plugin, run by intel/cpu-pinning-operator # kubelet-static kubelet static CPU manager (Guaranteed QoS pinning) # best-effort no pinning, standard scheduler # diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index a507ac78..6c12f2c5 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -187,12 +187,13 @@ A single switch controlling all CPU-pinning infrastructure. Dependent settings install, kubelet flags, model annotations — are derived from it. ```yaml -kubernetes_cpu_policy: "nri-balloons" # nri-balloons | kubelet-static | best-effort +kubernetes_cpu_policy: "nri-balloons" # nri-balloons | cpu-pinning-operator | kubelet-static | best-effort ``` | Value | Behaviour | |---|---| | `nri-balloons` (default) | NRI balloons resource policy — NUMA-aware pinning | +| `cpu-pinning-operator` | NRI balloons run by the CPU Pinning Operator; its webhook pins model pods | | `kubelet-static` | kubelet static CPU manager — Guaranteed QoS pinning | | `best-effort` | No pinning, standard scheduler | diff --git a/docs/reference/cpu-pinning.md b/docs/reference/cpu-pinning.md index 0e4ddbb6..8f3719d8 100644 --- a/docs/reference/cpu-pinning.md +++ b/docs/reference/cpu-pinning.md @@ -13,19 +13,20 @@ A *NUMA node* is a group of cores with the memory attached closest to them. Inte Toolkit pins model pods to physical cores that respect the node's NUMA topology, so each model gets exclusive, locality-aware CPU. -## The three policies +## The four policies One switch in [`config.yaml`](../configuration/configuration.md#cpu-policy) (in your environment: `env//config.inference.yaml`) controls all CPU-pinning infrastructure. Every dependent setting — NRI install, kubelet flags, model annotations — is derived from it. ```yaml -kubernetes_cpu_policy: "nri-balloons" # nri-balloons | kubelet-static | best-effort +kubernetes_cpu_policy: "nri-balloons" # nri-balloons | cpu-pinning-operator | kubelet-static | best-effort ``` | Policy | Mechanism | Use when | |---|---|---| | `nri-balloons` (default) | NRI balloons resource policy — NUMA-aware pinning into named CPU pools | The default. Best throughput and the most control | +| `cpu-pinning-operator` | The same NRI balloons plugin, run by the [CPU Pinning Operator](https://github.com/intel/cpu-pinning-operator): its admission webhook pins matched model pods | You want pinning kept in step with the nodes by an operator, with per-core dashboards | | `kubelet-static` | kubelet static CPU manager — Guaranteed QoS grants exclusive whole cores | You cannot run NRI, or you already standardized on the static CPU manager | | `best-effort` | No pinning; the standard scheduler places threads | Development, oversubscribed nodes, or debugging a pinning problem | @@ -111,6 +112,17 @@ more than one model. It runs `model_manager/scripts/nri-cpu-report.py`, which ne ./model-manager cpu-collisions-check ``` +## CPU Pinning Operator + +Under `cpu-pinning-operator`, model-manager renders the manifest without a balloon +annotation: the operator's admission webhook matches the serving container (`main` or +`kserve-container`), reads the span from `--tensor-parallel-size` and adds the annotation +itself. model-manager runs no placement pre-flight under this policy; the operator's own +capacity check applies. With no `MM_CPU_POLICY`, model-manager picks this policy when the +cluster has `BalloonsClusterConfig/cluster`. The operator is installed and configured from +the Toolkit Manager repo +([CPU Pinning Operator](https://github.com/intel/toolkit-manager/blob/main/docs/configuration/cpu-pinning-operator.md)). + ## kubelet static CPU manager Under `kubelet-static`, model pods are rendered as **Guaranteed QoS** — integer `cpu` diff --git a/model_manager/core/cli.py b/model_manager/core/cli.py index 6eef8454..23b976d7 100644 --- a/model_manager/core/cli.py +++ b/model_manager/core/cli.py @@ -53,7 +53,8 @@ (vLLM: waiting requests, default 2; OVMS: in-flight requests, default 4) {GREEN}--tp{RESET} N Tensor-parallel size (splits across N NUMA nodes; on a GPU runtime, also N GPUs) {GREEN}--gpus{RESET} N GPUs per pod (device: gpu runtimes, e.g. vllm-cuda); also the default --tp - {GREEN}--cpu-policy{RESET}

CPU pinning: nri-balloons | kubelet-static | best-effort + {GREEN}--cpu-policy{RESET}

CPU pinning: nri-balloons | cpu-pinning-operator | + kubelet-static | best-effort (default: MM_CPU_POLICY, else auto-detected) {GREEN}--category{RESET} Override category: llm | embed | rerank | vlm {GREEN}--routing{RESET} Override routing: epp | aigateway | direct @@ -85,7 +86,7 @@ {GREEN}HF_TOKEN{RESET} HuggingFace token for gated models {GREEN}MM_CONFIG{RESET} Path to models.yaml {GREEN}MM_CPU_POLICY{RESET} Cluster CPU policy: nri-balloons (default) | - kubelet-static | best-effort. Set by the Ansible + cpu-pinning-operator | kubelet-static | best-effort. Set by the Ansible install from kubernetes_cpu_policy; --cpu-policy wins. {GREEN}MM_NRI_ENABLED{RESET} Legacy: false ⇒ best-effort (no pinning) {GREEN}MM_PREFLIGHT{RESET} 'warn' ⇒ report placement failures, don't block @@ -101,6 +102,10 @@ {BOLD}{CYAN}CPU policies:{RESET} {GREEN}nri-balloons{RESET} (default) NRI balloons plugin — NUMA-aware balloons sized per TP shard. Requires the nri_cpu_balloons Ansible role. + {GREEN}cpu-pinning-operator{RESET} + The same plugin, run by intel/cpu-pinning-operator: its + webhook pins matched pods, so no balloon annotation and no + pre-flight here. Requires kubernetes_cpu_policy=cpu-pinning-operator. {GREEN}kubelet-static{RESET} kubelet static CPU manager — pods are rendered as Guaranteed QoS (integer cpu, requests == limits) so kubelet grants exclusive whole cores. No plugin needed. Requires the diff --git a/model_manager/core/policy.py b/model_manager/core/policy.py index a563cc85..0a667822 100644 --- a/model_manager/core/policy.py +++ b/model_manager/core/policy.py @@ -213,6 +213,13 @@ def failure(self, m: Model, tp: int) -> str: "(proceed anyway) or MM_SKIP_PREFLIGHT=1 (skip check).") +class CpuPinningOperator(BestEffort): + """intel/cpu-pinning-operator: its admission webhook annotates the pod and the NRI balloons plugin pins it, + so the manifest carries no balloon annotation; the operator's own capacity check stands in for the pre-flight.""" + name = "cpu-pinning-operator" + label = "operator" + + class GpuRuntime(BestEffort): """device: gpu runtimes carry no CPU pinning: balloons and static-CPU alignment are Xeon placement controls, and the accelerator resource limit does the scheduling. The pod is rendered without a CPU @@ -296,7 +303,7 @@ def failure(self, m: Model, tp: int) -> str: "with MM_PREFLIGHT=warn (proceed anyway) or MM_SKIP_PREFLIGHT=1 (skip check).") -POLICIES = {p.name: p for p in (NriBalloons, KubeletStatic, BestEffort)} +POLICIES = {p.name: p for p in (NriBalloons, CpuPinningOperator, KubeletStatic, BestEffort)} def _gpu_usage(pods: list, m: Model, resource: str) -> tuple[dict, dict, int]: @@ -407,7 +414,7 @@ def whole_cpus(cpu: str, floor: bool = False) -> int: def resolve_policy(requested: str, node: str) -> BestEffort: if requested and requested not in POLICIES: - abort(f"Invalid --cpu-policy '{requested}'. Valid: nri-balloons, kubelet-static, best-effort.") + abort(f"Invalid --cpu-policy '{requested}'. Valid: nri-balloons, cpu-pinning-operator, kubelet-static, best-effort.") env_policy = os.environ.get("MM_CPU_POLICY", "") if not requested and env_policy: requested = env_policy.lower() if env_policy.lower() in POLICIES else "" @@ -424,9 +431,11 @@ def resolve_policy(requested: str, node: str) -> BestEffort: info(f"Detected kubelet static CPU manager on '{node}' — using kubelet-static.") elif k8s.succeeds("get", "daemonset", "nri-resource-policy-balloons", "-n", "kube-system", "-o", "name"): requested = "nri-balloons" + elif k8s.succeeds("get", "balloonsclusterconfigs.cpu-pinning-operator.intel.com", "cluster", "-o", "name"): + requested = "cpu-pinning-operator" else: requested = "best-effort" - warn("No CPU-pinning mechanism detected (no NRI balloons DaemonSet, kubelet cpuManagerPolicy is not " + warn("No CPU-pinning mechanism detected (no NRI balloons DaemonSet or CPU Pinning Operator, kubelet cpuManagerPolicy is not " "static) — deploying best-effort, without CPU pinning.") return POLICIES[requested]() diff --git a/model_manager/tests/test_parity.py b/model_manager/tests/test_parity.py index 47809398..1cece143 100644 --- a/model_manager/tests/test_parity.py +++ b/model_manager/tests/test_parity.py @@ -159,6 +159,19 @@ def ovms_agw_route(name: str) -> tuple[str, str]: r" --gpus N GPUs per pod (device: gpu runtimes, e.g. vllm-cuda); also the default --tp\n"), (r"vllm \(default\) \| openvino \(alias: --runtime\)$", "vllm (default) | openvino | vllm-cuda | vllm-xpu (alias: --runtime)")] +# The cpu-pinning-operator policy: one more value in the help, the errors and auto-detection. +HELP_OPERATOR = [ + (r"(CPU pinning: nri-balloons \| )(kubelet-static \| best-effort)$", + r"\1cpu-pinning-operator |\n \2"), + (r"(Cluster CPU policy: nri-balloons \(default\) \|\n\s+)(kubelet-static)", r"\1cpu-pinning-operator | \2"), + (r"^( per TP shard\. Requires the nri_cpu_balloons Ansible role\.\n)", + r"\1 cpu-pinning-operator\n The same plugin, run by intel/cpu-pinning-operator: its\n" + r" webhook pins matched pods, so no balloon annotation and no\n" + r" pre-flight here. Requires kubernetes_cpu_policy=cpu-pinning-operator.\n"), +] +VALID_OPERATOR = (r"Valid: nri-balloons, ", "Valid: nri-balloons, cpu-pinning-operator, ") +DETECT_OPERATOR = (r"no NRI balloons DaemonSet, ", "no NRI balloons DaemonSet or CPU Pinning Operator, ") + def nri_node(in_use: int) -> list: """One Ready NRI worker w1: 2 NUMA nodes, 128 logical CPUs, siblings reserved; in_use balloon CPUs taken.""" @@ -240,7 +253,8 @@ def case(name, *args, env=None, k8s=(), catalog=None, deviations=()): (r"^\[WARN \] NRI balloons DaemonSet not found.*\nTraceback[\s\S]*?ValueError: .*\n", ""), (r"^/model-manager: line \d+: .*\n", "")]), case("nri-disabled-legacy-flag", "deploy", "qwen3-0-6b", "--dry-run", env={"MM_NRI_ENABLED": "false"}), - case("invalid-policy-env", "deploy", "qwen3-0-6b", "--dry-run", env={"MM_CPU_POLICY": "foo"}), + case("invalid-policy-env", "deploy", "qwen3-0-6b", "--dry-run", env={"MM_CPU_POLICY": "foo"}, + deviations=[DETECT_OPERATOR]), case("gateway-ref-env", "deploy", "qwen3-0-6b", "--dry-run", env={**BE, "MM_INFERENCE_GATEWAY": "gw2", "MM_INFERENCE_GATEWAY_NS": "gwns"}), case("fx-inline-template", "deploy", "tmpl-inline", "--dry-run", "--tp", "2", "--arg", "--trust-remote-code", @@ -267,10 +281,12 @@ def case(name, *args, env=None, k8s=(), catalog=None, deviations=()): case("fx-bad-env", "deploy", "badenv", "--dry-run", env=BE, catalog=FIXTURE), case("fx-bad-template", "deploy", "badtpl", "--dry-run", env=BE, catalog=FIXTURE), # CLI surface and validation errors. - case("no-args", deviations=[HELP_SVC_NS, *HELP_LIST, *HELP_HFID, *HELP_MEMORY, *HELP_GPU, *HELP_SCALING]), - case("help", "--help", deviations=[HELP_SVC_NS, *HELP_LIST, *HELP_HFID, *HELP_MEMORY, *HELP_GPU, *HELP_SCALING]), + case("no-args", deviations=[HELP_SVC_NS, *HELP_LIST, *HELP_HFID, *HELP_MEMORY, *HELP_GPU, *HELP_SCALING, + *HELP_OPERATOR]), + case("help", "--help", deviations=[HELP_SVC_NS, *HELP_LIST, *HELP_HFID, *HELP_MEMORY, *HELP_GPU, *HELP_SCALING, + *HELP_OPERATOR]), case("help-command", "help", deviations=[HELP_SVC_NS, *HELP_LIST, *HELP_HFID, *HELP_MEMORY, *HELP_GPU, - *HELP_SCALING]), + *HELP_SCALING, *HELP_OPERATOR]), case("version", "version"), case("version-flag", "-v"), case("unknown-option", "deploy", "qwen3-0-6b", "--bogus"), @@ -286,7 +302,7 @@ def case(name, *args, env=None, k8s=(), catalog=None, deviations=()): case("runtime-version-missing", "deploy", "llama3-8b-awq", "--server-version", "9.9", env=BE, deviations=[V0330]), case("flat-runtime-version", "deploy", "qwen3-5-2b-ovms", "--server-version", "1", env=BE), - case("invalid-cli-policy", "deploy", "qwen3-0-6b", "--cpu-policy", "bogus", "--dry-run"), + case("invalid-cli-policy", "deploy", "qwen3-0-6b", "--cpu-policy", "bogus", "--dry-run", deviations=[VALID_OPERATOR]), # Side effects (fake cluster). case("deploy-detached", "deploy", "qwen3-0-6b", env=BE, k8s=DOWNLOAD + POOL + QWEN_READY, deviations=[NO_LITELLM_URL]), diff --git a/model_manager/tests/test_units.py b/model_manager/tests/test_units.py index fe9bd278..8dc04fe7 100644 --- a/model_manager/tests/test_units.py +++ b/model_manager/tests/test_units.py @@ -1889,3 +1889,19 @@ def test_repo_root_found_by_either_installer_name(monkeypatch, tmp_path, install monkeypatch.setattr(config, "MM_DIR", mm_dir) monkeypatch.delenv("MM_GLOBAL_CONFIG_SEARCH", raising=False) assert config._repo_roots()[0] == tmp_path / "checkout" + + +def test_cpu_pinning_operator_is_selected_by_env_and_detected_by_its_cluster_config(monkeypatch): + monkeypatch.delenv("MM_NRI_ENABLED", raising=False) + monkeypatch.setenv("MM_CPU_POLICY", "cpu-pinning-operator") + assert isinstance(policy.resolve_policy("", ""), policy.CpuPinningOperator) + + monkeypatch.delenv("MM_CPU_POLICY") + monkeypatch.setattr(k8s, "out", lambda *a: "w1" if a[:2] == ("get", "nodes") else "") + monkeypatch.setattr(k8s, "succeeds", lambda *a: "balloonsclusterconfigs.cpu-pinning-operator.intel.com" in a) + chosen = policy.resolve_policy("", "") + assert isinstance(chosen, policy.CpuPinningOperator) + # The webhook adds the balloon annotation; the manifest only records the policy. + m = Model.__new__(Model) + m.cpu = "8" + assert chosen.annotations(m, 2) == ({"cpu-policy.model-manager.io/type": "cpu-pinning-operator"}, "8") diff --git a/roles/llm_services/defaults/main.yaml b/roles/llm_services/defaults/main.yaml index 98327076..acd91b79 100644 --- a/roles/llm_services/defaults/main.yaml +++ b/roles/llm_services/defaults/main.yaml @@ -15,6 +15,7 @@ # flags, model-manager annotations, CPU request doubling) is auto-derived. # # nri-balloons (default) NRI balloons resource policy — NUMA-aware pinning +# cpu-pinning-operator the same plugin, run by intel/cpu-pinning-operator # kubelet-static kubelet static CPU manager (Guaranteed QoS pinning) # best-effort no pinning, standard scheduler kubernetes_cpu_policy: "nri-balloons" diff --git a/roles/llm_services/tasks/validate.yaml b/roles/llm_services/tasks/validate.yaml index 992e3c69..5540dfab 100644 --- a/roles/llm_services/tasks/validate.yaml +++ b/roles/llm_services/tasks/validate.yaml @@ -53,6 +53,13 @@ failed_when: false register: _llm_nri_ds +- name: "llm_services | Check CPU Pinning Operator cluster config" + ansible.builtin.command: + cmd: kubectl get balloonsclusterconfigs.cpu-pinning-operator.intel.com cluster -o name + changed_when: false + failed_when: false + register: _llm_cpo_bcc + - name: "llm_services | Read kubelet cpuManagerPolicy from a node" ansible.builtin.shell: | set -o pipefail @@ -70,6 +77,7 @@ msg: - "Configured kubernetes_cpu_policy: {{ kubernetes_cpu_policy | default('nri-balloons') }}" - "NRI balloons DaemonSet: {{ 'present' if _llm_nri_ds.rc == 0 else 'absent' }}" + - "CPU Pinning Operator: {{ 'present' if _llm_cpo_bcc.rc == 0 else 'absent' }}" - "kubelet cpuManagerPolicy: {{ _llm_kubelet_cpu_policy.stdout | default('') | trim | default('unknown (needs RBAC on nodes/proxy)', true) }}" - name: "llm_services | Warn when the CPU policy does not match the cluster" @@ -81,6 +89,9 @@ the nri-resource-policy-balloons DaemonSet is not present in kube-system. Models will be annotated for NRI but get no CPU pinning. Run the nri_cpu_balloons role (./toolkit_manager.sh install nri_cpu_balloons). + {%- elif (kubernetes_cpu_policy | default('nri-balloons')) == 'cpu-pinning-operator' %} + the CPU Pinning Operator is not installed (no BalloonsClusterConfig/cluster). + Models will get no CPU pinning. Run ./toolkit_manager.sh install cpu_pinning_operator. {%- else %} kubelet reports cpuManagerPolicy='{{ _llm_kubelet_cpu_policy.stdout | default('') | trim }}', not 'static'. Guaranteed pods will NOT get exclusive CPUs. Re-run @@ -89,6 +100,7 @@ {%- endif %} when: >- ((kubernetes_cpu_policy | default('nri-balloons')) == 'nri-balloons' and _llm_nri_ds.rc != 0) + or ((kubernetes_cpu_policy | default('nri-balloons')) == 'cpu-pinning-operator' and _llm_cpo_bcc.rc != 0) or ((kubernetes_cpu_policy | default('nri-balloons')) == 'kubelet-static' and (_llm_kubelet_cpu_policy.stdout | default('') | trim) not in ['static', '']) diff --git a/roles/llm_services/vars/main.yaml b/roles/llm_services/vars/main.yaml index 4371a32f..3c937226 100644 --- a/roles/llm_services/vars/main.yaml +++ b/roles/llm_services/vars/main.yaml @@ -17,7 +17,7 @@ __llm_mm_env_common: MM_HTTPS_PROXY: "{{ https_proxy | default(lookup('env', 'https_proxy')) | default('') }}" MM_NO_PROXY: "{{ no_proxy | default(lookup('env', 'no_proxy')) | default('') }}" # CPU pinning: the cluster-wide kubernetes_cpu_policy (nri-balloons | - # kubelet-static | best-effort), so models match what kubelet/NRI runs. + # cpu-pinning-operator | kubelet-static | best-effort), so models match what kubelet/NRI runs. MM_CPU_POLICY: "{{ kubernetes_cpu_policy | default('nri-balloons') }}" # Legacy flag for older model-manager builds; MM_CPU_POLICY wins. MM_NRI_ENABLED: "{{ 'true' if kubernetes_cpu_policy | default('nri-balloons') == 'nri-balloons' else 'false' }}" From da097274db4b0ecdd2be377afe56c23a8e8eaef0 Mon Sep 17 00:00:00 2001 From: kwisniewski98 Date: Mon, 30 Nov 2026 14:13:47 +0100 Subject: [PATCH 2/2] feat(model-manager): pin GPU pods under cpu-pinning-operator The CPU Pinning Operator puts any pod that requests a device in its balloon-device type, but only one whose CPU request equals its limit in whole cores. Under this policy (asked for, or the operator detected) GPU runtimes now keep a whole-core CPU limit and carry the policy annotation; every other policy still renders GPU pods without a CPU limit. The cores are dedicated but not steered to the GPU's NUMA node unless the kubelet runs the alpha KubeletPodResourcesGet gate. Signed-off-by: kwisniewski98 --- docs/reference/cpu-pinning.md | 9 ++++++++- model_manager/core/cli.py | 7 ++++--- model_manager/core/policy.py | 25 ++++++++++++++++++++----- model_manager/core/renderer.py | 4 +++- model_manager/tests/test_gpu.py | 12 +++++++++++- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/docs/reference/cpu-pinning.md b/docs/reference/cpu-pinning.md index 8f3719d8..f795e020 100644 --- a/docs/reference/cpu-pinning.md +++ b/docs/reference/cpu-pinning.md @@ -119,7 +119,14 @@ annotation: the operator's admission webhook matches the serving container (`mai `kserve-container`), reads the span from `--tensor-parallel-size` and adds the annotation itself. model-manager runs no placement pre-flight under this policy; the operator's own capacity check applies. With no `MM_CPU_POLICY`, model-manager picks this policy when the -cluster has `BalloonsClusterConfig/cluster`. The operator is installed and configured from +cluster has `BalloonsClusterConfig/cluster`. + +GPU models (`device: gpu` runtimes) are pinned too, by this policy only: model-manager gives +the pod a CPU limit equal to its request in whole cores, and the operator puts any pod that +requests a device in its `balloon-device` type. Its cores are dedicated but not steered to +the GPU's NUMA node unless the kubelet runs the alpha `KubeletPodResourcesGet` feature gate. + +The operator is installed and configured from the Toolkit Manager repo ([CPU Pinning Operator](https://github.com/intel/toolkit-manager/blob/main/docs/configuration/cpu-pinning-operator.md)). diff --git a/model_manager/core/cli.py b/model_manager/core/cli.py index 23b976d7..5fecdc8c 100644 --- a/model_manager/core/cli.py +++ b/model_manager/core/cli.py @@ -19,8 +19,8 @@ from .config import (MM_DIR, Catalog, Model, Sizing, hf_config, hf_weight_bytes, hub_unreachable, is_uint, mm_path, pick, resolve, resolve_autoscaling, text, truthy) from .download import download_weights -from .policy import (ANN, GpuRuntime, mem_bytes, memory_gate, preflight_gate, resolve_auto_cpu, resolve_policy, - whole_cpus) +from .policy import (ANN, GpuRuntime, mem_bytes, memory_gate, operator_pins_gpu, preflight_gate, resolve_auto_cpu, + resolve_policy, whole_cpus) from .stuck import Watch from .ui import BOLD, CYAN, DIM, GREEN, RESET, YELLOW, abort, fmt_duration, info, ok, warn @@ -572,7 +572,8 @@ def deploy(o: Options, target: str) -> None: info(f" GPUs: {m.gpus} x {m.accel_resource}") if m.node: info(f" Node: {m.node}") - policy = GpuRuntime(catalog.pvc) if m.gpu else resolve_policy(o.cpu_policy, m.node) + policy = (GpuRuntime(catalog.pvc, operator_pins_gpu(o.cpu_policy)) if m.gpu + else resolve_policy(o.cpu_policy, m.node)) info(f" CPU policy: {policy.name}") resolve_auto_cpu(policy, m, tp) policy.prepare(m) diff --git a/model_manager/core/policy.py b/model_manager/core/policy.py index 0a667822..1b199093 100644 --- a/model_manager/core/policy.py +++ b/model_manager/core/policy.py @@ -223,16 +223,22 @@ class CpuPinningOperator(BestEffort): class GpuRuntime(BestEffort): """device: gpu runtimes carry no CPU pinning: balloons and static-CPU alignment are Xeon placement controls, and the accelerator resource limit does the scheduling. The pod is rendered without a CPU - limit (Burstable), so kubelet's static CPU manager does not pin it either. Never selected by --cpu-policy.""" + limit (Burstable), so kubelet's static CPU manager does not pin it either. Never selected by --cpu-policy. + The exception is the CPU Pinning Operator (pin): it puts any device pod in its balloon-device, but only one + whose CPU request equals its limit in whole cores.""" name = "n/a (GPU runtime — no CPU pinning)" label = "GPU" - def __init__(self, pvc: str) -> None: + def __init__(self, pvc: str, pin: bool = False) -> None: """pvc: the model-store claim. rolls: deploy clears it when only spec.replicas changes, so the pods stay. slots: per node, how many new replicas its free GPUs take, once preflight has counted them.""" - self.pvc, self.rolls, self.download_nodes, self.slots = pvc, True, (), None + self.pvc, self.rolls, self.download_nodes, self.slots, self.pin = pvc, True, (), None, pin + if pin: + self.name = "cpu-pinning-operator (GPU: balloon-device)" def annotations(self, m: Model, tp: int) -> tuple[dict, str]: + if self.pin: + return {f"{ANN}/type": CpuPinningOperator.name}, str(whole_cpus(m.cpu)) return {}, m.cpu def preflight(self, m: Model, tp: int) -> list[str]: @@ -435,11 +441,20 @@ def resolve_policy(requested: str, node: str) -> BestEffort: requested = "cpu-pinning-operator" else: requested = "best-effort" - warn("No CPU-pinning mechanism detected (no NRI balloons DaemonSet or CPU Pinning Operator, kubelet cpuManagerPolicy is not " - "static) — deploying best-effort, without CPU pinning.") + warn("No CPU-pinning mechanism detected (no NRI balloons DaemonSet or CPU Pinning Operator, kubelet " + "cpuManagerPolicy is not static) — deploying best-effort, without CPU pinning.") return POLICIES[requested]() +def operator_pins_gpu(requested: str) -> bool: + """Whether GPU pods get a whole-core CPU limit for the CPU Pinning Operator: the policy asked for, else whether + the cluster runs the operator. The other CPU policies never pin a GPU pod.""" + chosen = requested or os.environ.get("MM_CPU_POLICY", "").lower() + if chosen: + return chosen == CpuPinningOperator.name + return k8s.succeeds("get", "balloonsclusterconfigs.cpu-pinning-operator.intel.com", "cluster", "-o", "name") + + def resolve_auto_cpu(policy: BestEffort, m: Model, tp: int) -> None: """Turn `cpu: auto` (models.yaml) into a number, before the policy normalises m.cpu; --cpu overrides it. diff --git a/model_manager/core/renderer.py b/model_manager/core/renderer.py index 36283694..a9c865e3 100644 --- a/model_manager/core/renderer.py +++ b/model_manager/core/renderer.py @@ -296,7 +296,9 @@ def manifest(m: Model, catalog: Catalog, o, annotations: dict, cpu: str, cli_arg gateway, gateway_ns = gateway_ref() # GPU pods get no CPU limit, which makes them Burstable: kubelet's static CPU manager then never # gives them exclusive cores (full-pcpus-only would refuse an odd count with SMTAlignmentError). - cpu_limit = "" if m.gpu else f'\n cpu: "{cpu}"' + # Under the CPU Pinning Operator they keep it: its webhook pins only requests == limits. + pinned = annotations.get("cpu-policy.model-manager.io/type") == "cpu-pinning-operator" + cpu_limit = "" if m.gpu and not pinned else f'\n cpu: "{cpu}"' return platform.adapt_llmisvc(render( template("llm-inference-service.yaml"), **common, **_engine(m), IMAGE=m.image, SIZING_ANNOTATIONS="".join(["\n annotations:"] * bool(m.sizing) diff --git a/model_manager/tests/test_gpu.py b/model_manager/tests/test_gpu.py index 81b97467..8f274bd3 100644 --- a/model_manager/tests/test_gpu.py +++ b/model_manager/tests/test_gpu.py @@ -22,7 +22,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from core import cli, config, download, k8s, policy, renderer # noqa: E402 from core.config import Catalog, Model # noqa: E402 -from test_parity import (BE, DOWNLOAD, GOLDEN, HF_EXCLUDE_DEV, MM, NO_LITELLM_URL, NRI, POOL, # noqa: E402 +from test_parity import (BE, DOWNLOAD, GOLDEN, HF_EXCLUDE_DEV, MM, NO_LITELLM_URL, NRI, POOL, ROOMY, # noqa: E402 _ready, case, run) from test_units import _quiet_deploy # noqa: E402 @@ -548,3 +548,13 @@ def test_nemotron_entries(monkeypatch, name, gpus): for p in GPU_CASES: (GOLDEN / f"{p.id}.txt").write_text(run(legacy, p.values[0], Path(d))) print(f"wrote {p.id}") + + +@pytest.mark.parametrize("cpu_policy, pinned", [("cpu-pinning-operator", True), ("nri-balloons", False)]) +def test_only_the_cpu_pinning_operator_gives_a_gpu_pod_a_cpu_limit(cpu_policy, pinned, tmp_path): + c = {"args": ("deploy", "qwen3-0-6b-cuda", "--dry-run"), "env": {"MM_CPU_POLICY": cpu_policy}, + "k8s": ROOMY, "catalog": None} + out = run(MM / "model-manager", c, tmp_path) + limits = re.search(r"^ limits:\n((?: .*\n)+)", out, re.M).group(1) + assert ('cpu: "' in limits) is pinned + assert ("cpu-policy.model-manager.io/type: cpu-pinning-operator" in out) is pinned