Skip to content

Commit bb1be4f

Browse files
committed
[TRTLLM-16460][feat] trtllm_modeling_v2: isolated roles and steered operators, features wait for the core, multi-node sessions, prior art first, disagg proven by the tree's own test, tune after onboarding
How a run executes. Workers ran with the user's plugins and skills, ended their turn BLOCKED while a job queued, and built feature work on a core nobody had seen boot; operators steered by flooding the planner; a session could not span nodes; and the workers' source rule kept them from the tests, targets, kernel libraries and other engines that had solved their task. Disaggregation was proven by a witness whose second leg each run had to write, rebuilding a launcher the engine already ships; a KV-dtype variant needed an anchor no reference implementation can measure; and the tune campaign raced the onboarding it was meant to follow. Roles and operators - Roles load the run's own skills only. BackendConfig.plugins=False starts Codex with features.plugins and features.apps off; preflight's agent probe records the skills each backend's session loads, every role disables those the run does not ship, and the probe record keeps the list for a resumed run. - A job waiting in the spool is not the site's failure: the GPU-work section and the BLOCKED decisions say to work on and poll. A reopened task whose branch holds no commit the integration head lacks moves to that head; uncommitted edits stay. - `feedback` refuses a message over 1200 characters (evidence goes in a file it names). A message rides with the planner's next turn or the event window, `--now` wakes a turn at once, and one still waiting is read before the run is delivered. The README says the operator steers only through feedback and never cancels the run's own jobs. - Until a core boot check passes, the orchestrator holds back every assemble or feature task whose ref is a feature unit or a variant; kernel and investigate tasks are not held. The planner prompt says so. - The stall cap's help and docstrings say what resets it: a task done, a change landed or a contract check turning green. Sizing and nodes - environment.gpu_memory_gib states each device's memory. The intake lint reads the checkpoint's weight bytes (its safetensors index, else its files) and the fewest devices one engine's weights fit on (at most 60% of each device): member-too-narrow names a member below that width, disagg-placement (was disagg-two-nodes) whether disaggregation's two engines fit the nodes one gates session holds, and session-nodes-unneeded (info) a multi-node session no check needs. - A session of `nodes: N` is one allocation running its entry on each node, a watcher of the spool on every one. A job submitted with `--nodes N` (header `nodes=N`) holds N whole nodes of one allocation: the admitting watcher leads and records N-1 live peers, each drains and stops admitting GPU work, and once all are ready every node runs the script under MV2FLOW_JOB_NODES, MV2FLOW_JOB_NODE_RANK, MV2FLOW_JOB_HOSTS and MV2FLOW_JOB_MASTER. A failed part stops the others, a lost node fails the job, and the receipt waits for every part and names the first that failed. One multi-node job holds a spool's nodes at a time. Prior art first - A packaged skill, trtllm-modeling-v2-features, maps block reuse, chunked prefill, disaggregation, KV-cache dtype, CUDA graphs and the overlap scheduler, multimodal inputs and speculative decoding: what the engine owns and what the target must honour, where the code and tests are, a testing ladder from CPU checks to the flow's gates, and each proof's blind spots. Paths and symbols only; a test holds every path it names to the tree. The feature tag loads it. - Every worker is sent to the prior art before writing: TensorRT-LLM's unit, accuracy and perf tests (reproduce with one test through the spool, and start from their configurations rather than a new launcher, server, transport or harness), the ModelingV2 targets and built-in models, kernel libraries (FlashInfer, CUTLASS) and other engines (vLLM, SGLang). What is taken lands on this engine's terms: catalog entries, adapted code keeping its license header and naming its origin, values from the checkpoint, the HuggingFace reference as the ground truth of the math, source_embargo paths unread. - Prompts and the feature skill send an agent to a thing by the symbol that finds it and to tree_map.md, not by a fixed path; ModelingV2's own package and tests are one constant each (MODELING_V2_PACKAGE, CATALOG_TESTS_DIR). An embargo is set only when a request asks for one: in a product run everything is prior art. The tune campaign likewise renders an embargo only when one is set, and other engines' kernels and strategies are prior art its turns may adapt. - The planner plans no task that rebuilds what the engine and its tests provide and names the closest test and target; investigate reproduces in-tree first; the survey weighs other engines' kernels for each step's rung; a new kernel starts from the closest existing one; spec/INTAKE.md reads how other engines serve the model; an embargo says what it leaves open. Oracles - The witnesses (disagg equivalence, host_offload residency, kv_quant, decoder and encoder replay) and the logit gate are removed, with accuracy.witness, accuracy.logits, accuracy.boot.greedy, `anchor: pending`, `benchmark_members: sampled` and the witness-contrast lint rules. Each unit owes its boot and accuracy, a speculator its acceptance gate; an anchor not measured yet is a placeholder in reference_yaml. - disagg owes one check, gate `disagg` (checks/disagg.py): the target's disaggregated-serving accuracy test, written beside the tree's own (they serve through `trtllm-serve disaggregated`, launch_disaggregated_llm) and named by accuracy.disagg.test. The gate runs that node once, at the member the request validates fully, from its pytest root as CI does, on one node (the tree's launcher starts every worker on one host): two engines' devices at the member's width, at most a node's (accuracy.disagg.devices overrides, never past a node), under accuracy.disagg.env, and passes only when every test it selects passed: a skip fails it. The flow deploys nothing of its own, and a variant of disagg owes nothing. Lint and preflight block devices past a node; disagg-placement warns when two engines of the checkpoint do not fit the node (ENGINE_WEIGHT_FRACTION is 0.75: a 344-GiB checkpoint served two 277-GiB devices per engine). - derive names the node id beside the disagg_launcher anchor (Test<architecture>::test_auto_dtype) and takes the site's defaults.disagg; the lint notes a test not yet in the tree (disagg-test-pending) and leaves disagg out of the CUDA-graph rules, its test configuring its own engines. The requirements matrix treats the members the test does not run at, a variant of disagg and a pair of features as the spec's own choice; a member only disagg uses adds no column. - accuracy.anchor is `recorded` (a row of reference_yaml, a low placeholder until a measured one replaces it) or, for a configuration variant, `relative`: its unit's own score at the same member on the same target, the default for a variant that names no row of its own. The contract runs the unit's benchmark first (Check.after; verdicts keep the measured score); the floor is k x SE of the difference of the two runs. A variant's discriminators are layered over the unit's. Preflight refuses an anchor table the checkout holds uncommitted (each check reads it from a commit) and a relative variant whose unit's benchmark the contract does not run at its member. - derive builds the features a goal names (a drafter or tower the checkpoint carries and the goal does not is left out, and said), turns `kv=bf16/fp8/nvfp4` into a base dtype and one accuracy-only variant per other dtype, sizes max_batch_size to the goal's concurrency, and asks rather than guesses for accuracy.model_key (config.json names no model) and the concurrencies to tune at. - The planner's turn names the start member: the cheapest member one engine of the checkpoint fits, not tp1. - The tests are slimmed: merged where they set up the same thing, removed where another test asserts the same behavior. Tune - The campaign starts once onboarding is complete (every required check has passed), not after the core's inner checks, and the run is delivered when it ends (goal, budget or ideas spent); full support no longer tells it to wrap up. - It measures one baseline, which must serve the target (modeling_v2: require), and starts: no perf smoke, no stock reference (perf.reference), no noise repeats (perf.noise_repeats). perf.goal is ratio_to_baseline and/or pct_of_sol. With nothing kept, the wrap-up does not measure the baseline tree again. Signed-off-by: Wanli Jiang <35160485+Wanli-Jiang@users.noreply.github.com>
1 parent 23fe300 commit bb1be4f

130 files changed

Lines changed: 4233 additions & 8349 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎agent-flow/agent_flow/backends/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def create_backend(config: BackendConfig | str) -> Backend:
2828
reasoning_effort=effort,
2929
disabled_skills=disabled_skills,
3030
writable_roots=config.writable_roots if isinstance(config, BackendConfig) else (),
31+
plugins=config.plugins if isinstance(config, BackendConfig) else True,
3132
)
3233

