Open
[Feature]: PANKO for PyPTO-Pro — a multi-objective search-based Stage 5 auto-tuner for Pro kernels #326
Tomomasa YamasakiAdd on  28 days ago
Tomomasa Yamasaki
Tomomasa YamasakiCollaborators
28 days ago Create

Feature Description / 功能描述

Add pypto-pro-panko-manual, a search-based Stage 5 performance tuner for
PyPTO-Pro kernels, together with the pypto-pro-op-orchestrator gate that
records which Stage 5 optimizer ran.

This repository already has PANKO for classic PyPTO
(cannbot-skills/ops/pypto-op-perf-panko-manual). That tuner does not transfer
to PyPTO-Pro, because the two languages place on-chip buffers differently:

  • In classic PyPTO a tile is set_vec_tile_shapes(32, 512) and the compiler
    places the buffers.

  • In PyPTO-Pro the kernel writes both the shape and the address:

    t_vf = pl.make_tile_group(
        type=pl.TileType(shape=[HC, V], dtype=pl.DT_FP32,
                         target_memory=pl.MemorySpace.Vec),
        addrs=UB_VF, mutex_ids=[1])
    

    so changing one tile's extent invalidates every address after it, and the
    classic tuner's knobs and measurements have no Pro equivalent.

The proposed addition is a deterministic harness plus an agent, with a strict
split of ownership:

  • The harness owns action selection, address allocation, study state, acceptance,
    snapshots, accounting and stop decisions. It is a CLI over a persisted
    optimization/search_state.json, so a campaign survives interruption and can
    be audited after the fact.
  • Optuna TPE samples cube/vec TileType.shape coordinates only. Shape
    materialization then updates the required address map deterministically through
    an allocator; replacement addresses are never hand-written, and proven
    author-owned overlays are preserved.
  • The agent owns concrete structural proposals and the other numeric choices —
    buffer depth and mutex rotation, pipeline/preload, synchronization, launch
    configuration and case specialization.

It is multi-objective: latency and on-chip workspace bytes are both carried on a
Pareto front, rather than optimizing latency and discovering the capacity cost
afterwards.

Two properties of real Pro kernels drove most of the work:

  1. Factory form. Many delivered Pro kernels have no top-level @pl.jit; the
    kernel is built inside a factory that computes its extents. The editable
    region is therefore defined as the call-graph closure of the jit entries, not
    as a decorator list at module top level.
  2. Multi-file programs. A kernel's JIT entries and device helpers are often
    spread over several local modules. A version-2 program_manifest gives all of
    them one namespaced analysis view, one candidate hash and package-wide
    checkpoints, while the runtime modules keep their original imports and bytes.

The change is additive. It does not modify pypto-op-perf-panko-manual or
pypto-pro-op-perf-tune.

Use Case / 应用场景

Stage 5 performance tuning of a PyPTO-Pro kernel that has already passed
correctness verification, when the remaining gains depend on choices a human
would otherwise explore by hand: tile extents, buffer depth and mutex rotation,
preload and pipeline arrangement, and per-case specialization.

Concretely:

  1. A kernel whose tile extents are not literals. The extent is a function of
    factory arguments or a declared tiling-key field, so there is no number in the
    file to tune. INIT exposes the declaration, and TPE then searches the resolved
    shape domain.
  2. A kernel delivered as a package. For example a six-file attention kernel
    where one candidate changes three modules together. The campaign stages,
    evaluates and rolls back the whole program as one unit, and the test command
    stays the original import-based one.
  3. A campaign that must be resumable and auditable. The persisted state
    records which action was selected and why, what was measured, what was
    accepted, and which budget remains, so a long tuning run can be interrupted,
    inspected and continued without re-measuring.
  4. Reporting that distinguishes "searched and found nothing" from "could not
    search".
    INIT states the program it analyzed and whether the tile space can
    be drawn at all, so an empty search is visible before the budget is spent
    rather than after.

The intended caller is the pypto-pro-op-autotuner subagent under the existing
orchestration flow. It is not a replacement for pypto-pro-op-perf-tune, whose
knowledge cards and general methods remain the source of structural optimization
items; this is the search and measurement machinery around such changes.

Expected Behavior / 期望行为

Command surface. python scripts/panko_harness.py <command> over a persisted
campaign: status, init, normalize, select, block, feasible, record,
probe, evolve, close, stop, verify, pareto, report. status reads
stored facts without importing the optimization or device stack, and without
selecting, stopping, migrating state or restoring source.

