From b3aae7c6d2cb491d356ca741b8795559ef688221 Mon Sep 17 00:00:00 2001 From: Dong1017 <55723162+Dong1017@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:19:30 +0800 Subject: [PATCH 1/3] Index Searchspace Matrix coordinate pairs Agent-assisted-by: Codex / unknown [effort=unknown] (author) Signed-off-by: Dong1017 <55723162+Dong1017@users.noreply.github.com> --- docs/contributing.md | 9 + docs/searchspace-index.json | 102 ++++++++++ src/inferrsi/knowledge/searchspace_index.py | 143 ++++++++++++++ tests/test_searchspace_index.py | 202 ++++++++++++++++++++ tools/build_skill_coverage.py | 147 ++++++++++---- 5 files changed, 570 insertions(+), 33 deletions(-) create mode 100644 docs/searchspace-index.json create mode 100644 src/inferrsi/knowledge/searchspace_index.py create mode 100644 tests/test_searchspace_index.py diff --git a/docs/contributing.md b/docs/contributing.md index 1fee29f23..8b4f5fec9 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -48,6 +48,15 @@ cleanup and adjudication. See [extension contracts](architecture.md#where-to-ext For a finding, edit one [record](../src/inferrsi/knowledge/data/skill_library/records/README.md). For a procedure, edit its registered owner. Commit changed skill sources, then regenerate the two build inputs with `python tools/build_skill_index.py --source-revision `. Verify with the same command plus `--check`. The catalog constructs schema-1 views when requested. See the [knowledge contribution workflow](knowledge-contribution-workflow.md). +Regenerate the checkout [SearchSpace coordinate index](searchspace-index.json) +after changing the SearchSpace Matrix, Skill registry or Skill metadata source +files with `python tools/build_skill_coverage.py --searchspace-index`. Add +`--check` to verify without writing. The index records resource and lifecycle +stage pairs from the numbered matrix's Candidate Skills column. Supplementary, +unknown, explicitly excluded and conflicting Skills have no matchable pairs. +The Python reader `load_searchspace_index(checkout)` verifies the source +digests before returning entries qualified by Skill root, id and path. + Protected changes also require a current-head [knowledge authorship declaration](knowledge-model-policy.md). Every material AI author must use an approved model at `xhigh` or `max`; human-only work is declared diff --git a/docs/searchspace-index.json b/docs/searchspace-index.json new file mode 100644 index 000000000..8810a3d3a --- /dev/null +++ b/docs/searchspace-index.json @@ -0,0 +1,102 @@ +{ + "schema_version": 1, + "source": { + "matrix_path": "docs/searchspace-matrix.md", + "catalog_path": "src/inferrsi/knowledge/data/skill_library/skill-index.json", + "skill_root": "src/inferrsi/knowledge/data/skill_library", + "matrix_sha256": "2d90d24c94babcbb9e3f9da9b7138d7896459af03e39280eb8d97540fdf911a0", + "catalog_sha256": "d243e2ae44c7badc8e68788153de35fe6ac31de618b7499fef6339eadf396871", + "metadata_sha256": "7e3efbdd366d493e8db5fa06c87a45ecbdb4b51bdb55b3dc30679afe697733e5" + }, + "skills": { + "ascend-aclgraph-capture-replay": {"path": "systems/platforms/ascend/ascend-aclgraph-capture-replay/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"]]}, + "ascend-device-health": {"path": "systems/platforms/ascend/ascend-device-health/SKILL.md", "state": "covered", "coordinates": [["Network", "Diagnose"], ["OS", "Configure"], ["OS", "Diagnose"], ["OS", "Observe"], ["OS", "Profile"], ["OS", "Verify"]]}, + "ascend-distributed-parallel": {"path": "systems/platforms/ascend/ascend-distributed-parallel/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Network", "Configure"], ["Network", "Diagnose"], ["Network", "Observe"], ["Network", "Optimize"], ["Network", "Verify"]]}, + "ascend-graph-mode": {"path": "systems/platforms/ascend/ascend-graph-mode/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Verify"], ["SSD", "Diagnose"]]}, + "ascend-model-adaptation": {"path": "systems/platforms/ascend/ascend-model-adaptation/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["SSD", "Configure"], ["SSD", "Diagnose"]]}, + "ascend-operator-profiling": {"path": "systems/platforms/ascend/ascend-operator-profiling/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Observe"], ["Accelerator", "Profile"], ["OS", "Observe"], ["OS", "Profile"]]}, + "ascend-operator-tuning": {"path": "systems/platforms/ascend/ascend-operator-tuning/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Optimize"]]}, + "ascend-optimization-casebook": {"path": "casebooks/ascend/ascend-optimization-casebook/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Optimize"], ["Accelerator", "Verify"]]}, + "ascend-performance-analysis": {"path": "systems/platforms/ascend/ascend-performance-analysis/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Observe"], ["Accelerator", "Profile"], ["Accelerator", "Verify"], ["Network", "Diagnose"], ["Network", "Observe"], ["Network", "Profile"], ["Network", "Verify"], ["OS", "Diagnose"]]}, + "ascend-video-diffusion-optimization": {"path": "systems/platforms/ascend/ascend-video-diffusion-optimization/SKILL.md", "state": "supplementary", "coordinates": []}, + "ascendc-tiling-design": {"path": "systems/platforms/ascend/ascendc-tiling-design/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Optimize"]]}, + "assess-serving-preemption": {"path": "playbooks/planning/assess-serving-preemption/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"], ["RAM/Host", "Configure"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Optimize"], ["RAM/Host", "Verify"]]}, + "assess-split-backward-schedule": {"path": "playbooks/planning/assess-split-backward-schedule/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"]]}, + "audit-afd-p2p-exchanges": {"path": "systems/engines/afd-plugin/audit-afd-p2p-exchanges/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Verify"]]}, + "audit-fixed-workload-claim": {"path": "playbooks/measurement/audit-fixed-workload-claim/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "SKILL.md §§ Preserve the observation hierarchy, Check what was actually compared, and Return an auditable conclusion audit supplied measurements and verdicts; device identity is comparison metadata, not a hardware-resource mechanism."}, + "audit-flare-session-lifecycle": {"path": "systems/engines/flare-local-inference/audit-flare-session-lifecycle/SKILL.md", "state": "supplementary", "coordinates": []}, + "audit-h3-metal-fasth3-semantics": {"path": "systems/engines/h3-metal/audit-h3-metal-fasth3-semantics/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Observe"], ["Accelerator", "Verify"]]}, + "audit-h3-runtime-residency": {"path": "systems/engines/h3-c/audit-h3-runtime-residency/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Observe"], ["Accelerator", "Verify"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Observe"], ["RAM/Host", "Verify"], ["SSD", "Configure"], ["SSD", "Diagnose"], ["SSD", "Verify"]]}, + "audit-llama-runtime-state": {"path": "systems/engines/llama-cpp/audit-llama-runtime-state/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Verify"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Verify"]]}, + "audit-recurrent-kv-finalization": {"path": "systems/engines/vllm-rlt/audit-recurrent-kv-finalization/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Verify"]]}, + "audit-sd-cpp-residency": {"path": "systems/engines/stable-diffusion-cpp/audit-sd-cpp-residency/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Observe"], ["Accelerator", "Verify"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Observe"], ["RAM/Host", "Verify"], ["SSD", "Diagnose"], ["SSD", "Verify"]]}, + "audit-sglang-diffusion-lifetimes": {"path": "systems/engines/sglang/audit-sglang-diffusion-lifetimes/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Verify"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Verify"]]}, + "audit-vllm-kv-lifetimes": {"path": "systems/engines/vllm/audit-vllm-kv-lifetimes/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Observe"], ["Accelerator", "Verify"]]}, + "bound-windowed-attention-replay": {"path": "systems/engines/deepinfer/bound-windowed-attention-replay/SKILL.md", "state": "supplementary", "coordinates": []}, + "budget-speculative-verification": {"path": "systems/engines/deepinfer/budget-speculative-verification/SKILL.md", "state": "supplementary", "coordinates": []}, + "calibrate-serving-simulation": {"path": "playbooks/measurement/calibrate-serving-simulation/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Verify"]]}, + "cann-attribution-overlap": {"path": "systems/platforms/ascend/cann-attribution-overlap/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Observe"], ["Accelerator", "Optimize"], ["Accelerator", "Profile"], ["Accelerator", "Verify"], ["Network", "Diagnose"], ["Network", "Optimize"], ["Network", "Verify"]]}, + "cgroup-resource-controls": {"path": "systems/platforms/host/cgroup-resource-controls/SKILL.md", "state": "covered", "coordinates": [["RAM/Host", "Configure"], ["RAM/Host", "Observe"], ["RAM/Host", "Profile"], ["RAM/Host", "Verify"], ["OS", "Configure"], ["OS", "Diagnose"], ["OS", "Observe"], ["OS", "Optimize"], ["OS", "Profile"], ["OS", "Verify"]]}, + "checkpoint-recovery-consistency": {"path": "playbooks/planning/checkpoint-recovery-consistency/SKILL.md", "state": "covered", "coordinates": [["RAM/Host", "Configure"], ["RAM/Host", "Verify"], ["SSD", "Configure"], ["SSD", "Verify"], ["Network", "Configure"], ["Network", "Diagnose"], ["Network", "Verify"], ["OS", "Configure"], ["OS", "Diagnose"]]}, + "choose-parallel-training-plan": {"path": "playbooks/planning/choose-parallel-training-plan/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"], ["Network", "Configure"], ["Network", "Diagnose"], ["Network", "Optimize"], ["Network", "Verify"]]}, + "cite-check-downstream-pr": {"path": "workflows/governance/cite-check-downstream-pr/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "SKILL.md §§ Checklist and Red flags check acceptance links, revision/artifact citations and claim wording; they provide no hardware-resource mechanism."}, + "claim-contract": {"path": "workflows/governance/claim-contract/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Verify"]]}, + "comfy-ui": {"path": "systems/engines/comfy-ui/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Verify"], ["RAM/Host", "Configure"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Verify"]]}, + "competitor-scan": {"path": "workflows/research/competitor-scan/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "SKILL.md §§ Frame, Rules and Deliverable produce a qualitative competitive comparison with evidence limits, not a hardware-resource decision or implementation mechanism."}, + "dcp-async-save-performance": {"path": "systems/frameworks/pytorch/dcp-async-save-performance/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["RAM/Host", "Configure"], ["RAM/Host", "Observe"], ["RAM/Host", "Optimize"], ["RAM/Host", "Profile"], ["RAM/Host", "Verify"], ["SSD", "Configure"], ["SSD", "Observe"], ["SSD", "Optimize"], ["SSD", "Profile"], ["SSD", "Verify"]]}, + "dense-performance-evidence": {"path": "playbooks/measurement/dense-performance-evidence/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Observe"], ["Accelerator", "Profile"], ["Accelerator", "Verify"], ["RAM/Host", "Verify"], ["Network", "Verify"]]}, + "diagnose-attention-bottlenecks": {"path": "systems/platforms/cuda/diagnose-attention-bottlenecks/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"]]}, + "diagnose-vllm-admission-pressure": {"path": "systems/engines/vllm/diagnose-vllm-admission-pressure/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Observe"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"]]}, + "diffusers-invocation-state": {"path": "systems/frameworks/diffusers/diffusers-invocation-state/SKILL.md", "state": "supplementary", "coordinates": []}, + "draft-acceptance-issue": {"path": "workflows/governance/draft-acceptance-issue/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "SKILL.md §§ Steps and Output prepare an acceptance issue, RunSpec, frozen gates and evidence paths; device identifiers are campaign metadata rather than a hardware-resource mechanism."}, + "dwarfstar": {"path": "systems/engines/dwarfstar/SKILL.md", "state": "supplementary", "coordinates": []}, + "evaluate-elastic-serving-placement": {"path": "playbooks/planning/evaluate-elastic-serving-placement/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"], ["RAM/Host", "Configure"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Optimize"], ["RAM/Host", "Verify"], ["Network", "Configure"], ["Network", "Diagnose"], ["Network", "Optimize"], ["Network", "Verify"]]}, + "generation-cache-lifecycle": {"path": "systems/engines/mlx-lm/generation-cache-lifecycle/SKILL.md", "state": "supplementary", "coordinates": []}, + "host-memory-management": {"path": "systems/platforms/host/host-memory-management/SKILL.md", "state": "covered", "coordinates": [["RAM/Host", "Configure"], ["RAM/Host", "Verify"]]}, + "host-overhead-optimization": {"path": "systems/platforms/host/host-overhead-optimization/SKILL.md", "state": "covered", "coordinates": [["RAM/Host", "Diagnose"], ["RAM/Host", "Optimize"], ["RAM/Host", "Verify"]]}, + "host-overhead-profiling": {"path": "systems/platforms/cuda/host-overhead-profiling/SKILL.md", "state": "covered", "coordinates": [["RAM/Host", "Diagnose"], ["RAM/Host", "Observe"], ["RAM/Host", "Profile"]]}, + "husky": {"path": "systems/engines/husky/SKILL.md", "state": "unknown", "coordinates": []}, + "inference-benchmark-design": {"path": "playbooks/measurement/inference-benchmark-design/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "SKILL.md §§ Select the task and its evaluation contract, Statistical requirements, Shared-machine measurement discipline, and Search integrity and final-state verification design comparable evaluation; hardware identity and allocation isolation are comparison controls, not a hardware-resource mechanism."}, + "inference-optimization-casebook": {"path": "casebooks/inference/inference-optimization-casebook/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Optimize"]]}, + "inference-task-router": {"path": "tasks/inference-task-router/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "This entry selects a task and its evidence requirements before resource-layer analysis."}, + "kernel-writing-guide": {"path": "playbooks/optimization/kernel-writing-guide/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"]]}, + "kv-tier-management": {"path": "systems/engines/lmcache/kv-tier-management/SKILL.md", "state": "covered", "coordinates": [["RAM/Host", "Configure"], ["RAM/Host", "Optimize"], ["SSD", "Optimize"]]}, + "lazy-evaluation-stream-lifetimes": {"path": "systems/frameworks/mlx/lazy-evaluation-stream-lifetimes/SKILL.md", "state": "supplementary", "coordinates": []}, + "lily": {"path": "systems/engines/lily/SKILL.md", "state": "supplementary", "coordinates": []}, + "lithos-metal": {"path": "systems/engines/lithos-metal/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"]]}, + "local-dream": {"path": "systems/engines/local-dream/SKILL.md", "state": "supplementary", "coordinates": []}, + "mistral-rs": {"path": "systems/engines/mistral-rs/SKILL.md", "state": "supplementary", "coordinates": []}, + "mlc-llm": {"path": "systems/engines/mlc-llm/SKILL.md", "state": "supplementary", "coordinates": []}, + "mlx-swift-lm": {"path": "systems/engines/mlx-swift-lm/SKILL.md", "state": "supplementary", "coordinates": []}, + "model-sol-analysis": {"path": "playbooks/measurement/model-sol-analysis/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Verify"], ["Network", "Diagnose"], ["Network", "Verify"]]}, + "npu-skill-factory": {"path": "workflows/maintenance/npu-skill-factory/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "SKILL.md §§ Choose the evidence product, Artifact lifecycle, and What this skill does not do define skill-distillation/evaluation methodology; NPU task tiers are evaluation prerequisites, not a hardware-resource mechanism."}, + "optimization-search-policy": {"path": "playbooks/planning/optimization-search-policy/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Optimize"]]}, + "os-process-placement": {"path": "systems/platforms/host/os-process-placement/SKILL.md", "state": "covered", "coordinates": [["OS", "Optimize"]]}, + "performance-ceiling-analysis": {"path": "playbooks/measurement/performance-ceiling-analysis/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Verify"], ["OS", "Configure"]]}, + "plan-activation-residency": {"path": "playbooks/planning/plan-activation-residency/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"]]}, + "project-maya": {"path": "systems/engines/project-maya/SKILL.md", "state": "supplementary", "coordinates": []}, + "pytorch": {"path": "systems/frameworks/pytorch/pytorch/SKILL.md", "state": "supplementary", "coordinates": []}, + "reason-hopper-kernels": {"path": "systems/platforms/cuda/reason-hopper-kernels/SKILL.md", "state": "supplementary", "coordinates": []}, + "repository-evolution-analysis": {"path": "workflows/research/repository-evolution-analysis/SKILL.md", "state": "covered", "coordinates": [["OS", "Configure"], ["OS", "Diagnose"], ["OS", "Verify"]]}, + "rsi-evidence": {"path": "workflows/governance/rsi-evidence/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Verify"]]}, + "skill-evolution-playbook": {"path": "workflows/maintenance/skill-evolution-playbook/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "SKILL.md §§ When should one trajectory update a skill?, How large should a skill edit be?, and When should skills split or merge? govern skill-text evolution and held-out evaluation, not hardware-resource state or control."}, + "splash": {"path": "systems/engines/splash/SKILL.md", "state": "supplementary", "coordinates": []}, + "storage-io-measurement": {"path": "systems/platforms/host/storage-io-measurement/SKILL.md", "state": "covered", "coordinates": [["SSD", "Diagnose"], ["SSD", "Observe"], ["SSD", "Profile"], ["SSD", "Verify"]]}, + "task-accuracy": {"path": "tasks/task-accuracy/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "The procedure selects supporting evidence and tests within the caller's declared search space."}, + "task-day-0": {"path": "tasks/task-day-0/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "The procedure selects supporting evidence and tests within the caller's declared search space."}, + "task-debug": {"path": "tasks/task-debug/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "The procedure selects supporting evidence and tests within the caller's declared search space."}, + "task-derived-engine": {"path": "tasks/task-derived-engine/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "The procedure selects supporting evidence and tests within the caller's declared search space."}, + "task-independent-engine": {"path": "tasks/task-independent-engine/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "The procedure selects supporting evidence and tests within the caller's declared search space."}, + "task-performance": {"path": "tasks/task-performance/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "The procedure selects supporting evidence and tests within the caller's declared search space."}, + "task-version-alignment": {"path": "tasks/task-version-alignment/SKILL.md", "state": "not-applicable", "coordinates": [], "exclusion_reason": "The procedure selects supporting evidence and tests within the caller's declared search space."}, + "torch-npu": {"path": "systems/frameworks/torch-npu/torch-npu/SKILL.md", "state": "supplementary", "coordinates": []}, + "torchnpu-device-memory-lifecycle": {"path": "systems/platforms/ascend/torchnpu-device-memory-lifecycle/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["Accelerator", "Verify"]]}, + "torchnpu-pinned-host-memory-lifecycle": {"path": "systems/platforms/ascend/torchnpu-pinned-host-memory-lifecycle/SKILL.md", "state": "covered", "coordinates": [["RAM/Host", "Configure"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Optimize"], ["RAM/Host", "Verify"]]}, + "training-input-pipeline": {"path": "playbooks/optimization/training-input-pipeline/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Observe"], ["Accelerator", "Optimize"], ["RAM/Host", "Configure"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Observe"], ["RAM/Host", "Optimize"], ["SSD", "Configure"], ["SSD", "Diagnose"], ["SSD", "Optimize"], ["Network", "Configure"], ["Network", "Optimize"], ["OS", "Configure"], ["OS", "Optimize"]]}, + "training-resource-budget": {"path": "playbooks/planning/training-resource-budget/SKILL.md", "state": "covered", "coordinates": [["Accelerator", "Configure"], ["Accelerator", "Diagnose"], ["Accelerator", "Optimize"], ["RAM/Host", "Configure"], ["RAM/Host", "Diagnose"], ["RAM/Host", "Observe"], ["RAM/Host", "Optimize"], ["RAM/Host", "Verify"], ["SSD", "Configure"], ["SSD", "Optimize"], ["Network", "Diagnose"], ["Network", "Observe"], ["Network", "Verify"], ["OS", "Configure"], ["OS", "Diagnose"]]}, + "video-diffusion-optimization": {"path": "playbooks/optimization/video-diffusion-optimization/SKILL.md", "state": "supplementary", "coordinates": []}, + "vllm-ascend": {"path": "systems/engines/vllm-ascend/SKILL.md", "state": "supplementary", "coordinates": []}, + "vllm-metal": {"path": "systems/engines/vllm-metal/SKILL.md", "state": "supplementary", "coordinates": []}, + "weight-loading-optimization": {"path": "playbooks/optimization/weight-loading-optimization/SKILL.md", "state": "covered", "coordinates": [["SSD", "Diagnose"], ["SSD", "Observe"], ["SSD", "Optimize"], ["SSD", "Profile"], ["SSD", "Verify"], ["Network", "Configure"], ["Network", "Optimize"], ["Network", "Verify"]]} + } +} diff --git a/src/inferrsi/knowledge/searchspace_index.py b/src/inferrsi/knowledge/searchspace_index.py new file mode 100644 index 000000000..fecb55c2d --- /dev/null +++ b/src/inferrsi/knowledge/searchspace_index.py @@ -0,0 +1,143 @@ +"""Read a matrix coordinate snapshot for an InferRSI source checkout.""" + +from __future__ import annotations + +import hashlib +import json +from collections.abc import Iterable, Mapping +from dataclasses import dataclass +from pathlib import Path +from types import MappingProxyType + +from .skill_catalog import _entry, skill_directories + +LIBRARY = Path("src/inferrsi/knowledge/data/skill_library") +CATALOG = LIBRARY / "skill-index.json" +MATRIX = Path("docs/searchspace-matrix.md") +INDEX = Path("docs/searchspace-index.json") + +RESOURCES = {"1": "Accelerator", "2": "RAM/Host", "3": "SSD", "4": "Network", "5": "OS"} +STAGES = ("Observe", "Profile", "Diagnose", "Configure", "Optimize", "Verify") +STATES = ("covered", "supplementary", "unknown", "not-applicable", "conflict") + + +class SearchspaceSourceMismatch(ValueError): + """The artifact or lookup is for a different source identity.""" + + +class StaleSearchspaceIndex(ValueError): + """The artifact does not correspond to this checkout's current sources.""" + + +def _sha256(path: Path) -> str: + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def input_digest(root: Path, paths: Iterable[Path]) -> str: + """Hash inputs in repository-relative POSIX path order on every host.""" + digest = hashlib.sha256() + relative = {path: path.relative_to(root).as_posix() for path in paths} + for path in sorted(relative, key=relative.__getitem__): + digest.update(relative[path].encode("utf-8")) + digest.update(b"\0") + digest.update(bytes.fromhex(_sha256(path))) + return digest.hexdigest() + + +def _source_paths() -> dict[str, str]: + return { + "matrix_path": MATRIX.as_posix(), + "catalog_path": CATALOG.as_posix(), + "skill_root": LIBRARY.as_posix(), + } + + +def coordinate_inputs(root: Path) -> tuple[dict[str, str], dict[str, str]]: + """Fingerprint the matrix, registry and all files supplying Skill metadata.""" + root = root.resolve() + matrix = root / MATRIX + catalog = root / CATALOG + sources = {**_source_paths(), "matrix_sha256": _sha256(matrix)} + registry_bytes = catalog.read_bytes() + sources["catalog_sha256"] = hashlib.sha256(registry_bytes).hexdigest() + directories = skill_directories(root / LIBRARY) + registry = json.loads(registry_bytes)["skills"] + paths = {name: f"{registry[name]['path']}/SKILL.md" for name in directories} + metadata = [] + for name, directory in directories.items(): + entrypoint = root / LIBRARY / paths[name] + metadata.append(entrypoint) + if _entry(directory, "metadata.json").is_file(): + metadata.append(entrypoint.with_name("metadata.json")) + sources["metadata_sha256"] = input_digest(root, metadata) + return sources, paths + + +@dataclass(frozen=True) +class SearchspaceEntry: + path: str + state: str + coordinates: frozenset[tuple[str, str]] + exclusion_reason: str | None = None + + def matches(self, resource: str, stage: str) -> bool: + """Match a declared pair. Missing, supplementary and excluded pairs miss.""" + return (resource, stage) in self.coordinates + + +@dataclass(frozen=True) +class SearchspaceIndex: + _skill_root: Path + _entries: Mapping[str, SearchspaceEntry] + + def entry(self, *, skill_root: Path, skill_id: str, path: str) -> SearchspaceEntry: + """Look up an identity qualified by its Skill root and relative SKILL.md path.""" + entry = self._entries.get(skill_id) + if skill_root.resolve() != self._skill_root or entry is None or path != entry.path: + raise SearchspaceSourceMismatch(f"Skill is outside this SearchSpace: {skill_id}") + return entry + + +def _load_entry(row: object, path: str) -> SearchspaceEntry: + if not isinstance(row, dict) or row.get("path") != path: + raise StaleSearchspaceIndex(f"SearchSpace path disagrees with the Skill registry: {path}") + state, pairs, reason = row.get("state"), row.get("coordinates"), row.get("exclusion_reason") + if ( + state not in STATES or not isinstance(pairs, list) + or bool(pairs) != (state == "covered") + or (reason is not None and (not isinstance(reason, str) or not reason.strip())) + or (reason is not None) != (state in ("not-applicable", "conflict")) + or any( + not isinstance(pair, list) or len(pair) != 2 + or pair[0] not in RESOURCES.values() or pair[1] not in STAGES + for pair in pairs + ) + ): + raise ValueError(f"Invalid SearchSpace index entry: {path}") + return SearchspaceEntry(path, state, frozenset(tuple(pair) for pair in pairs), reason) + + +def load_searchspace_index(checkout: Path) -> SearchspaceIndex: + """Read and verify a generated index against its canonical checkout sources.""" + root = checkout.resolve() + artifact = json.loads((root / INDEX).read_bytes()) + if not isinstance(artifact, dict) or type(artifact.get("schema_version")) is not int: + raise ValueError("Invalid SearchSpace index") + if artifact["schema_version"] != 1: + raise ValueError("Unsupported SearchSpace index schema") + source = artifact.get("source") + if not isinstance(source, dict) or any( + source.get(key) != path for key, path in _source_paths().items() + ): + raise SearchspaceSourceMismatch("SearchSpace index names different canonical sources") + try: + current, paths = coordinate_inputs(root) + except (FileNotFoundError, ValueError) as exc: + raise StaleSearchspaceIndex("SearchSpace sources are missing or invalid") from exc + if source != current: + raise StaleSearchspaceIndex("SearchSpace matrix, registry or Skill metadata changed") + entries = artifact.get("skills") + if not isinstance(entries, dict) or entries.keys() != paths.keys(): + raise StaleSearchspaceIndex("SearchSpace skills disagree with the Skill registry") + loaded = {name: _load_entry(entries[name], path) for name, path in paths.items()} + return SearchspaceIndex((root / LIBRARY).resolve(), MappingProxyType(loaded)) diff --git a/tests/test_searchspace_index.py b/tests/test_searchspace_index.py new file mode 100644 index 000000000..1259b5160 --- /dev/null +++ b/tests/test_searchspace_index.py @@ -0,0 +1,202 @@ +"""SearchSpace coordinates preserve canonical owner identity and authority.""" + +import json +import shutil +from pathlib import Path + +import pytest + +from inferrsi.knowledge.searchspace_index import ( + CATALOG, + INDEX, + LIBRARY, + MATRIX, + SearchspaceSourceMismatch, + StaleSearchspaceIndex, + load_searchspace_index, +) +from tools.build_skill_coverage import render_coordinate_index + +PROJECT = Path(__file__).resolve().parents[1] +GRAPH = "ascend-graph-mode" +LLAMA = "audit-llama-runtime-state" +REASON = "The owner records a resource exclusion for this test." + + +def _read_json(path): + return json.loads(path.read_bytes()) + + +def _registered_path(root, name): + return _read_json(root / CATALOG)["skills"][name]["path"] + "/SKILL.md" + + +def _entry(index, root, name): + return index.entry(skill_root=root / LIBRARY, skill_id=name, path=_registered_path(root, name)) + + +def _generate(root): + artifact = render_coordinate_index(root).encode("utf-8") + (root / INDEX).write_bytes(artifact) + return artifact + + +@pytest.fixture(scope="module") +def real_index(): + return load_searchspace_index(PROJECT) + + +@pytest.fixture +def checkout(tmp_path): + root = tmp_path / "checkout" + (root / MATRIX).parent.mkdir(parents=True) + shutil.copyfile(PROJECT / MATRIX, root / MATRIX) + registry = _read_json(PROJECT / CATALOG) + registry["skills"] = {name: registry["skills"][name] for name in (GRAPH, LLAMA)} + for owner in registry["skills"].values(): + path = LIBRARY / owner["path"] / "SKILL.md" + (root / path).parent.mkdir(parents=True) + shutil.copyfile(PROJECT / path, root / path) + (root / CATALOG).write_text(json.dumps(registry), encoding="utf-8") + return root + + +@pytest.mark.parametrize( + "name,positive,negative", + [ + (GRAPH, (("Accelerator", "Configure"), ("SSD", "Diagnose")), (("SSD", "Configure"),)), + ("audit-h3-runtime-residency", (("RAM/Host", "Observe"), ("SSD", "Configure")), + (("SSD", "Observe"), ("Accelerator", "Configure"))), + (LLAMA, (("Accelerator", "Diagnose"), ("RAM/Host", "Verify")), + (("SSD", "Optimize"), ("OS", "Optimize"))), + ("audit-afd-p2p-exchanges", (("Accelerator", "Verify"),), (("Network", "Verify"),)), + ], +) +def test_real_matrix_coordinates_never_cross_resource_rows(real_index, name, positive, negative): + entry = _entry(real_index, PROJECT, name) + assert entry.state == "covered" + assert all(entry.matches(*pair) for pair in positive) + assert not any(entry.matches(*pair) for pair in negative) + + +@pytest.mark.parametrize( + "name,state", + [("reason-hopper-kernels", "supplementary"), ("husky", "unknown"), + ("audit-fixed-workload-claim", "not-applicable")], +) +def test_noncovered_owners_keep_their_distinct_states(real_index, name, state): + entry = _entry(real_index, PROJECT, name) + assert entry.state == state + assert entry.coordinates == set() + assert bool(entry.exclusion_reason) == (state == "not-applicable") + + +def test_lookup_requires_root_and_registered_path(real_index, tmp_path): + path = _registered_path(PROJECT, GRAPH) + other_root = tmp_path / "other-kb" / "skill_library" + (other_root / path).parent.mkdir(parents=True) + shutil.copyfile(PROJECT / LIBRARY / path, other_root / path) + with pytest.raises(SearchspaceSourceMismatch): + real_index.entry(skill_root=other_root, skill_id=GRAPH, path=path) + with pytest.raises(SearchspaceSourceMismatch): + real_index.entry(skill_root=PROJECT / LIBRARY, skill_id=GRAPH, path=f"other/{path}") + + +def test_only_canonical_candidate_entries_contribute_coordinates(checkout): + path = f"../{LIBRARY.as_posix()}/{_registered_path(checkout, LLAMA)}" + graph = f"../{LIBRARY.as_posix()}/{_registered_path(checkout, GRAPH)}" + fake = f"../other/{LIBRARY.as_posix()}/{_registered_path(checkout, LLAMA)}" + # The identically named target really exists, but outside the registry's source. + alternative = (checkout / "docs" / fake).resolve() + alternative.parent.mkdir(parents=True) + shutil.copyfile(checkout / LIBRARY / _registered_path(checkout, LLAMA), alternative) + row = ( + f"| **Observe / Profile** | `{LLAMA}` | [{GRAPH}]({graph}) (see [{LLAMA}]({path})); " + f"[owner map]({path}); [{LLAMA}]({path}#choose-the-scope); [{LLAMA}]({fake}) " + f"| `{LLAMA}` | [{LLAMA}]({path}) | — |" + ) + matrix = checkout / MATRIX + matrix.write_text(matrix.read_text(encoding="utf-8").replace( + "|---|---|---|---|---|---|", f"|---|---|---|---|---|---|\n{row}", 1, + ), encoding="utf-8") + _generate(checkout) + index = load_searchspace_index(checkout) + for stage in ("Observe", "Profile"): + assert _entry(index, checkout, GRAPH).matches("Accelerator", stage) + assert not _entry(index, checkout, LLAMA).matches("Accelerator", stage) + + +@pytest.mark.parametrize("changed", (MATRIX, CATALOG)) +def test_index_rejects_stale_matrix_or_registry(checkout, changed): + artifact = _generate(checkout) + path = checkout / changed + if changed == CATALOG: + registry = _read_json(path) + registry["skills"][GRAPH]["backend"] = "common" + path.write_text(json.dumps(registry), encoding="utf-8") + else: + path.write_bytes(path.read_bytes() + b"\n") + with pytest.raises(StaleSearchspaceIndex): + load_searchspace_index(checkout) + assert (checkout / INDEX).read_bytes() == artifact + + +def test_index_rejects_an_artifact_declaring_another_source(checkout): + _generate(checkout) + artifact = _read_json(checkout / INDEX) + artifact["source"]["catalog_path"] = "other/skill-index.json" + (checkout / INDEX).write_text(json.dumps(artifact), encoding="utf-8") + with pytest.raises(SearchspaceSourceMismatch): + load_searchspace_index(checkout) + + +def test_verified_sources_do_not_hide_a_wrong_generated_skill_path(checkout): + artifact = json.loads(_generate(checkout)) + artifact["skills"][GRAPH]["path"] = f"other/{GRAPH}/SKILL.md" + (checkout / INDEX).write_text(json.dumps(artifact), encoding="utf-8") + with pytest.raises(StaleSearchspaceIndex, match="path disagrees"): + load_searchspace_index(checkout) + + +@pytest.mark.parametrize("legacy_sidecar", (False, True)) +def test_exclusion_metadata_alone_stales_the_index_and_yields_conflict(checkout, legacy_sidecar): + path = checkout / LIBRARY / _registered_path(checkout, GRAPH) + if legacy_sidecar: + path.write_bytes(f"---\nname: {GRAPH}\ndescription: Legacy Skill\n---\n".encode()) + path.with_name("metadata.json").write_text("{}", encoding="utf-8") + _generate(checkout) + old = load_searchspace_index(checkout) + old_fingerprints = _read_json(checkout / INDEX)["source"] + assert _entry(old, checkout, GRAPH).matches("Accelerator", "Configure") + + if legacy_sidecar: + path.with_name("metadata.json").write_text( + json.dumps({"searchspace_not_applicable": REASON}), encoding="utf-8", + ) + else: + initial = path.read_bytes() + exclusion = f' "searchspace_not_applicable": "{REASON}",\n'.encode() + path.write_bytes(initial.replace(b" {\n", b" {\n" + exclusion, 1)) + with pytest.raises(StaleSearchspaceIndex): + load_searchspace_index(checkout) + + _generate(checkout) + fingerprints = _read_json(checkout / INDEX)["source"] + assert fingerprints["matrix_sha256"] == old_fingerprints["matrix_sha256"] + assert fingerprints["catalog_sha256"] == old_fingerprints["catalog_sha256"] + assert fingerprints["metadata_sha256"] != old_fingerprints["metadata_sha256"] + entry = _entry(load_searchspace_index(checkout), checkout, GRAPH) + assert entry.state == "conflict" + assert entry.exclusion_reason == REASON + assert not entry.matches("Accelerator", "Configure") + assert entry.coordinates == set() + + +def test_generated_file_matches_canonical_sources(): + assert render_coordinate_index(PROJECT).encode("utf-8") == (PROJECT / INDEX).read_bytes() + + +def test_generation_is_checkout_location_independent(checkout, tmp_path): + other = tmp_path / "another checkout" + shutil.copytree(checkout, other) + assert _generate(checkout) == _generate(other) diff --git a/tools/build_skill_coverage.py b/tools/build_skill_coverage.py index 259f39c29..3d6f1f573 100644 --- a/tools/build_skill_coverage.py +++ b/tools/build_skill_coverage.py @@ -1,17 +1,19 @@ import argparse -import hashlib import json import re import sys +from collections import defaultdict from difflib import unified_diff from pathlib import Path -from inferrsi.knowledge.skill_catalog import skill_directories, skill_metadata +from inferrsi.knowledge.searchspace_index import CATALOG as INDEX +from inferrsi.knowledge.searchspace_index import INDEX as COORDINATE_INDEX +from inferrsi.knowledge.searchspace_index import LIBRARY, STAGES, coordinate_inputs, input_digest +from inferrsi.knowledge.searchspace_index import MATRIX as SEARCHSPACE +from inferrsi.knowledge.searchspace_index import RESOURCES as SHORT +from inferrsi.knowledge.skill_catalog import _effective, skill_directories, skill_metadata -LIBRARY = Path("src/inferrsi/knowledge/data/skill_library") -INDEX = LIBRARY / "skill-index.json" OUTPUT = Path("docs/skill-coverage.md") -SEARCHSPACE = Path("docs/searchspace-matrix.md") REFERENCE = Path("docs/reference-matrix.md") EVIDENCE = Path("evidence") @@ -24,11 +26,11 @@ "4": "Communication Card / Network", "5": "OS / System", } -SHORT = {"1": "Accelerator", "2": "RAM/Host", "3": "SSD", "4": "Network", "5": "OS"} - HEADING = re.compile(r"^## ([1-5]) · (.+)$") LINK = re.compile(r"\(([^()\s]*/skill_library/[^()\s]+/SKILL\.md)\)") BOLD = re.compile(r"\*\*(.+?)\*\*") +CANDIDATE_LINK = r"\[(?P