3334
raise ValueError(f"Unknown backend: {kind!r}")

‎agent-flow/agent_flow/backends/codex.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,28 @@ def _disabled_skills_override(names: tuple[str, ...]) -> tuple[str, ...]:
234234
return (f"skills.config=[{entries}]",)
235235

236236

237+
#: The feature switches that keep a session's user-installed plugins and apps out of it.
238+
_NO_PLUGINS_OVERRIDES: tuple[str, ...] = ("features.plugins=false", "features.apps=false")
239+
240+
241+
def _config_overrides(disabled_skills: tuple[str, ...], plugins: bool) -> tuple[str, ...]:
242+
"""The app server's ``-c`` overrides: skills turned off, and plugins unless kept."""
243+
return _disabled_skills_override(disabled_skills) + (() if plugins else _NO_PLUGINS_OVERRIDES)
244+
245+
237246
class CodexBackend(Backend):
238247
def __init__(
239248
self,
240249
reasoning_effort: str | None = None,
241250
disabled_skills: tuple[str, ...] = (),
242251
writable_roots: tuple[str, ...] = (),
252+
plugins: bool = True,
243253
) -> None:
244254
self._transport: CodexTransport | None = None
245255
self._reasoning_effort = reasoning_effort
246256
self._disabled_skills = disabled_skills
247257
self._writable_roots = writable_roots
258+
self._plugins = plugins
248259
self._sandbox, self._approval = _SANDBOXES[0], _APPROVALS[0]
249260

