Skip to content
Merged
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
10 changes: 10 additions & 0 deletions docs/benchmarks/benchmark-comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ implementation and version, framework and runtime versions, device model and
allocator profile. `python` selects the executable in the launch command.
Report generation verifies the campaign again to detect changes after collection.

Tasks can require delivery of a package knowledge card in the on arm. The
task manifest's `knowledge_delivery` declares a `query`, `scenario`, and
package `ref`. Preparing the comparison freezes those fields along with the
card revision, body hash, and context byte budget. The on dispatch prompt
provides the corresponding `session knowledge` command. Collection checks for
the actual assembled text and card body at that budget in the verified inputs
to the first search round. Collection retains the evidence for a missing body,
late capture, or budget mismatch and excludes the affected pair. The delivery
requirement applies to plans that declare it.

Each round can supply `--strategy <description>` and repeated
`--knowledge-ref <delivered-context-path>` in addition to `--hypothesis`.
Harness accepts citations only to contexts already delivered in that campaign.
Expand Down
2 changes: 2 additions & 0 deletions src/inferrsi/apps/cli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ def _optimization_actions(stages, *, project=False):
stage.add_argument("--page", type=int, default=1)
if name == "knowledge":
stage.add_argument("--query", required=True)
if not project:
stage.add_argument("--scenario", help="Filter package records by workload scenario")
stage.add_argument(
"--relevance-method", metavar="find-lexical-v1",
help="Find is the default and only ranking method",
Expand Down
108 changes: 104 additions & 4 deletions src/inferrsi/apps/workflows/benchmark_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
from inferrsi.harness.artifact_primitives import digest, file_lock, sha256
from inferrsi.harness.atomic_json import atomic_write_json
from inferrsi.harness.optimization_session import _runtime_identity
from inferrsi.harness.records.knowledge_capture import verify_capture
from inferrsi.harness.task_protocol import run as protocol_operation
from inferrsi.knowledge.catalog import SCENARIO_ALIASES
from inferrsi.knowledge.context_projection import assemble_context_text
from inferrsi.knowledge.knowledge_operations import KnowledgeReader

from ..delivery import project
from ..delivery.benchmark_usage import terminal_token_usage, update_metrics
Expand All @@ -56,6 +60,7 @@
CONFIG_NAME = Path(".inferrsi/benchmarks.json")
OBSERVED_FIELDS = ("model", "effort", "environment_id", "environment_fingerprint")
SHARED_SESSION = "native_session_bound_to_multiple_attempts"
KNOWLEDGE_CONTEXT_BYTES = 64 * 1024


def _io_path(path):
Expand Down Expand Up @@ -174,14 +179,39 @@ def ignored(directory, names):
shutil.copytree(source, destination, ignore=ignored)


def _prefix(config, resources):
manifest = _object(resources / "task.json")
def _prefix(config, manifest):
devices = manifest.get("devices", manifest.get("world_size", 2))
if type(devices) is not int or devices < 1:
raise ValueError("Task must declare its positive device count")
return config["evaluation_prefix"].replace("{devices}", str(devices))


def _freeze_knowledge_delivery(manifest, task):
if "knowledge_delivery" not in manifest:
return None
requirement = manifest["knowledge_delivery"]
if (not isinstance(requirement, dict) or requirement.keys() != {"query", "scenario", "ref"}
or any(not isinstance(value, str) or not value.strip()
for value in requirement.values())
or not requirement["ref"].startswith("package:")):
raise ValueError(f"{task}: knowledge_delivery requires a query, scenario and package ref")
card = KnowledgeReader().read(requirement["ref"]).view()
scenario = SCENARIO_ALIASES.get(requirement["scenario"], requirement["scenario"])
card_scenario = card.get("scenario")
if (card["kind"] != "knowledge" or card["entrypoint"] != "record.json"
or SCENARIO_ALIASES.get(card_scenario, card_scenario) != scenario):
raise ValueError(f"{task}: expected a package knowledge card for the declared scenario")
return {**requirement, "scenario": scenario, "revision": card["revision"],
"body_sha256": card["resources"]["record.json"],
"context_bytes": KNOWLEDGE_CONTEXT_BYTES}


def _knowledge_requirement(plan, trial):
if trial["condition"] == "on":
return plan["task_settings"][trial["task"]].get("knowledge_delivery")
return None


def prepare(args):
config, sources = resolve_config(args)
if not config["environment_id"]:
Expand All @@ -206,11 +236,15 @@ def prepare(args):
task_settings = {}
for name in config["tasks"]:
resource = Path(str(task_resources(name)))
manifest = _object(resource / "task.json")
settings = protocol_operation(resource, sha256(resource / "optimization.py"),
"validate_arguments",
arguments=shlex.split(config["task_arguments"][name]))
task_settings[name] = {"settings": settings, "files": _manifest(resource),
"evaluation_prefix": _prefix(config, resource)}
"evaluation_prefix": _prefix(config, manifest)}
requirement = _freeze_knowledge_delivery(manifest, name)
if requirement is not None:
task_settings[name]["knowledge_delivery"] = requirement
root.parent.mkdir(parents=True, exist_ok=True)
with TemporaryDirectory(prefix=".compare-", dir=_io_path(root.parent)) as temporary:
staging = Path(temporary) / "experiment"
Expand Down Expand Up @@ -451,6 +485,16 @@ def _prompt(root, plan, trial, workspace):
"observed measurements with benchmarks session diagnose --session <campaign> "
"--bottleneck <description> --evidence <UTF-8-measurement-summary>. "
)
retrieval = ""
requirement = _knowledge_requirement(plan, trial)
if requirement is not None:
knowledge = [*start[:6], "knowledge", "--session", str(campaign),
"--query", requirement["query"], "--scenario", requirement["scenario"],
"--context-bytes", str(requirement["context_bytes"])]
retrieval = (
"After diagnosis, run the frozen knowledge request before the first round. "
f"Knowledge argv (a JSON array, execute without a shell): {json.dumps(knowledge)}\n"
)
return (
f"Run complete RSI optimization: {trial['task']}, condition {trial['condition']}.\n"
f"Work only in {workspace}. Set PYTHONPATH to {runtime}; disable bytecode. "
Expand All @@ -473,7 +517,7 @@ def _prompt(root, plan, trial, workspace):
"For remote execution, copy this exact runtime to the prepared target. Use a private "
"campaign directory there; return its entire unchanged tree to workspace/campaign above. "
"Preserve bytes and relative paths. Exclude other trials and runtimes.\n"
f"Read frozen TASK.md. {diagnosis}"
f"Read frozen TASK.md. {diagnosis}{retrieval}"
"Analyze feedback and choose a justified optimization each round. "
"Submit candidate, --strategy and --hypothesis; cite delivered --knowledge-ref paths when "
"used and retain failures. When knowledge is enabled, use session knowledge for a "
Expand Down Expand Up @@ -611,6 +655,44 @@ def _native_window(host, payload):
"source": "caller_exported_terminal_native_receipt"}, None


