Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
23 changes: 21 additions & 2 deletions docs/reference/cpu-pinning.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<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 |

Expand Down Expand Up @@ -111,6 +112,24 @@ 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`.

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)).

## kubelet static CPU manager

Under `kubelet-static`, model pods are rendered as **Guaranteed QoS** — integer `cpu`
Expand Down
16 changes: 11 additions & 5 deletions model_manager/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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} <p> CPU pinning: nri-balloons | kubelet-static | best-effort
{GREEN}--cpu-policy{RESET} <p> CPU pinning: nri-balloons | cpu-pinning-operator |
kubelet-static | best-effort
(default: MM_CPU_POLICY, else auto-detected)
{GREEN}--category{RESET} <cat> Override category: llm | embed | rerank | vlm
{GREEN}--routing{RESET} <mode> Override routing: epp | aigateway | direct
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -567,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)
Expand Down
38 changes: 31 additions & 7 deletions model_manager/core/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,32 @@ 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
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]:
Expand Down Expand Up @@ -296,7 +309,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]:
Expand Down Expand Up @@ -407,7 +420,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 ""
Expand All @@ -424,13 +437,24 @@ 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 "
"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.

Expand Down
4 changes: 3 additions & 1 deletion model_manager/core/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion model_manager/tests/test_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
26 changes: 21 additions & 5 deletions model_manager/tests/test_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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"^<MM>/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",
Expand All @@ -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"),
Expand All @@ -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]),
Expand Down
16 changes: 16 additions & 0 deletions model_manager/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Loading