250261
def version(self) -> str:
@@ -259,7 +270,7 @@ async def __aenter__(self) -> "CodexBackend":
259270
CodexConfig(
260271
codex_bin=_resolve_codex_bin(),
261272
experimental_api=True,
262-
config_overrides=_disabled_skills_override(self._disabled_skills),
273+
config_overrides=_config_overrides(self._disabled_skills, self._plugins),
263274
)
264275
)
265276
try:

‎agent-flow/agent_flow/config.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class BackendConfig:
2020
# Code's maximum, or the effort Codex's own configuration sets.
2121
reasoning_effort: str | None = None
2222
disabled_skills: tuple[str, ...] = ()
23+
# ``False`` runs Codex without the plugins and apps its user installed
24+
# (Slack, mail, drives...): an unattended session gets only the tools it
25+
# is configured with here. Claude Code takes plugins from its settings.
26+
plugins: bool = True
2327
tools: list[Any] | None = None
2428
# Native SDK hook configuration. Claude accepts HookMatcher callbacks.
2529
# Codex requires hooks to be configured and trusted in its native config;

‎agent-flow/agent_flow/workflows/trtllm_modeling_v2/README.md‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ The agent prepares the spec and launches the workflow; missing inputs must be re
1818

1919
**The agent writes the spec by following [spec/INTAKE.md](spec/INTAKE.md)**: `trtllm-modeling-v2 intake
2020
derive` writes a starting spec (no `site.yaml` needed), and `trtllm-modeling-v2 intake lint` checks
21-
it for slow or stalling choices (eager gates, a batch below the claimed concurrency, disaggregation
22-
wider than one node, variant cross products, variants that boot at every member, a feature proven
21+
it for slow or stalling choices (eager gates, a batch below the claimed concurrency, a member too
22+
narrow for one engine, disaggregation wider than a session, variant cross products, variants that
23+
boot at every member, a feature proven
2324
at several members or again under another axis, unusable accuracy anchors, open-ended boot probes) and blocks an accuracy check that runs without CUDA graphs and
2425
what would stop preflight (uncovered requested cells, a KV-cache dtype the engine does not load),
2526
and prints the contract's checks per unit and variant, the
@@ -54,6 +55,15 @@ backend model environment overrides, then the launching session. Claude uses its
5455
assistant model, which can lag a switch; Codex queries its live thread. If lookup is unavailable,
5556
set the model explicitly. Custom models and effort remain available through `agents.defaults` and
5657
`agents.roles` in [task.example.yaml](task.example.yaml). Model inheritance does not grant permissions.
58+
Roles load the run's own skills only: preflight's agent probe reads the skills a session would load
59+
and turns off the user's, and Codex roles run without the user's plugins and apps.
60+
61+
**While it runs**, the operator keeps the sessions alive and leaves the work to the run. Never cancel
62+
a job the run submitted (a gate, a worker's test) or run a replacement check beside it: a cancelled
63+
check proves nothing, runs again, and the planner never learns why. To change the direction, send
64+
`trtllm-modeling-v2 feedback --workspace <ws> "<what to change and why>"`: a few sentences (at most
65+
1200 characters) naming any evidence by its path, not status reports. A message rides with the
66+
planner's next turn; `--now` wakes it, for what must change before that.
5767

5868
## Design
5969

@@ -69,14 +79,16 @@ set the model explicitly. Custom models and effort remain available through `age
6979
4. **Resume:** checkpoints, decision identities and task receipts recover completed work without
7080
adopting another attempt's answer. Compute sessions own resource allocation and safe cancellation;
7181
the operator handles cluster allocations and session renewal.
72-
5. **Tune optionally:** tuning can start after core checks pass or run independently. Tuner proposals
73-
run in parallel; verification and keeps currently serialize. Local speedups need final cumulative
82+
5. **Tune optionally:** tuning starts once onboarding is complete (every required check has passed),
83+
or runs on its own (`trtllm-modeling-v2 tune`). It measures one baseline, with no smoke, stock
84+
reference or repeat, then starts the campaign; the run is delivered when the campaign ends. Tuner
85+
proposals run in parallel; verification and keeps currently serialize. Local speedups need final cumulative
7486
end-to-end validation. Results stay on a separate best branch, with `tune/summary.md`,
7587
`perf_ledger.jsonl` and `UNMERGED_OPTIMIZATIONS.md`; they are not merged into delivery automatically.
7688

77-
Current tuning retains configurable smoke, stock reference and noise repeats. A strict single
78-
baseline and parallel candidate measurement remain planned changes. Disaggregation currently uses a
79-
supplied contrast leg; through-the-hop accuracy is not implemented. Engine attestation still needs
89+
Parallel candidate measurement remains a planned change. Disaggregation is proven by the
90+
tree's own disaggregated-serving accuracy test for the target (`accuracy.disagg.test`), run as CI
91+
runs it; the flow deploys nothing of its own. Engine attestation still needs
8092
an internal rank hook where public APIs provide no resolved facts.
8193

8294
## Code map

‎agent-flow/agent_flow/workflows/trtllm_modeling_v2/agents/decisions.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class Decision:
5959
),
6060
Decision(
6161
"BLOCKED",
62-
"nothing in this turn can move the entry: the environment, or a prerequisite "
63-
"outside it; say which",
62+
"nothing in this turn can move the entry: the environment (a refused job or no "
63+
"session, never a job still queued), or a prerequisite outside it; say which",
6464
f"{_TO_PLANNER} with your summary",
6565
False,
6666
),
@@ -78,7 +78,8 @@ class Decision:
7878
"the work cannot go on in this turn: a callable no catalog entry covers "
7979
"(`blocked_reason: vocabulary_gap`, the callable in `missing_entry`), or what "
8080
"you lack (`knowledge_gap`), an accuracy you cannot close (`accuracy_shortfall`) "
81-
"or the site (`environment`). Block as soon as you know",
81+
"or the site (`environment`: a refused job or no session, never a job still "
82+
"queued). Block as soon as you know",
8283
f"{_TO_PLANNER} at once with `blocked_reason`, `missing_entry` and your "
8384
"summary: it adds the missing entry's kernel task and retries yours, or "
8485
"re-plans",

‎agent-flow/agent_flow/workflows/trtllm_modeling_v2/agents/prompts/_common.py‎

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,30 @@
1212
import re
1313
from typing import Sequence
1414

15+
from ...operators.coverage import CATALOG_TESTS_DIR, MODELING_V2_PACKAGE
16+
1517

1618
def tidy(text: str) -> str:
1719
"""Collapse the blank-line runs that composing blocks leaves behind."""
1820
return re.sub(r"\n{3,}", "\n\n", text).strip() + "\n"
1921

2022

21-
MODELING_V2_LAYOUT = """\
23+
MODELING_V2_LAYOUT = f"""\
2224
## ModelingV2: where things live
2325
24-
**Read `tensorrt_llm/_torch/_experimental/modeling_v2/README.md` first**: it
26+
**Read `{MODELING_V2_PACKAGE}/README.md` first**: it
2527
is the authoritative description of routing, layout, entries and gates, and
2628
`catalog/_op.py` states the entry contract. The source-level gates (no GPU)
27-
are `tests/unittest/_torch/modeling_v2/test_modeling_v2_*.py`.
28-
29-
The existing targets are gate-verified exemplars: **copy patterns, never
30-
values**; every model-specific value is re-derived from this checkpoint.
29+
are `{CATALOG_TESTS_DIR}/test_modeling_v2_*.py`.
30+
31+
The existing targets (`{MODELING_V2_PACKAGE}/models/`,
32+
one directory per family) are gate-verified exemplars, and reading them is
33+
part of the work. Unless `source_embargo` names one, find the targets that
34+
already solved what your task needs (the same attention kind, MoE routing,
35+
sparse or recurrent state, a vision tower, the cache state that reuse,
36+
chunking and disaggregation depend on) before you write: call or promote
37+
their entries, and follow their structure and their tests. **Copy patterns,
38+
never values**: every model-specific value is re-derived from this checkpoint.
3139
"""
3240

3341
MODELING_V2_SWITCH = """\
@@ -41,16 +49,36 @@ def tidy(text: str) -> str:
4149
"""
4250

4351
SOURCE_BOUNDARY = """\
44-
## Reading the engine
45-
46-
TensorRT-LLM's source, the built-in model zoo included, is an ordinary read.
47-
**Read to understand an interface — what an op expects, what the runtime
48-
allocates, which metadata field a kernel reads — never to copy a structure**:
49-
the zoo's forward is a module tree built on helpers no entry wraps, so a copy
50-
of it breaks the closed vocabulary, in which every op the forward reaches
51-
goes through an entry. A missing op is a missing entry. The HuggingFace
52-
reference is the ground truth of the **math**, never the shape of target
53-
code. Other inference engines' code is never a source.
52+
## Prior art: read widely, then build on this engine
53+
54+
Most of what a task needs has been done somewhere. Before you write it, find
55+
how others did it, and say in your report what you used:
56+
57+
- **TensorRT-LLM's tests**: the unit, accuracy and perf tests show working
58+
configurations, how each feature is deployed and tested, and the scores
59+
they reach (the reuse rule under How you work).
60+
- **TensorRT-LLM's models**: the ModelingV2 targets and the built-in models
61+
(the modules that call `register_auto_model`): how a model of this family
62+
is wired, loads its weights, binds its cache state, takes multimodal input
63+
and speculates.
64+
- **Kernel libraries**: the engine's own ops, FlashInfer, CUTLASS: the kernels
65+
the sourcing ladder reuses before anything is written.
66+
67+
`tree_map.md` in the workspace says where each part of this tree is in the
68+
checkout under test. A path you were given that is not there has moved: find
69+
what it defined by name (`git grep`), and trust the tree over any prompt.
70+
- **Other inference engines** (vLLM, SGLang, ...), from a checkout, an
71+
installed package or the web where you have one: often the first to serve
72+
a new architecture, so their model, kernel and deployment code is a map of
73+
its ops, layouts and feature choices.
74+
75+
What you take lands on this engine's terms. The target's forward calls
76+
catalog entries, so an op another implementation calls is an entry to reuse,
77+
wrap or write (the sourcing ladder), not code pasted into the forward. Code
78+
you adapt keeps its license header and names its origin. Values come from
79+
this checkpoint. The HuggingFace reference stays the ground truth of the
80+
math the gates judge: another implementation shows how, never what is
81+
correct. Paths in `source_embargo` stay unread.
5482
"""
5583

5684
EVIDENCE_DISCIPLINE = """\
@@ -163,9 +191,10 @@ def source_embargo_block(paths: Sequence[str]) -> str:
163191
"from them would prove nothing about whether this pipeline can derive one.\n"
164192
"\n" + "\n\n".join(running) + "\n"
165193
"\n"
166-
"Your references are the checkpoint itself (`config.json`, the weight index, "
167-
"the quantization config) and the HuggingFace `transformers` implementation of "
168-
"this architecture. Both are outside the embargo.\n"
194+
"Everything not listed stays open, and you are expected to use it: the "
195+
"checkpoint itself, the HuggingFace `transformers` implementation of this "
196+
"architecture, this tree's targets, models and tests, kernel libraries and other "
197+
"engines' implementations (Prior art).\n"
169198
)
170199

171200

‎agent-flow/agent_flow/workflows/trtllm_modeling_v2/agents/prompts/kernel.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ class KernelContext:
6161
KERNEL_SOURCES = """\
6262
## Where a kernel comes from
6363
64-
An op in `torch.ops.trtllm` is registered from Python (`tensorrt_llm/_torch/custom_ops/*.py`:
65-
the file name is its source) or from C++ (`cpp/tensorrt_llm/thop/*.cpp`), and grepping the op's
66-
name there finds it. A FlashInfer callable no op wraps is tier 3: the entry's `__call__` calls
64+
An op in `torch.ops.trtllm` is registered from Python (a `torch.library.custom_op("trtllm::...")`
65+
under the custom ops `tree_map.md` lists: the file name is its source) or from C++ (a
66+
`TORCH_LIBRARY_FRAGMENT(trtllm, ...)` / `TORCH_LIBRARY_IMPL(trtllm, ...)` block), and
67+
`git grep` for the op's name finds it. A FlashInfer callable no op wraps is tier 3: the entry's `__call__` calls
6768
`flashinfer.<module>.<name>` itself. What the entry certifies follows the source: a JIT-compiled
6869
kernel (CuTe DSL, Triton, FlashInfer) states the architecture it compiled for and that the JIT
6970
path ran; a compiled-in C++ kernel is in the wheel or not. Say which in the entry's `note`.

0 commit comments

Comments
 (0)