Skip to content

Latest commit

 

History

History
434 lines (351 loc) · 25.7 KB

architecture.md

File metadata and controls

434 lines (351 loc) · 25.7 KB

Modular architecture

The engineering task library packages MoE forward, Qwen-Image denoising and real-model Qwen3-TTS under benchmark/tasks. inferrsi benchmarks list|show discovers the packages. inferrsi benchmarks run <package> ... launches the package's benchmark.py. Task-specific orchestration, sampling and assessment live inside each package. The task library owns its index.json registration. The existing benchmark/registry.py discovers the resources. The CLI package apps/cli/ and apps/workflows/benchmark_operations.py provide application assembly and launch. Each task retains its own protocol and task-specific code.

The current-Agent optimization session assembles the first complete handoff for the Qwen task. harness/optimization.py controls budget, attempts, feedback records, selection and independent final execution. harness/task_protocol.py freezes a supplied resource directory and loads its task-owned assessment protocol. harness/optimization_session.py assembles execution and assessment; the CLI resolves task resources and injects knowledge access and the capture callback from apps/workflows/campaign.py. The external Agent chooses and edits candidates between round submissions. The same controller serves ordinary projects through campaign start/round/final and packaged tasks through benchmarks session. The shared workflow and sequence diagram describe multi-file candidates, explicit acceptance inputs, stop rules and dashboard projections from one control record. harness/project.py freezes caller-provided checks and assesses their retained outputs. Ordinary optimization does not import Benchmark. Benchmark supplies task definitions and specialized rules, while Harness manages their execution and the complete optimization lifecycle. Neither infers quality criteria from a natural-language goal. Ordinary projects default to the current Agent conversation. The optional service-reuse protocol adds project assessment and foreground service ownership within this same controller. Its protocol and result rules live in harness.project_service, with process lifetime managed by local_process. The experimental speculative search composes immutable candidate trees, bounded completion menus, synchronous VATS and CPU GVO roles. Its work controller uses shared RunStore transactions and the existing local process executor. Apps supplies Engine/Skill grading; the support matrix identifies remaining production accounting and pilot evidence. Serial session commands keep their existing controller and behavior. The native host handoff lets the initiating Agent resolve the task request before any campaign exists, use its host's new-session tool and retain the native identity and returned artifacts. The child owns the complete start/knowledge/round/final lifecycle; the parent observes and collects. This path records the handoff; it does not implement a background Agent CLI driver or a native-host deadline.

The application injects harness.executor.trials.external.execute_trial into the two-rank MoE entry. The standalone image benchmark and TTS service protocol expose their documented execution boundaries. Apps and Harness callers assemble these operations into optimization rounds under the #362 target architecture. Each task records its qualification.

The diagrams below show where the CLI assembles an experiment, which package owns each step and where to extend it. The compatibility notes cover retained interfaces and imports that moved.

Architecture anchors

Use these anchors to trace review findings to their source. The linked source governs if wording differs. The governing Issue owner decides anchor changes. The checks below identify existing test coverage. The linked acceptance criteria are specifications for review.

A1 — Core imports and assembly

D001 keeps Knowledge, Harness and Benchmark as sibling cores and Apps as the only assembler, so the import gate restricts cross-core imports and admits the exact python -m inferrsi CLI delegation, while shared layers stay independent of campaigns in examples/.

Checked by tests/repository/test_target_module_import_gate.py and tests/repository/test_module_boundaries.py::test_shared_layers_do_not_import_campaigns_or_reverse_dependencies.

A2 — Versioned envelopes and technical leaves

Cross-core traffic uses versioned JSON envelopes with explicit conversion and core-owned business types, with shared technical leaves limited to the exact D001 list and its neutral-leaf importer rule.

Checked by tests/repository/test_first_wave_isolation_policy.py.

A3 — Retired paths

Retired module paths stay retired without forwarders or aliases, and the tracked package root holds only __init__.py and __main__.py.

Checked by tests/repository/test_package_root_inventory.py and tests/repository/test_target_module_import_gate.py.

A4 — Benchmark judgment

Benchmark owns claim, metric, eligibility, comparison and scope semantics and scope containment, while Apps maps roles, fields and versions verbatim without imposing sampling, retry, budget or judgment rules.

Checked by review.

A5 — Execution and offline assessment

Harness owns lifecycle, deadlines, budget, cleanup and the optimization loop, Benchmark owns the worker recipe, sampling and aggregation, and its prepare and assess start no worker, with offline assess making no subprocess, network or device call.

Checked by review against T04–T07 and T15–T17.

A6 — Evidence and verdicts