def _card_delivery(snapshot, campaign_id, references, requirement):
"""Match the frozen request and card body against verified first-round inputs."""
budget_problem = None
for reference in references:
if reference.get("kind") != "delivered_context":
continue
path = reference["path"]
source = snapshot.file(path, "knowledge", reference["sha256"], document=True)
if not snapshot.verified([source]):
continue
capture, _ = verify_capture(snapshot.documents[path])
if (capture is None or capture["campaign_id"] != campaign_id
or capture["request"].get("relevance") != requirement["query"]
or capture["request"].get("scenario") != requirement["scenario"]):
Comment thread
Dong1017 marked this conversation as resolved.
Resolved
continue
budget = capture.get("context_budget")
if (not isinstance(budget, dict) or type(budget.get("max_bytes")) is not int
or budget["max_bytes"] != requirement["context_bytes"]
or capture["request"].get("context_bytes") != requirement["context_bytes"]):
budget_problem = budget_problem or "context budget differs from the frozen plan"
continue
if any(omission.get("ref") == requirement["ref"]
and omission.get("reason") == "context_limit"
for omission in capture["context_omissions"]):
budget_problem = "context budget exceeded"
matching_body = any(
resource["path"] == "record.json" and resource["sha256"] == requirement["body_sha256"]
for context in capture["contexts"]
if (context["ref"] == requirement["ref"]
and context["revision"] == requirement["revision"])
for resource in context["resources"]
)
if (matching_body
and capture["assembled_text"] == assemble_context_text(capture["contexts"])):
return reference, None
return None, budget_problem


