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
16 changes: 8 additions & 8 deletions src/tests/e2e/benchmarks/chatqna/pysweep/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ SPDX-License-Identifier: Apache-2.0

# pysweep — Declarative Configuration Sweeps for ChatQNA Benchmarks

> **Status.** This document covers both config planes. On the Runtime-API plane
> `llms.max_new_tokens` is implemented; `retriever.k` and `reranker.top_n` are
> designed and land next. The K8s-spec plane's one designed knob, `llms.model`
> (`LlmModel`: model-manager + `gmc-config`), is **not implemented yet**; the
> sections on it describe the design it will follow. Until then the runner only *reads* the served model,
> **Status.** This document covers both config planes. The Runtime-API plane
> (`llms.max_new_tokens`, `retriever.k`, `reranker.top_n`) is implemented. The
> K8s-spec plane's one designed knob, `llms.model` (`LlmModel`: model-manager +
> `gmc-config`), is **not implemented yet**; the sections on it describe the
> design it will follow. Until then the runner only *reads* the served model,
> to derive the benchmark's tokenizer (`cluster/served_model.py`).

## Problem
Expand Down Expand Up @@ -486,8 +486,8 @@ on the next pod start. This is a likely third plane, deferred for now.

| Existing | Plane | Property |
|---|---|---|
| `prepare_change_reranker.sh` (`top_n`) | Runtime API | `RerankerTopN` — **designed, not implemented** (`reranker.top_n`) |
| `prepare_change_retriever.sh` (`k`) | Runtime API | `RetrieverK` — **designed, not implemented** (`retriever.k`) |
| `prepare_change_reranker.sh` (`top_n`) | Runtime API | `RerankerTopN` — **implemented** (`reranker.top_n`) |
| `prepare_change_retriever.sh` (`k`) | Runtime API | `RetrieverK` — **implemented** (`retriever.k`) |
| `prepare_change_max_tokens.sh` (`max_new_tokens`) | Runtime API | `MaxNewTokens` — **implemented** (`llms.max_new_tokens`) |
| `switch_llm_model.sh` (the served model) | K8s spec | `LlmModel` — **designed, not implemented** (`llms.model`), via `model-manager` + `gmc-config` |
| `run.bash` model-server replicas / CPU / memory reads | K8s spec | Not ported: these are now per-model facts in model-manager's catalog, so a sweep dimension over them would fight the tool that owns them. Sweep `llms.model` instead. |
Expand All @@ -509,6 +509,6 @@ on the next pod start. This is a likely third plane, deferred for now.
behind the Envoy AI gateway. What lives in the pipeline namespace (`chatqna`)
is the `llm-usvc` Deployment that *calls* it, and that is where the observed
model is read from.
- [ ] Port `RetrieverK` (`prepare_change_retriever.sh`) and `RerankerTopN`
- [x] Port `RetrieverK` (`prepare_change_retriever.sh`) and `RerankerTopN`
(`prepare_change_reranker.sh`), the remaining runtime-API knobs from the
original scripts.
8 changes: 7 additions & 1 deletion src/tests/e2e/benchmarks/chatqna/pysweep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ environment gotchas.
| `results.py` | Run records, `results.json` and the summary CSV. |
| `client_args.py` | Adapter mirroring `benchmark.py`'s CLI options as sweep knobs. Not properties — no plane, nothing to apply or read back; see below. |
| `pre_bench/` | Done once before the first run: `run_pre_bench()` in `__init__.py`, and `seed.py`, which loads the vector DB through EDP up to `pre_bench.edp.vector_db.num_vectors`. |
| `properties/` | Deployment knobs: `base.py` (the `Property` interface and `Plane` enum) and one module per knob, e.g. `max_tokens.py` (`MaxNewTokens`, LLM `max_new_tokens`, Runtime-API plane). |
| `properties/` | Deployment knobs: `base.py` (the `Property` interface and `Plane` enum) and one module per knob: `max_tokens.py` (`MaxNewTokens`, LLM `max_new_tokens`), `retriever_k.py` (`RetrieverK`, the retriever's `k`) and `reranker_top_n.py` (`RerankerTopN`, how many reranked documents reach the prompt), all on the Runtime-API plane. |
| `cluster/auth.py` | `KubernetesAccess` (side-effect-free RBAC preflight via `SelfSubjectAccessReview`), `load_build_config()` (the installed environment's config), `keycloak_helper()` (the maintained `KeycloakHelper`, for user tokens) and `client_token_lifespan()` (a sweep-long access-token lifespan for the UI client, restored afterwards). |
| `cluster/fingerprint.py` | `system_fingerprint` client. `HelperFingerprintClient` adapts the suite's `FingerprintApiHelper`; `PortForwardTransport` / `IngressTransport` cover deployments the helper can't reach. |
| `cluster/served_model.py` | `ServedModel`: reads the model the pipeline is **observed** to generate with, out of the running `llm-usvc` pods. Not a knob — the runner uses it to pick the benchmark's tokenizer. |
Expand Down Expand Up @@ -61,6 +61,12 @@ A sweep is declared in YAML and validated by `config.load_config()`:
llms: # DEPLOYMENT knobs: optional, outer loop
max_new_tokens: [128, 256, 512] # a list -> one product dimension

retriever:
k: 10 # documents fetched per query

reranker:
top_n: 7 # of those, how many reach the prompt

client: # CLIENT knobs: required, inner loop
question_file: ../questions-short.csv # relative to pysweep_bench.py, not the CWD
concurrency: [1, 16, 128] # a list -> the innermost dimension
Expand Down
16 changes: 16 additions & 0 deletions src/tests/e2e/benchmarks/chatqna/pysweep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
ClientArg,
)
from .properties.max_tokens import MaxNewTokens
from .properties.reranker_top_n import RerankerTopN
from .properties.retriever_k import RetrieverK

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -72,6 +74,10 @@ class ClientSetting:


MaxTokensValue = PositiveInt | list[PositiveInt]
# k=0 retrieves nothing; PositiveInt is also the app's own type.
RetrieverKValue = PositiveInt | list[PositiveInt]
# top_n=0 leaves the prompt without context; PositiveInt is also the app's own type.
RerankerTopNValue = PositiveInt | list[PositiveInt]

# Tighter than benchmark.py's argparse, which accepts -c 0, -e -1 and -w -1.
CountValue = PositiveInt | list[PositiveInt]
Expand Down Expand Up @@ -107,6 +113,14 @@ class LlmsConfig(_StrictModel):
max_new_tokens: Annotated[MaxTokensValue | None, PropertyBinding(MaxNewTokens)] = None


class RetrieverConfig(_StrictModel):
k: Annotated[RetrieverKValue | None, PropertyBinding(RetrieverK)] = None


class RerankerConfig(_StrictModel):
top_n: Annotated[RerankerTopNValue | None, PropertyBinding(RerankerTopN)] = None


class ClientConfig(_StrictModel):
"""Load-generator knobs mirroring ``benchmark.py``; ``-m`` is derived, not declared."""

Expand Down Expand Up @@ -134,6 +148,8 @@ class RunConfig(_StrictModel):
class SweepConfig(_StrictModel):
pre_bench: PreBenchConfig | None = None
llms: LlmsConfig | None = None
retriever: RetrieverConfig | None = None
reranker: RerankerConfig | None = None
client: ClientConfig

def iter_settings(self) -> Iterator[tuple[str, type[Property], list[Any]]]:
Expand Down
2 changes: 2 additions & 0 deletions src/tests/e2e/benchmarks/chatqna/pysweep/configs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ combination.
| Key | Meaning |
|---|---|
| `llms.max_new_tokens` | Tokens the LLM may generate per request. |
| `retriever.k` | Documents the retriever fetches per query. |
| `reranker.top_n` | Of those, how many survive reranking and reach the prompt (the LLM's input length). Values above the live `k` all give the same prompt. |

**Client knobs** are `benchmark.py`'s options. All are required, so no run
silently falls back to the tool's defaults. They are the inner loop: each value
Expand Down
6 changes: 6 additions & 0 deletions src/tests/e2e/benchmarks/chatqna/pysweep/configs/sweep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pre_bench:
llms:
max_new_tokens: [128, 256]

retriever:
k: 5

reranker:
top_n: 1

client:
question_file: ../questions-pubmed.csv
concurrency: [1, 16, 128]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

from .max_tokens import MaxNewTokens
from .reranker_top_n import RerankerTopN
from .retriever_k import RetrieverK

__all__ = ["MaxNewTokens"]
__all__ = ["MaxNewTokens", "RerankerTopN", "RetrieverK"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import logging

from .base import Plane, Property, PropertyReadError
from ..cluster.fingerprint import FingerprintClient

logger = logging.getLogger(__name__)

COMPONENT = "reranker"
PARAMETER = "top_n"


class RerankerTopN(Property):
"""Number of reranked documents appended to the prompt."""

plane = Plane.RUNTIME_API

def __init__(self, client: FingerprintClient):
self.client = client

def read(self) -> int:
"""Return the observed ``top_n`` from the live fingerprint API."""
values = self.client.read_values(COMPONENT)
if PARAMETER not in values:
raise PropertyReadError(
f"'{PARAMETER}' is absent from the fingerprint '{COMPONENT}' "
f"arguments; got keys: {sorted(values)}"
)
raw = values[PARAMETER]
try:
return int(raw)
except (TypeError, ValueError) as exc:
raise PropertyReadError(
f"'{PARAMETER}' is not an integer (got {raw!r})."
) from exc

def is_satisfied(self, desired: int) -> bool:
return self.read() == int(desired)

def apply(self, desired: int) -> None:
"""Set the reranker's ``top_n`` to ``desired`` (idempotent)."""
desired = int(desired)
if self.is_satisfied(desired):
logger.debug("reranker top_n already %s; skipping change_arguments.", desired)
return
logger.info("Setting %s.%s = %s via change_arguments.", COMPONENT, PARAMETER, desired)
self.client.change_arguments(
[{"name": COMPONENT, "data": {PARAMETER: desired}}]
)

# change_arguments is synchronous, so the inherited no-op wait_until_ready suffices.
53 changes: 53 additions & 0 deletions src/tests/e2e/benchmarks/chatqna/pysweep/properties/retriever_k.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import logging

from .base import Plane, Property, PropertyReadError
from ..cluster.fingerprint import FingerprintClient

logger = logging.getLogger(__name__)

COMPONENT = "retriever"
PARAMETER = "k"


class RetrieverK(Property):
"""Number of documents the retriever fetches per query."""

plane = Plane.RUNTIME_API

def __init__(self, client: FingerprintClient):
self.client = client

def read(self) -> int:
"""Return the observed ``k`` from the live fingerprint API."""
values = self.client.read_values(COMPONENT)
if PARAMETER not in values:
raise PropertyReadError(
f"'{PARAMETER}' is absent from the fingerprint '{COMPONENT}' "
f"arguments; got keys: {sorted(values)}"
)
raw = values[PARAMETER]
try:
return int(raw)
except (TypeError, ValueError) as exc:
raise PropertyReadError(
f"'{PARAMETER}' is not an integer (got {raw!r})."
) from exc

def is_satisfied(self, desired: int) -> bool:
return self.read() == int(desired)

def apply(self, desired: int) -> None:
"""Set the retriever's ``k`` to ``desired`` (idempotent)."""
desired = int(desired)
if self.is_satisfied(desired):
logger.debug("retriever k already %s; skipping change_arguments.", desired)
return
logger.info("Setting %s.%s = %s via change_arguments.", COMPONENT, PARAMETER, desired)
self.client.change_arguments(
[{"name": COMPONENT, "data": {PARAMETER: desired}}]
)

# change_arguments is synchronous, so the inherited no-op wait_until_ready suffices.
129 changes: 129 additions & 0 deletions src/tests/e2e/validation/pysweep/test_config_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
load_run_config,
)
from tests.e2e.benchmarks.chatqna.pysweep.properties.max_tokens import MaxNewTokens
from tests.e2e.benchmarks.chatqna.pysweep.properties.reranker_top_n import RerankerTopN
from tests.e2e.benchmarks.chatqna.pysweep.properties.retriever_k import RetrieverK

CLIENT = {
"question_file": "questions-short.csv",
Expand Down Expand Up @@ -182,6 +184,132 @@ def test_max_new_tokens_is_runtime_api_plane():
assert MaxNewTokens.plane == Plane.RUNTIME_API


@allure.feature("pysweep")
def test_retriever_k_binds_to_retriever_k_property():
cfg = load_config(_sweep(retriever={"k": 5}))
(path, property_cls, values) = next(iter(cfg.iter_settings()))
assert path == "retriever.k"
assert property_cls is RetrieverK
assert values == [5]


@allure.feature("pysweep")
def test_retriever_k_list_expands_to_product():
cfg = load_config(_sweep(retriever={"k": [1, 5, 10]}))
combos = cfg.deployment_combinations()
assert [c[0].value for c in combos] == [1, 5, 10]
assert all(c[0].property_cls is RetrieverK for c in combos)


@allure.feature("pysweep")
def test_retriever_section_is_optional():
assert list(load_config(_sweep()).iter_settings()) == []
assert list(load_config(_sweep(retriever={})).iter_settings()) == []


@allure.feature("pysweep")
@pytest.mark.parametrize("bad", [0, -1])
def test_non_positive_retriever_k_is_rejected(bad):
with pytest.raises(ConfigError):
load_config(_sweep(retriever={"k": bad}))


@allure.feature("pysweep")
def test_unknown_retriever_key_is_rejected():
with pytest.raises(ConfigError):
load_config(_sweep(retriever={"kk": 5}))


@allure.feature("pysweep")
def test_retriever_k_is_runtime_api_plane():
assert RetrieverK.plane == Plane.RUNTIME_API


@allure.feature("pysweep")
def test_retriever_k_appears_in_knob_paths():
cfg = load_config(_sweep(retriever={"k": [1, 5]}))
assert "retriever.k" in cfg.knob_paths()
assert "retriever.k" in cfg.varying_paths()


@allure.feature("pysweep")
def test_reranker_top_n_binds_to_reranker_top_n_property():
cfg = load_config(_sweep(reranker={"top_n": 3}))
(path, property_cls, values) = next(iter(cfg.iter_settings()))
assert path == "reranker.top_n"
assert property_cls is RerankerTopN
assert values == [3]


@allure.feature("pysweep")
def test_reranker_top_n_list_expands_to_product():
cfg = load_config(_sweep(reranker={"top_n": [2, 7, 15]}))
combos = cfg.deployment_combinations()
assert [c[0].value for c in combos] == [2, 7, 15]
assert all(c[0].property_cls is RerankerTopN for c in combos)


@allure.feature("pysweep")
def test_reranker_section_is_optional():
assert list(load_config(_sweep()).iter_settings()) == []
assert list(load_config(_sweep(reranker={})).iter_settings()) == []


@allure.feature("pysweep")
@pytest.mark.parametrize("bad", [0, -1])
def test_non_positive_reranker_top_n_is_rejected(bad):
with pytest.raises(ConfigError):
load_config(_sweep(reranker={"top_n": bad}))


@allure.feature("pysweep")
def test_unknown_reranker_key_is_rejected():
with pytest.raises(ConfigError):
load_config(_sweep(reranker={"topn": 3}))


@allure.feature("pysweep")
def test_reranker_top_n_is_not_accepted_under_retriever():
"""Each section rejects the other component's knob."""
with pytest.raises(ConfigError):
load_config(_sweep(retriever={"top_n": 3}))
with pytest.raises(ConfigError):
load_config(_sweep(reranker={"k": 5}))


@allure.feature("pysweep")
def test_reranker_top_n_is_runtime_api_plane():
assert RerankerTopN.plane == Plane.RUNTIME_API


@allure.feature("pysweep")
def test_reranker_top_n_and_retriever_k_sweep_together():
"""Two runtime-API knobs are ordered by dotted path."""
cfg = load_config(_sweep(reranker={"top_n": [2, 7]}, retriever={"k": [4, 10]}))
combos = cfg.deployment_combinations()

assert [tuple(s.path for s in c) for c in combos] == [
("reranker.top_n", "retriever.k")
] * 4
assert [tuple(s.value for s in c) for c in combos] == [
(2, 4), (2, 10), (7, 4), (7, 10),
]


@allure.feature("pysweep")
def test_reranker_top_n_appears_in_knob_paths():
cfg = load_config(_sweep(reranker={"top_n": [2, 7]}))
assert "reranker.top_n" in cfg.knob_paths()
assert "reranker.top_n" in cfg.varying_paths()


@allure.feature("pysweep")
def test_constant_reranker_top_n_is_a_column_but_not_a_dimension():
cfg = load_config(_sweep(reranker={"top_n": 3}))
assert "reranker.top_n" in cfg.knob_paths()
assert "reranker.top_n" not in cfg.varying_paths()


@allure.feature("pysweep")
@pytest.mark.parametrize("missing", sorted(CLIENT))
def test_every_scenario_client_knob_is_required(missing):
Expand Down Expand Up @@ -309,6 +437,7 @@ def test_varying_paths_reports_only_multi_valued_knobs():
{
"client": {**CLIENT, "concurrency": [1, 16]},
"llms": {"max_new_tokens": [128, 256]},
"retriever": {"k": 5},
}
)
assert cfg.varying_paths() == {"client.concurrency", "llms.max_new_tokens"}
Expand Down
Loading