Unknown budget facts use null with a reason, unperformed checks use not_performed, finished requires confirmed cleanup of external resources when applicable, and a same-claim, same-scope conflict defaults to INCONCLUSIVE under the frozen rules.

Checked by review against T01–T14 and T22–T24.

A7 — Legacy compatibility and frozen evidence

D013 preserves its legacy CLI entry points, arguments, Path behavior, output bytes and old run exit codes, while historical evidence retains its original bytes and a new campaign with a changed implementation requires fresh frozen references.

Checked by tests/apps/test_legacy_run_v0_frozen.py for the legacy run exit codes and evaluation.json bytes. Review covers the remaining clauses.

A8 — Shared scenario and adapter lifecycle

Scenario and adapter extensions reuse the common AB/BA loop, process cleanup and performance adjudication.

Checked by tests/repository/test_module_boundaries.py::test_new_scenario_target_and_backend_share_abba_and_verdict.

A9 — Governing approval for contract changes

Changes to these anchors, docs/contracts/**, the docs/guides/module-layout.md rules or docs/legacy-knowledge-manifest.json require a same-repository governing Issue whose recorded decision accepts the specific change and independent review under the review rules and D018.

Checked by review. The advisory CI check is a separate delivery in #574.

Three-objective delivery framing

The current WIP develops three connected objectives:

  1. Roofline / Optimization Headroom: source-grounded bounds, observed attainable limits, calibrated predictions and experiment selection. The ceiling skill provides guidance and pure conditional arithmetic for supplied L1 inputs; application results require their own measurements.
  2. Dense Commit Coordination: ownership, concurrent work, review, testing, integration, release and feedback into later changes. The existing Magpie material is history analysis. A first-hand coordination case is pending Dot delivery and owner review; neither that analysis nor paper methodology implements or verifies an autonomous development pipeline.
  3. Skill System: reusable candidate skills, knowledge and cases, the Reference Matrix, SearchSpace Matrix and the generated Skill Coverage View, and explicit read-only access. The Reference Matrix records inspected sources. The SearchSpace Matrix also supplies the verified resource/stage pairs used when a caller selects a coordinate filter for Find. The coverage view projects the same sources by skill. Execution requires a separate request.

This framing is presentation and delivery traceability, not a third primary matrix. Dot owns source extraction, the owner approves sources and reviews content/mappings, and the integration workstream owns reconciliation with the current artifacts. Candidate coverage and empirical validation stay separate. Paper versions/readsets remain distinct from implementation pins; a shared lineage or a linked paper is not independent corroboration.

Reviewed paper comparisons, readsets and cases live under their owning skill's references/ tree; distinct workflows receive their own candidate entrypoints. Paper knowledge does not supply repository-only schema fields such as a Git SHA, so it remains linked Markdown rather than a parallel registry or fabricated repo_packs record. The knowledge-base contract defines skill-local metadata ownership, typed source examples, shared checkout references and legacy package compatibility. Normalized reads and bounded Collect (knowledge-operations.md) and the authorized local store (knowledge-store.md) are implemented Python interfaces; existing CLI commands remain supported.

Module responsibilities and dependencies

Implemented modules and their dependencies

Module Owns Does not own
Knowledge The skill library and knowledge records, search, cited knowledge/context export and the collected-context projection Execution, task grading or campaign composition
Harness Command execution and process domains, AB/BA order, deadlines, source checks, optimization sessions, retained records and evidence Task grading and verdicts, report presentation, device-specific conditions, request schemas or kernel dispatch
Benchmark Task discovery and packages, graders, metric validation, assessments and the old-run gates Process execution, knowledge search or presentation
Apps CLI and the assembly of the three cores, host bindings (source identity, device discovery/qualification, environment facts), artifact digests and JSON writes, provider integrations including the Anthropic adapters, views and reports Model constants, task rules or performance verdicts
contracts/, resources/ The immutable RunSpec, JSON, claim and evidence-path helpers, and the neutral repository-pack reader Business DTOs or core initialization; neither package is a fourth core

Dependencies flow from entrypoints to Harness. #498 removed the Infra and Model packages, so Harness reaches neither. None of these shared packages imports a campaign from examples/.

Environment inspection follows that direction. apps/host/inspection.py is the facts API: it takes the command probe and the repository snapshot as ports. apps/host/prepared_environment.py binds those ports to this host with apps.host.commands.probe_command and apps.host.targets.repository_identity, and the CLI calls that composition. The apps/host/ package moved from Infra in #498 slice 3a and keeps its limit: it reaches no Knowledge, Harness or Benchmark module. apps/host/inspection.py reads a repository-pack description through the neutral resources.repository_packs leaf, under the one permanent importer rule in module-layout.md.

The target module layout describes the migration and the scope of the static import checks. The migration manifest records the retired compatibility pairs and the permanent neutral-leaf importer rule.

The caller still prepares the benchmark runtime and baseline/candidate source checkouts. Separate working directories alone do not isolate Python imports, resources or an existing server. The local executor can run directly on a prepared remote machine; SSH dispatch, distributed leases, automatic planning, patch generation and Hub publication remain future work.

Local executor commands are noninteractive and receive EOF on standard input. Supply their inputs through command arguments or files rather than the caller's input stream.

Offline harness-improvement lane

The single-step offline controller adds a bounded policy above the existing Skill Eval comparator. Supplied declarative INV/DOM edits are materialized as immutable Git snapshots. Development grades select a successor; it must run again before freezing for one independent held-out accept/reject gate. The controller accounts for the entire loop; candidate execution cost is reported separately. It reuses run_trial and the local executor, including their inherited absolute deadline, rather than creating another execution backend.

flowchart LR
    I["Frozen tasks, edits, policy and total budget"] --> C["Offline improvement controller"]
    C --> S["Existing Skill Eval comparator / run_trial"]
    S --> V["Independent grader + verified receipts"]
    V --> C
    C --> H["Freeze final candidate → one holdout gate"]
    C --> X["Development-only experience; no Store write"]
Loading

The feedback arrow represents development evidence only. Holdout cannot select a different candidate or cause another edit. Real-client execution, autonomous proposal generation, external sandbox enforcement and Store/CAS reuse are outside this MVP. PR skill evaluation is another existing consumer of the comparator; the engine AB/BA path retains its independent acceptance contract.

Directory map

Implemented modules mapped to directories

The four core READMEs cover current entry points and extension rules.

  • Knowledge owns retrieval and the packaged knowledge corpus.
  • Harness owns execution, run records and recovery.
  • Benchmark owns task definitions and independent assessment.
  • Apps owns the CLI and Python composition, host adapters and result delivery.

The contracts define versioned interfaces. The neutral resources package reads repository-pack descriptors. Use the module layout for ownership, compatibility and placement rules.

The package root holds exactly two tracked files: __init__.py and __main__.py. __main__.py and the console script call inferrsi.apps.cli:main. The build generates _version.py as wheel metadata. See the retired paths and replacements and the import gate for migration and dependency rules.

Where to extend

Add Main extension locations Required qualification
Model or scenario harness/serving, benchmark/metrics.py, benchmark/validators; trials run through the model-independent harness/executor/trials/external.py Frozen request and metric contract; model-specific quality coverage
Repository apps/host/targets, a composed scenario, resources/repo_packs Stable source identity; command/result contract; environment isolation
Hardware apps/host/platforms Device selection, process exclusivity and independent backend/model evidence; a backend is registered in apps/host/platforms/__init__.py and its probe command is defined in the implementing module under apps/host/platforms/, not in package data

The acceptance rule is: a new model or hardware adapter must reuse the common AB/BA loop, process cleanup and performance adjudication. The extension regression test composes a new metric schema, non-Git source adapter and backend probe through those interfaces while running real subprocesses. Its numbers are synthetic contract fixtures, not accelerator measurements.

Compose a new scenario

apps.legacy.run.run_experiment(spec, environment, *, execute, snapshot) composes the old run and accepts small callable adapters. It passes them, the Benchmark v0 gates and the report to harness.manager.run_experiment, whose four ports (execute, snapshot, assess, report) have no defaults. An omitted execute or snapshot is read from apps.legacy.run when the run starts (execute_trial and repository_identity), which is the two-argument call that the retired root execution.run_experiment provided. For a new external benchmark format, reuse the standard executor and only replace metric interpretation:

from functools import partial

from inferrsi.apps.legacy.run import execute_trial, run_experiment
from inferrsi.benchmark.metrics import read_metric


def read_engine_metric(document, key):
    normalized = {"metrics": {"latency_ms": float(document["duration_seconds"]) * 1000}}
    return read_metric(normalized, key)


run_dir = run_experiment(
    spec,
    environment,
    execute=partial(execute_trial, metric_reader=read_engine_metric),
)

The standard executor retains timeout, cancellation, logs, result paths and child cleanup. A custom execute(command, cwd, trial_dir, deadline, metric_key) must preserve that trial record contract. Prefer composing execute_trial over reimplementing process lifetime. Metric readers convert a result document into a float; benchmark.legacy_run_v0.trial_metric then applies the one finite, positive metric contract (benchmark.metrics.validate_metric) to whatever the reader returns, so a reader that yields 0.0, a bool or a non-finite value records a metric error rather than entering the evaluation. The Harness executor harness.executor.trials.external.execute_trial holds no metric rule: a caller that passes a metric key also passes metric=, its validation function.

Run state is written by the termination path, never assumed. status.json reports completed only after the final artifacts were written; a run stopped by a command state keeps timeout, failed or cancelled; an exception outside the adapter error contract writes crashed and re-raises; and a failure while writing the terminal artifacts writes termination_failed with the original measurement error beside it.

A new source adapter implements snapshot(repo, excluded_run_dir) and returns available plus a stable snapshot_hash and explanatory metadata. It must fingerprint relevant source, including changes between individual commands; it must not claim availability without a trustworthy identity. Git remains the default. Alternative adapters must define their own exclusion semantics.

Image campaigns can compose ImageProtocol.request with benchmark.sampling.collect_samples. The protocol receives model name, dimensions and sampling parameters from the campaign. The collector owns warmups, first-response retention, groups and artifact hashes; it accepts a request callback and file suffix, so it has no model/backend dispatch. The Qwen example now uses these shared modules.

For new image quality checks, install inferrsi[image] and construct an explicit ImageQualityGate from the frozen campaign plan. No SSIM/PSNR threshold is selected by the shared validator. RGB and alpha are checked separately, and a campaign can additionally require exact pixels. Image dependencies are lazy; the default control package continues to require only the standard library.

Add a platform or repository

Register a device probe in apps.host.platforms.PLATFORM_PROBES; supply the selected IDs, device model and bounded command runner. A new backend name additionally needs an entry in knowledge.catalog.BACKENDS, which supplies the CLI --backend choices and the accepted knowledge and skill backends; no package-data descriptor is required. Adding a device SKU within a backend is a parameter/configuration change. CUDA qualification takes an explicit device count and model; it contains no B300 or four-device default. ROCm and Ascend currently expose raw tool facts and require independent qualification. Discovery is not compatibility or performance certification.

For a new repository, start with the Git target adapter if applicable, add the repository descriptor/knowledge pack and compose its benchmark scenario. Update catalog choices for a new named repository type. These registrations do not change the AB/BA algorithm, process cleanup or evaluator.

Compatibility and historical evidence

The supervised server helpers (harness.serving.server.launch_server / stop_server) require Linux with a readable /proc process table. They reject other platforms before launch; missing or inaccessible process enumeration raises an error rather than reporting successful cleanup. Workers must remain in their owned process group. Windows Job Object support in the general command executor (harness.executor.local_process) does not extend to these server helpers. These constraints do not restrict read-only knowledge operations or the control CLI to Linux.

  • Existing CLI flags, external JSON metrics, run artifacts, cancellation handling and report generation are retained. Root Python import paths are not all retained: #451 and #412 R1 retired the root modules listed in CHANGELOG.md with no forwarding shell or alias. That file maps each old path to its replacement and states the pickle impact.
  • examples/qwen21_turbo_b300.py retains its command interface and campaign settings while delegating lifecycle, requests and sampling to shared modules.
  • The LTX helper and quality script, plus the pre-cleanup Qwen quality script, are preserved byte-for-byte under tests/fixtures/legacy/ for historical regression tests. The current Qwen quality entrypoint imports the same shared artifact utilities directly; its numerical and manifest checks are unchanged. Current examples no longer depend on LTX campaign code.
  • The Qwen runner hashes every Python module in the installed control package plus its current runner and quality entrypoints. A changed implementation requires fresh frozen references for a new campaign. Do not combine a new runner with an old guard-hash manifest or rewrite previous evidence to make it pass. Replay historical campaigns with their original source-pinned bundle.

Knowledge and evidence ownership

The knowledge library owns packaged procedures, engineering records and their provenance. Its layout and retrieval guide maps the registered owners, search configuration and generated build inputs. The knowledge base contract defines applicability, source attribution and verification. Runtime reads preserve the source revision and dependency resources. Imported knowledge supplies guidance for the caller to verify against the target workload.

Run evidence remains in the caller-selected run directory. Frozen campaign plans, results, patches and validators live under evidence/.

The earlier component design and complete workflow remain long-term references. Their Chinese component and Chinese workflow originals are preserved.

The supplied system overview is also available in English and Chinese. It summarizes inputs, normalization, the AB/BA loop, adjudication and retained evidence. Its feedback arrow represents explicit review and reuse by the caller, not implemented automatic promotion into the knowledge catalog or RunSpec. The original diagram is preserved; the source audit tracks cleanup portability and other implementation gaps.