Repository navigation
Conversation
Adds mode=mega to kernel_lane.js. Mega runs the lane's own phases and its Optimize round (plan -> engineer -> verify -> select -> memory). Each phase and round step keeps one agent call for every mode: under MODE === 'mega' it gets the mega inputs, schema and timeouts, and mega steps run before/after it (e.g. megaAfterAnalyze, megaEngineerTurn/after, verifyStep/after, megaStateWrite/megaCheckStateWrite). Roles are the lane's role files plus roles/_fragments/<role>_mega.md, whose sections replace the same-named sections. optimize/author prompts and results are byte-identical to main (scripts/tests/test_lane_golden.py). The AMD-AGI#539 package (perf_knowledge/expert_skills/expert_workflows/mega_fusion/) is left unchanged; its knowledge, tools, scripts and tests are copied under kernel_workflow/ and the package is removed in a follow-up PR. CI runs kernel_workflow/tests in their own steps (file names repeat the package's). Also: - several candidate lanes per round (mega_directions_per_round); - mega_graph_ab deletes per-rank output tensors when a run ends; - the prior-reuse leak check skips a candidate built on this run's own candidate; - finalist identity compares commits, not SHA strings (short vs full); - check_mega_identity passes rows the lane only excluded locally when they are byte-identical; the engineer excludes file patterns, not source dirs; - the mega planner gets a mode=mega opening and specialties section; - the lane version leaves out the fast-test cache, the chain-debt tracker, route-only mode and the strict-autonomy proof runs.
…very rank A pipeline (e.g. KernelFusion for an L3 MegaKernel region, or the e2e kernel track) can now hand mode=mega a multi-rank operator as a region UT task dir: the caller passes only region_ut (= kernel_path), gpu_ids and gpus_per_job. mode=mega (kernel_lane.js): - tools/region_ut_args.py turns the UT's meta.json into the mega args the caller left unset (its unittest.py as benchmark, case sigs as guards and accuracy cases, the case tolerances, the bound modules, a positive control inside kernel_src/); an arg the caller passed wins. Read once, before any mega arg is parsed. - every mode=mega role also reads knowledge/mega_region_ut.md: only kernel_src/ may change, the UT's unittest.py is the benchmark and the accuracy verdict, the engineer writes kernel_src/_handback/support.json and notes.md. Without region_ut no prompt changes (8 mega replays identical). e2e UT harness (e2e_workflow/scripts): - meta.world_size > 1: every leg runs under torchrun on the leased GPU set; time is the slowest rank (per_rank_ms kept), run_correctness_ranks checks every rank's outputs against the baseline leg's, eager and under one captured graph per case; cases.setup_dist / teardown_dist hooks. - meta.correct_metric "rel_l2" and a per-case tol, for operators whose stock output is not elementwise reproducible. - candidate_bind may be a list (one entry per module of a region); the integrator replays it entry by entry. Single-rank tasks run exactly as before.
…ked re-run dir keeps the task dir off sys.path Found on card (MegaMoE region UT, EP4 on 4 GPUs): a multi-rank task builds its inputs per rank, so listing its cases needs the process group (list now runs under torchrun too); and a hand-back re-run dir that symlinks the task's files put the task dir (with its unittest.py) on sys.path, shadowing stdlib unittest.
…mode=mega's finalist gate Found by an on-card mode=mega flow run on a MegaMoE region UT (EP4): the candidate was correct (bit-exact on 4 ranks) and 1.13x on the heaviest case, but no finalist could pass, because every case was a target guard (a case the implementation declares a refusal for, at stock speed, failed the target readout) and the UT gave no replay count for the liveness gate. - region_ut_args.py: the heaviest case is the target; the others are regression guards with a 2% floor; required_replays comes from the UT's meta.graph_replays. - leg_runner check: meta.graph_replays more replays of each case's captured graph, cycling through the draws, every one checked on every rank (graph_replays in the result); mega_region_ut.md: the UT's GRAPH_REPLAYS line is the liveness evidence.
…heck (never n/a) Found by the second on-card flow run: the verifier reported graph_safe n/a for a config-only candidate, which the finalist gate reads as not graph-safe, though the UT had captured and replayed the seam 256 times on every rank.
…inalists measure every guard to its pair count Found by the third on-card flow run on a MegaMoE region UT (EP4): the finalist (3 launches, 1.087x, correct on 4 ranks) was rejected because the registry head was short (41ff2d2) and the director reported the full SHA (the identity check was fixed for this in 70ec987dc, the final verdict was not), and because the director measured the regression guard with 3 pairs where REQUIRED_PAIRS is 5.
…ere (delivery, finalist rows, verify) Found by the certify-only on-card run on a MegaMoE region UT (EP4): finalist re-test, identity check (all 56 tree rows equal), report and director validate all passed (1.09x on the target case, validation accepted), yet nothing was delivered: the delivery check compared the director's full source SHA with the registry's short one as strings. The finalist-row and verify head checks had the same flaw. sameCommit also accepts two equal non-hex strings. Replays: 7 of 8 identical; gen64 now keeps a candidate whose verify reported the full SHA of its short registry head as scored (it was wrongly left runnable), so that replay diverges from round 3 on.
Resolve conflicts with AMD-AGI#636 (batched UT timing, multi-GPU per-rank receipts): - leg_runner/harness_lib: multi-rank legs on the timing_specs/make_timing_case API; list is metadata only and single-process; time mode follows --sigs on every rank. - kernel_lane: per-call timeouts default to AGENT_WAIT_MS; mode=mega keeps its own schemas and does not take the UT_MR path. - test_lane_golden: size cap uses the 4 KiB margin of test_workflow_script_size.js.
…tract format; drop the e2e multi-rank harness region_ut_args.py now reads the fields KernelFusion writes: acceptance.tol (the UT's own error units) as the accuracy bound, per-case regression floors widened by run/self_noise.json, and the UT's graph-case --iters as the replay count. mega_region_ut.md follows that UT's runner and output (mp_harness ranks, ORACLE/RANDOM/SERVED gates, case lines, ut_result.json). A KernelFusion UT runs its ranks through its own mp_harness.py, so the torchrun legs, per-rank check mode and list candidate_bind in leg_runner/harness_lib (and their test) are reverted to main.
… as well as a KernelFusion one region_ut_args.py reads either format GEAK produces: cases from meta.cases or meta.workload.cases (weight, else effective_calls), the bound from acceptance.tol or meta.tol, graph cases from regime or phase_regimes. The replay evidence is the UT's own: --iters when its runner has it, else its one refreshed-input replay per graph case; the search-time liveness check uses at most required_replays. mega_region_ut.md describes both UTs' runs and outputs.
…ut into one unified contract mode=mega no longer requires a fixed UT format. Before any mega arg is read, the region UT adapter reads the UT and writes <region_ut>.mega_ut.json: the mega args plus how to run and read the UT (command, GPU count, editable files, verdict, per-case times, replay evidence, null arm). mega_region_ut.md fixes the contract's fields and the adapter's limits; region_ut_args.py is its starting point for the layouts GEAK produces. The lane refuses a contract without a benchmark or a target guard, and every mode=mega role reads the contract.
…baseline run; a wrapper never decides validation The benchmark engineer checks the adapter's contract against the unchanged code on its first run (verdict PASS, every case timed on both legs, headline and replay evidence where the contract says) and stops Setup otherwise. When the benchmark is a wrapper, the director also runs the UT's own command on the final patch, and that verdict counts.
…t_lane_refs reads one per line)
MEGA_BENCH/VERIFY/PLAN_BASE/ANALYZE_BASE/MEMORY_SCHEMA spread the lane schema and keep only the fields mega adds or redefines. Every schema an agent receives is the same object (replays: same fields, key order only).
…a/ folders tools/*.py and scripts/replay_runs.js move to scripts/mega/, the mode=mega knowledge files to knowledge/mega/; every reference (lane prompts, role fragments, knowledge, tests, README) follows. tests/test_mega_paths.js checks that every workflow path mode=mega hands an agent exists. Replays: same calls and results; prompts differ only in these paths.
|
Thanks for the work on integrating mega mode into the unified kernel workflow. I agree with the overall direction, but have a few concerns regarding the implementation:
Overall, I would prefer to keep the core workflow and roles as generic as possible, maximize the reuse of existing components, and introduce task-specific capabilities through modular skills rather than modifying the main workflow extensively. |
feat(kernel_workflow): run mode=mega on the kernel_lane lifecycle
Summary
mode=megaoptimizes a multi-rank operator as one fused kernel: e.g. an EP MoE block whose dispatch,GEMMs and combine across all GPUs become one persistent kernel.
mode=optimizemakes one kernel faster;mega replaces a whole multi-kernel, multi-GPU region, which needs more than one candidate in flight,
backtracking, and stricter acceptance (a fused multi-rank kernel can deadlock, read stale data, or win only
inside the noise).
#539 added mega as a self-contained workflow under
perf_knowledge/expert_skills/expert_workflows/mega_fusion/(its own workflow script, roles and loop).This PR moves it onto
kernel_lane.js, so mega and optimize/author share one lifecycle, one set of agentcalls and one set of roles. The #539 package is left unchanged here; removing it is a follow-up PR.
kernel_lane.jssetsMEGA = MODE === 'mega'. Setup, Analyze, Benchmark, Profile,the Optimize loop, Report and Validate are the lane's own phases; each calls a mega hook only under
MEGA.and timeouts to the same call and runs its steps before/after it.
roles/<role>.mdplusroles/_fragments/<role>_mega.md; a fragmentsection replaces the same-named section. Main's role files are unchanged.
region_ut): mega can take a UT task dir of any layout (see below).What changed, where
kernel_lane.js(+5,956 / −1,170)MEGAflag;roleAgentreads the mega fragment;agentTper-call timeout options; at each shared call theMEGA ?inputs/schema/options and the call to the mega hook// mode=mega backendsectionThe calls mega shares and what it adds around each:
directorsetupmegaAfterSetup(mega checks, resume fromstate_dir)tech_leadanalyzemegaAnalyzeInputs;megaAfterAnalyze(contract check + one full re-run, task graph, ladder)benchmark_engineersetupmegaBenchInputs;megaAfterBenchmark(recover a baseline left on disk);megaCalibrate(positive/null control)profile_engineerbaselinemegaAfterProfile(MoE analysis skill)tech_leadplan_roundmegaPlanPrompt;megaPlanStep(direction checks, candidate-lane binding)megaEngineerTurn(one candidate lane in its own tree); after: recover, recordverify_engineerverifyverifyStep(structure check, inputs); after: score, recover, recordmegaSelectCandidate(best eligible candidate from the registry; candidates are never merged)tech_leadupdate_memorymegaStateWrite/megaCheckStateWrite(registry to STATE.json, read back)megaStopRule(modeled clock, deliverable)tech_leadreport /directorvalidatemegaReportInputs/megaValidateInputs;megaFinish(finalist re-test, identity check, delivery)Why mega needs its own code, and what is shared
Shared with optimize: every phase and round call, the role files (mega adds fragments), the lane's schemas
(mega extends them), the GPU lease, the stop/budget machinery.
Outside
kernel_lane.jskernel_workflow.jsmode=megagoes tokernel_lane.jsroles/_fragments/*_mega.md(7)knowledge/mega/(14)knowledge/collectors/,knowledge/analysis_skills/knowledge/amd_instinct.md,hip_optimization.mdknowledge/mega/scripts/mega/(10)scripts/multi_rank_analysis/tests/(54)kernel_lane.jsscripts/tests/test_lane_golden.py+ fixtureskernel_workflow/testsin its own pytest/node steps (file names repeat the #539 package's)Most of the non-lane lines are copied from the #539 package and go away with it in the follow-up PR.
Region UT input
region_ut: a caller passes a UT task dir (any layout) and the GPU set. Before Setup, a region UTadapter agent reads the UT and writes one unified contract beside it (
<region_ut>.mega_ut.json): themega args (benchmark, target and regression guards with noise-aware floors, accuracy bound in the UT's
own units, replay count, bound module, positive control) and how to run and read the UT (command and GPU
count, editable files, correctness verdict, per-case times, replay evidence, null arm).
knowledge/mega/mega_region_ut.mdfixes the contract's fieldsand the adapter's limits (adapt, never weaken the UT's own check or tolerance; a wrapper beside the UT
when something is missing, never inside it).
scripts/mega/region_ut_args.pygives the adapter astarting contract for the UT layouts GEAK already produces.
benchmark engineer proves the contract on the first baseline run (verdict PASS, every case timed on both
legs, headline and replay evidence where the contract says) or stops Setup; when the benchmark is a
wrapper, the director also runs the UT's own command on the final patch and that verdict counts.
their patch plus
support.json/notes.md.Fixes found on-card
and delivery;
check_mega_identitypasses rows the lane only excluded locally (.git/info/exclude) when they arebyte-identical; the engineer fragment excludes file patterns, not source directories;
mega_graph_abdeletes its per-rank output tensors when a run ends.Results (EP8 MegaMoE, 8× MI355X, no Expert Skill)
Performance matches the version before the refactor:
Tests
scripts/tests/test_lane_golden.pyreplays 5 lane scenarios; prompts andresults are byte-identical to main.
and results, except one (gen64) from its round 3 on, where a candidate is now correctly scored (the
commit-comparison fix above).
kernel_workflow/tests/(JS + Python, incl.test_mega_paths.js: every workflow path mega hands an agentexists),
test_mode_dispatch.js,test_fast_mode_off_identical.js,test_lane_refs.py,test_workflow_script_size.js, the L0 unit pytest: pass, except tests that fail on main too.on card (verdict, per-case times, headline, replay evidence), and a broken candidate reads FAIL.
Notes
kernel_lane.jsis 519,185 B, under the workflow tool's limit with the 4 KiB margin oftest_workflow_script_size.js(≈1 KB left). To fit, 159 of main's comments inkernel_lane.jsareshortened (≈60 KB); no code or prompt text is changed by that. The advisory growth check will warn.
expert_workflows/mega_fusion/stays as is in this PR, so mega knowledge/tools/tests exist twice untilthe follow-up PR removes the package.
relies on them; they follow separately.