def _trial_result(root, plan, trial, host, payload, *, workspace, host_error=None):
result = {"id": trial["id"], "task": trial["task"], "repeat": trial["repeat"],
"condition": trial["condition"], "status": "blocked", "eligible": False,
Expand Down Expand Up @@ -691,6 +773,24 @@ def _trial_result(root, plan, trial, host, payload, *, workspace, host_error=Non
result["knowledge_deliveries"] = control["contexts"]
if trial["condition"] == "off" and control["contexts"]:
result["gaps"].append("Knowledge was delivered in the off condition")
requirement = _knowledge_requirement(plan, trial)
if requirement is not None:
# The verified observation pins the inputs snapshotted at round start.
first_inputs = []
if (control["rounds"] and delivery["rounds"]
and delivery["rounds"][0].get("record_verified")):
first_inputs = control["rounds"][0]["contexts"]
matched, budget_problem = _card_delivery(
snapshot, delivery["campaign"]["id"], first_inputs, requirement)
result["knowledge_delivery"] = {
"ref": requirement["ref"], "revision": requirement["revision"], "capture": matched,
}
if matched is None:
gap = ("Required knowledge card body was not delivered before the first round: "
f"{requirement['ref']}")
if budget_problem:
gap += f" ({budget_problem})"
result["gaps"].append(gap)
result["usage"].update(delivery["usage"])
result["benchmark_metrics"] = delivery.get("benchmark_metrics")
child_metrics_policy = campaign_plan.get("report_metadata", {}).get("benchmark_metrics")
Expand Down
5 changes: 5 additions & 0 deletions src/inferrsi/benchmark/tasks/qwen21-denoise-npu/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"backend": "ascend",
"devices": 1,
"dtype": "bfloat16",
"knowledge_delivery": {
"query": "Qwen-Image-2.1 denoise NPU eager",
"scenario": "diffusion.image_generation",
"ref": "package:vllm_omni.ascend.diffusion.qwen_image_21_eager_t2i"
},
"output": "all post-Euler latent states, shape [steps, batch, height*width, channels]",
"tolerance": {"rtol": 0.03, "atol": 0.03, "max_nrmse": 0.01},
"measurement": {
Expand Down
1 change: 1 addition & 0 deletions src/inferrsi/harness/optimization_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def session_command(args, *, task_source: Path | None = None, knowledge_reader=N
query="",
relevance=args.query,
relevance_method=args.relevance_method,
scenario=getattr(args, "scenario", None),
context_bytes=args.context_bytes,
limit=args.limit,
)
Expand Down
12 changes: 12 additions & 0 deletions tests/apps/test_cli_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
}


def test_managed_knowledge_scenario_is_benchmark_only(capsys):
cli = parser()
knowledge = ["knowledge", "--session", "run", "--query", "denoise", "--context-bytes", "65536"]
scenario = ["--scenario", "diffusion.image_generation"]
assert cli.parse_args(["benchmarks", "session", *knowledge, *scenario]).scenario == scenario[1]
cli.parse_args(["campaign", *knowledge])
with pytest.raises(SystemExit) as error:
cli.parse_args(["campaign", *knowledge, *scenario])
assert error.value.code == 2
assert "unrecognized arguments: --scenario" in capsys.readouterr().err


class CatalogTests(unittest.TestCase):
def test_source_grounded_imports_and_backend_boundaries(self):
records = knowledge_records()
Expand Down
Loading
Loading