Repository navigation
refactor(kernelforge): pass rewrite, orchestration and example-driver inputs as typed objects instead of parallel keywords - #1975
Conversation
Code metrics gate: PASSEDJudged: the 40 files this change touches. Files it does not touch never fail it; anything found there is listed under Outside this change for information.
Module length warning: over 800 lines, within the 1200-line failure limit (not failing): 1
93 findings in files this change does not touchOutside this change (informational): 93
...and 68 more; the job log lists every row.
Thresholds and sources: |
PR #1975 -- refactor(kernelforge): pass rewrite, orchestration and example-driver inputs as typed objects instead of parallel keywordsWhat it does: kernelforge's rewrite pipeline ( Blocking issues: none deferred: none Step 7 independent reader: a second reader re-checked the forge-rewrite-by-flydsl help and JSON contracts against the base, the Python 3.10/3.11 imports and the size breakdown (1370 + 747 + 377 = 2494) at head. Checked: LGTM |
…ndidate bench's never-passed knobs
…ackend and stage timeout knobs
…est; own OptimizeOptions in the optimize stage
…author it in one AuthoringTurn
…ngest one RewriteSubject
…nd FlydslMeasurement; drop the unused best commit and never-passed validation timeout
…llectedPatch and run each attempt from a brief and a turn
…ce, budget and apply-back switch in the rewrite layer
… from one AnalysisSession and read its inputs as AnalysisSources; build outcomes directly
…d; run every orchestration turn from one Turn
…tuned op and GEMM operands
cf56675 to
4206089
Compare
|
Retargeted to main after #1974 merged and rebased onto it (head 4206089). The 13 commits applied without conflicts and the code-metrics baseline needed no change. Re-verified at this head: code-metrics gate passes, the rewrite / orchestration / tier3 test files pass (235 tests), and CI is green (33 pass, 7 skipped). The earlier LGTM stands. |
chaojhou
left a comment
There was a problem hiding this comment.
PR #1975 -- refactor(kernelforge): pass rewrite, orchestration and example-driver inputs as typed objects instead of parallel keywords
What it does: brings the last kernelforge parameter-count targets under the limit. run_rewrite takes one RewriteRun built by forge-rewrite-by-flydsl; RewriteWorkspace / RewriteBudget / ApplybackSwitch / OptimizeOptions move from the CLI module into the rewrite layer; RewriteSpec carries framework; the orchestrator's turns, analysis session and specialist round each take one object; the example drivers take small case records; and parameters no caller passes or the body never read are deleted. No CLI flag, default, help text, JSON contract or KB identity changes.
Blocking issues: none
Non-blocking:
OptimizeOptions.profile_timeout_secdefaults to 1800 while the--profile-timeout-secoption that fills it defaults to 3600, andRewriteBudget.deadline_unixdefaults toNoneagainst the CLI's0.0. Only tests use the type defaults, but one value now has two defaults; the CLI-filled types would read better with none.preflight_reference(warmup=10, iters=30)keeps its knobs while the identical candidate values moved into_CANDIDATE_BENCH. The source and candidate must be timed the same way for the speedup to mean anything, so one shared constant for bothDriverModes would hold that rule in one place.- Every
kernelforge.clisubcommand (gemm-tune, forge-fuse, kernel-rewrite-controller, and the hyperloominstall.shprobe) now loads the rewrite package at startup, so an import error there would take all of them down. Worth one sentence beside the 17 ms note; the lazy imports left insideforge_rewrite_command.pyno longer avoid anything. knowledge/local_wiki/.../mori/operators/ep_dispatch_combine/tuning.md:136still names_combine_with_config, now_TunedOp.combine_with_config.
Checked: every positional construction of the new records against the old keyword order (DriverPreparation, PortRequest, ApplybackRequest, CollectedPatch, _AuthoringTurn, _AnalysisSession, _BundleIdentity, _BundleReading, SpecialistRound, FlydslMeasurement); defaults and the constants replacing deleted parameters (1800 s timeouts, 10/30 and 1/1 bench runs); RewriteSpec.framework (not serialised; KB identity and _infer_framework unchanged); the _build_outcome removal (replace reproduces the three exhausted branches); the mori capture move (the slice is a view, no kernel launch); consumers outside src/kernelforge (hyperloom reaches kernelforge only through the CLI; no doc or SKILL names a moved type); the CLI import closure (stdlib and kernelforge modules only, no import-time env or logging side effects) | Ran: --help, forge-rewrite-by-flydsl --help / --capabilities-json / --applyback-contract-json, forge-loop --help on base and head (byte-identical); the real forge-rewrite-by-flydsl through click's CliRunner on base and head with stubbed GPU/LLM stages in four modes (full options, defaults, --no-applyback --no-rewrite-kb, best moved off the PORT commit), recording PORT/OPTIMIZE argv, every KB write, resolve_identity, apply-back inputs and the result JSON (identical apart from the attempt-directory name); CI green at head. Not run: pytest (not installed here) and the example drivers (no GPU) | Base: d914a83 | Head: 4206089
LGTM
|
What this PR does Finishes the kernelforge parameter-count work by replacing the long parallel keyword lists in Blocking issues: none Checked, file by file against the merge base:
Not run: the kernelforge suite does not execute on the review host ( Not checked: Base LGTM |
Description: what and why
Finishes the kernelforge parameter-count work (
function-args> 5) inrewrite_by_flydsl,orchestratorand the example drivers. Values that travel together through the rewrite pipeline and the orchestration turns were carried as long keyword lists; each function now takes the object they belong to:run_rewritetakes oneRewriteRunthatforge-rewrite-by-flydslbuilds;RewriteWorkspace,RewriteBudget,ApplybackSwitchandOptimizeOptionsmove from the CLI module down into the rewrite layer that owns them (rewrite_by_flydsl/request.py,optimize.py);OptimizeRequest,PortRequest,DriverPreparation,DriverMode,RewriteSubject,RewriteKbTarget,FlydslMeasurement,ApplybackRequest,CollectedPatch,ResultScope/RewriteOutcome;RewriteSpecgains aframeworkfield soresolve_identityand the apply-back step read it from the spec; the KB helpers become methods of_RewriteKb.AnalysisSources,_BundleIdentity,_BundleReading,_AnalysisSessioninanalysis.py(callers buildAnalysisOutcomedirectly instead of through the_build_outcomeforwarder);SpecialistRoundincontracts.py, shared by orchestration andplan_critic.review; one_Turnfor every orchestration turn._Case; the mori driver uses_TunedOp,_CorrectnessCase,_BenchPlan; the mxfp8 driver uses_Activation/_Weights/_Routing.No
**kwargs, untyped dict, compatibility shim or new fallback branch is added; every call site is updated.Scope: the 50 remaining functions over the limit in those directories (Triton/Gluon
@jitkernels excluded); 49 are done._grouped_gemm_mxfp8(13) keeps its signature: it is the source kernel the rewrite example ports from, named by--source-entryinrun_example.sh, mirroring SGLang's host API, and its source text feeds the port agent and the KB source identity.Gate count of functions over the parameter limit (
function-argsentries inscripts/code_metrics_baseline.txt): 256 on main -> 215 (-41; the 8 example-driver functions are outside the gate's scope); the cyclomatic-complexity entries and the broad-exceptcount are unchanged.Linked issue(s): none.
Tests: added/updated? commands run?
write_flydsl_kb_solution(best_commit=), an argument the function never read; where it mattered the equivalentsession_keyis asserted instead.test_forge_orchestration.pygains a shared fixture so the touched tests do not duplicate setup.python -m kernelforge.cli <cmd> --helpfor the root command,forge-loop,forge-rewrite-by-flydsl,forge-fuse,kernel-rewrite-controller,roofline-ceiling,gemm-tune run, andforge-rewrite-by-flydsl --capabilities-json/--applyback-contract-jsonare byte-identical to main. Two failingforge-rewrite-by-flydslruns (missing source, missing driver) give the same stdout and result JSON as the base apart from the random attempt-directory name.python:3.10-slimandpython:3.11-slim(the CLI module needsclick, absent from the slim image). The 4 changed example drivers compile on both versions; they need torch and GPUs to run, which were not available for this change.PYTHONPATH=src(never the full suite): 34 related test files, 1336 passed.ruff check/ruff format --checkon the changed files; import-linter keeps all 7 contracts;python scripts/code_metrics.py --base-ref origin/mainPASSED; baseline lowered with--update-baseline.Size/complexity triggers crossed: split, or why the shape is right:
Diff budget: 2494 production Python lines changed (+1120 / -1374 in 23 production
.pyfiles): rewrite 1370 (includingcli/forge_rewrite_command.py), orchestrator 747 (includingloop/analysis_runtime.py), examples 377. One concern (the last kernelforge parameter-count targets). Each commit touches at most 5 production files and is grouped by module. The code-metrics gate passes without a waiver.If this simplifies or refactors: which mechanism was removed, which contract was preserved, and the tests that show it:
Removed: the keyword lists threaded through the rewrite stages and orchestration turns, the
_build_outcomeforwarder, and the option dataclasses' detour through the CLI module. Preserved: theforge-rewrite-by-flydslCLI and JSON contracts used by AgentKernelArena (above), the KB records and identities, and each example's documented command.Deleted parameters (checked across src, scripts, docs, examples and tests):
run_port_loop(kernel_backend=, validate_stage_timeout_sec=)andpreflight_candidate(warmup=, iters=)(never passed);try_flydsl_kb_warmstart(validation_timeout_sec=)(only one test passed it, with the default 1800);write_flydsl_kb_solution(best_commit=)(never read).Observable effect: what an operator will now see, and what the old behaviour cost them (if none, why the change is unobservable):
None: no CLI flag, default, help text, JSON contract, output file or log line changes.
kernelforge.clinow imports the rewrite package at startup because the rewrite option types live there (about 17 ms). In the mori example driver one input slice moved from inside the graph-capture block to just before it; slicing launches no GPU work, so the captured graph is the same.Breaking changes: yes, for Python callers only: the refactored functions take their typed objects, and
RewriteWorkspace/RewriteBudget/ApplybackSwitch/OptimizeOptionslive inkernelforge.rewrite_by_flydsl.request/.optimizeinstead of the CLI module. The CLI is unchanged. Every in-tree caller is updated.PR addresses single concern: yes (parameter count of
rewrite_by_flydsl,orchestratorand the example drivers).Root cause is upstream (Magpie/TraceLens/GEAK/IntelliKit/AgentKernelArena), ticket filed: n/a.