Initialization.

  • INIT exposes declarations without changing accuracy or baseline performance.
    Recorded case bindings with unchanged runtime bytes are preferred.
  • Any runtime rewrite must pass normalization plus hash-bound device correctness
    and latency equivalence.
  • An unreadable live declaration or an empty required shape domain is refused,
    not hidden in order to start a campaign. Chip capacities are derived from the
    platform configuration and refused when they cannot be derived; they are never
    guessed or copied from another device.
  • When ordinary INIT refuses an input, a bounded repair path may propose a
    diagnosis; its result returns to ordinary INIT, which must accept the candidate
    before any search begins.

Search.

  • TPE owns cube/vec tile shapes only. Existing full-shape equality constraints
    couple source and destination tile parameters, so pl.move pairs are drawn
    together rather than independently.
  • Shape materialization deterministically updates the address map through the
    allocator. Author-owned overlays that tile shapes cannot re-derive keep their
    written addresses.
  • Acceptance and the selected base follow the Pareto front, not a
    "fastest-only" rule.
  • Accepted candidates are snapshotted, rejected candidates reverted, and the
    delivered program restored at STOP.

Measurement contract. Device, architecture, case, interpreter, test command,
objectives, warmup/runs, thresholds and budget are frozen for the campaign. The
latency objective is in-kernel AICore time attributed to exactly one op name, and
host code outside the kernel is frozen so that readings stay comparable across
candidates. A reading whose launch structure or op name disagrees with the pinned
campaign values is refused rather than recorded.

Reporting. Static coverage, actual TPE and device trial counts, final
verification and remaining gaps are reported separately. An empty or
single-anchor shape block is reported as such, not as successful shape tuning.

Additional Information / 附加信息

Where it lives

  • cannbot-skills/ops/pypto-pro-panko-manual/ — the skill: entry document, phase
    references, action catalog, and scripts/ (harness, source analysis, allocator,
    program bundle, measurement, chip profile, and the test suite).
  • cannbot-skills/plugins-official/pypto-pro-op-orchestrator/ — records which
    Stage 5 optimizer ran and gates on it.

Validation status (CPU only)

  • Full regression suite: 1,877 tests passing.
  • Multi-file packages: five packages and fifteen selected cases passed INIT
    readiness, shape-domain construction and real Optuna TPE sampling, and each
    passed a further TPE block after a real loop-structure edit. A six-file
    attention package exposed 57 declarations / 114 shape parameters, with one
    candidate changing three modules together and complete restoration after every
    trial.
  • Source integrity: 2,410 Python occurrences from the validation corpus were
    rehashed before and after; zero original-source changes.
  • Validation reports are included in the change under
    references/validation_*.md, with their own stated limits.

Known limits, stated deliberately

  • The validation above is CPU pipeline evidence. It is not NPU correctness,
    capacity or speedup evidence; correctness and timing callbacks returned
    synthetic observations, and CPU tests ran with an empty hardware envelope.
  • Joint-program preparation currently requires a fixed set of UTF-8 Python
    sources with statically resolvable acyclic local imports. Dynamic or escaping
    module access, local-scope or cyclic imports, star imports and unsupported
    class construction need explicit INIT repair.
  • Source-rewriting INIT repair across a whole package is not supported and is
    refused by name rather than approximated with the single-file helper.
  • An insufficient cluster budget, a single-anchor result or a bounded coverage
    failure does not by itself demonstrate meaningful TPE exploration.

Relationship to existing assets

  • pypto-op-perf-panko-manual (classic PyPTO PANKO) is unchanged, and no classic
    PyPTO knob or measurement is imported into a Pro campaign.
  • pypto-pro-op-perf-tune is unchanged.

Happy to split this into smaller reviewable pieces if the maintainers prefer —
for example the harness and skill first, and the multi-file package support as a
follow-up.

likedislike
Tomomasa YamasakiTomomasa YamasakiCollaborators
28 days ago Associated pull request
宋乐宋乐Collaborators
28 days ago Added label: Agent
宋乐
宋乐Collaborators
28 days ago Comments:

感谢贡献,请跟踪闭环

likedislike
leedongkun30-archleedongkun30-archCollaborators
23 days ago Associated pull request
Tomomasa YamasakiTomomasa YamasakiCollaborators
10 days ago Associated pull request
Tomomasa YamasakiTomomasa YamasakiCollaborators
10 days ago Associated pull request
Tomomasa YamasakiTomomasa YamasakiCollaborators
10 days ago Associated pull request
Tomomasa YamasakiTomomasa YamasakiCollaborators
10 days ago Associated pull request
leedongkun30-archleedongkun30-archCollaborators
5 days ago Associated pull request