Agent skill

Mpk Lever Cleanup

by mirage-project in mirage-project/mirage

A skill your agent uses when a batch of env-gated (ifdef MPKDSV3 / os.environ-controlled, default-OFF) MPK optimization levers needs to be consolidated into a single clean code path for a PR…

Apache-2.0Auto-check passedDevelopment

Install Mpk Lever Cleanup

skills CLI
$ npx skills add mirage-project/mirage --skill mpk-lever-cleanup -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install mirage-project/mirage mpk-lever-cleanup --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/mirage-project/mirage.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/mpk-lever-cleanup .claude/skills/mpk-lever-cleanup && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
mpk-lever-cleanup
GitHub stars
2.5k
Token cost
~2.2k tokens
SKILL.md length
1,053 words
Files
1
Skills in repo
24
Repo updated
First seen
Licence
Apache-2.0

At a glance

A skill your agent uses when a batch of env-gated (ifdef MPKDSV3 / os.environ-controlled, default-OFF) MPK optimization levers needs to be consolidated into a single clean code path for a PR…

  • Works in 7 steps: Enumerate all gates → Classify every gate (VERIFY each one —… → Codex-vet the classification + refactor… → …
  • A batch of env-gated (ifdef MPKDSV3 / os.environ-controlled
  • SKILL.md covers Procedure (7 steps, in order) and Key pitfalls (all hit in…
  • Calls git

What it does

Mpk Lever Cleanup is an agent skill from mirage-project/mirage. Use when a batch of env-gated (ifdef MPKDSV3 / os.environ-controlled, default-OFF) MPK optimization levers needs to be consolidated into a single clean code path for a PR: hard-wire every winning lever as the default, delete the legacy else branches, remove the env vars that select new-vs-old logic, revert dead levers that measured KILL/NULL/regress, delete diagnostic probes, then commit one clean version. Applies to the wrap-up stage where the optimization work has settled and is being merged to mainline. Not…

Its SKILL.md is about 2.2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Code quality. The repository describes itself as: Mirage Persistent Kernel: Compiling LLMs into a MegaKernel. The licence is Apache-2.0.

When your agent uses it

  • A batch of env-gated (ifdef MPKDSV3 / os.environ-controlled
  • Delete the legacy else branches
  • Remove the env vars that select new-vs-old logic
  • Revert dead levers that measured KILL/NULL/regress

Example prompts

  • “/mpk-lever-cleanup”

Workflow steps

7 steps, taken from the step headings in SKILL.md.

  1. Enumerate all gates
  2. Classify every gate (VERIFY each one — never assume default-OFF)
  3. Codex-vet the classification + refactor plan
  4. Freeze the reference (the correctness comparison baseline)
  5. Execute in the safe order (build-check after every step)
  6. Verify correctness (the default path's math has changed)
  7. Commit one clean version (for the PR)

What it can do on your machine

Read from SKILL.md and the folder at commit f9eb70c. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • git

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Mpk Lever Cleanup loads about 2.2k tokens when it runs. Until then it costs about 165 tokens; SKILL.md has 1,053 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~165
When it runs · the whole SKILL.md, loaded when a task matches
~2.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from mirage-project/mirage at commit f9eb70c, republished under its Apache-2.0 licence (© mirage-project). 1,053 words, ~2,206 tokens.

Download SKILL.mdSave it as .claude/skills/mpk-lever-cleanup/SKILL.md (or your agent's skills folder).
name
mpk-lever-cleanup
description
Use when a batch of env-gated (`#ifdef MPK_DSV3_*` / `os.environ`-controlled, default-OFF) MPK optimization levers needs to be consolidated into a single clean code path for a PR: hard-wire every winning lever as the default, delete the legacy `#else` branches, remove the env vars that select new-vs-old logic, revert dead levers that measured KILL/NULL/regress, delete diagnostic probes, then commit one clean version. Applies to the wrap-up stage where the optimization work has settled and is being merged to mainline. Not for the exploration phase (levers should stay env-gated default-OFF there) or for runtime/execution-model changes.
tags
mpk, cleanup, refactor, pr
related_skills
mpk-internals, add-mpk-task
version
1.0.0

MPK Lever Cleanup — consolidate env-gated optimizations into one clean path

During exploration, every MPK performance optimization is an env-gated, default-OFF lever (#if MPK_DSV3_XXX + the #else legacy path + os.environ.get(...) → -D injection in persistent_kernel.py). Once the work has settled and is headed for mainline, the levers must be consolidated into a single path: hard-wire the winners as the default, delete the legacy code, remove the control variables. This skill is the complete procedure — plus the pitfalls actually hit — from that wrap-up refactor.

Core mindset: this is a refactor that intentionally changes the default build — the default path flips from "the safe legacy logic" to "the optimized path". The usual "default build must stay byte-identical" commit gate is therefore deliberately waived here; that is the whole point of this commit.

Procedure (7 steps, in order)

1. Enumerate all gates
bash
grep -rhoE "MPK_(DSV3_)?[A-Z0-9_]+" <the megakernel .cuh files> <builder.py> <persistent_kernel.py> \
  | sort -u | grep -vE "MPK_(MAX|PAGE|PROFILING|NUM)"

List both the #ifdef gates in the .cuh files and the os.environ/-D injections in persistent_kernel.py.

2. Classify every gate (VERIFY each one — never assume default-OFF)
ClassActionHow to decide
WINHard-wire ON: remove the gate + delete the #else legacy + remove the env injection; keep the geometry guard (TP8/mbt/workers)Lever already committed in git log + a WIN row in experiment_history
DEADFully revert (delete all of its code; roll back any ABI it changed)A KILL/NULL/REGRESS row in experiment_history
DIAGNOSTICDelete (probe/no-op/poison/xor — not a lever)Name contains PROBE/NOOP/POISON/XOR; used only for measurement
ALREADY-ONConfirm it is still present; keep it as the unconditional default (do not add a gate)grep persistent_kernel.py: is it already injected via -D unconditionally?
LEAVE-UNTOUCHEDDo not touchA fallback outside this path (e.g. the TP<8 ROUTER_GEMV), inert, or a generic non-DSv3 flag

⚠️ Classification must be verified, never recalled from memory. Pitfalls actually hit: TOPK_PARALLEL, assumed default-OFF and slated for revert, is in fact ON in every decode build (part of the current winning stack — KEEP); ROUTER_GEMV, assumed obsolete, is in fact the router of the TP<8 fallback (must not be deleted). Use grep -n on the injection condition in persistent_kernel.py and check whether the gate is actually exercised at the production geometry.

3. Codex-vet the classification + refactor plan

Hand the gate inventory + classification + goal to Codex (mcp__codex__codex) for a multi-round discussion: validate the classification, agree on a safe execution order, the correctness risks, how to verify the ABI-revert, and the structural-vs-leaf distinction. Codex will catch conflicts in the classification (see the step-2 pitfalls).

4. Freeze the reference (the correctness comparison baseline)

Before changing anything, run the current winning stack (all levers ON) and record its output: e2e tpot + logits/prose (run it twice to get the A/A nondeterminism envelope). The final "clean default build" is compared against this winning-stack reference, not against the old safe default.

5. Execute in the safe order (build-check after every step)
  1. First revert the dead levers that changed the ABI (most dangerous; do it in isolation and verify). If a dead lever touched the (num_in,num_out,TASK_ENUM,variant) tuple in graph.cc/task_register or added a tensor, a single ABI mismatch = "Invalid global read" at runtime. If those changes were never committed, simply git checkout HEAD -- <producer files> to return to a clean ABI, then:
    bash
    git diff HEAD -- graph.cc task_register.cc tasks.py multigpu.py allreduce.cuh | wc -l   # expect ≈ 0
    grep -rn "tile_sumsq|<sidecar tokens>|input_ptrs\[N\]" <files>                          # expect 0
    Delete the dead lever's consumer half at the same time (otherwise it is a stale-env out-of-bounds landmine).
  2. Delete the remaining dead levers + all diagnostic probes → build-check.
  3. Hard-wire the LEAF wins (leaf optimizations with a clean #else): remove the gate, delete the #else, keep the geometry guard → build-check.
  4. Hard-wire the STRUCTURAL wins last (path-selectors that change the graph shape / large control flow): delete the entire alternate path, keep the TP8/mbt/workers guard → build-check + a --layers 0-3 in-MPK smoke. (Structural gates are more dangerous than leaves — removing one deletes a whole alternate code path. Do it after the tree has already shrunk.)
Show full SKILL.md (435 more words)Show less
6. Verify correctness (the default path's math has changed)
  • Token-identity cannot be used (DSv3 TP8 decode is FP-nondeterministic — cross-CTA atomicAdd).
  • Use instead: the A/A envelope (winning stack compared against itself) + clean default vs the winning-stack reference with the per-step logit-cosine inside the envelope + stable top-k overlap + 512 tokens of coherent prose + no NaN/Inf.
  • Perf smoke: e2e tpot should ≈ the winning-stack reference (confirms no win was silently dropped).
  • TP8 JIT smoke: --layers 0-3 confirms the hard-wired megakernel really instantiates and runs (the #else-deleted path only instantiates at world_size==8).
  • Qwen3 / TP4 regression smokes protect the untouched fallback / non-DSv3 paths.
7. Commit one clean version (for the PR)
  • Stage source files only (kernels/.cuh, builder.py, persistent_kernel.py, task_register.cc); exclude .claude/, scratch/, experiment_history/, CSVs/outputs/.pk_compile and other local artifacts.
  • Run mpk-commit-reviewer and tell it explicitly that the default-build change is intentional (otherwise it will BLOCK per the standard gate); it still checks staged-path hygiene, the allowed surface, the message, and the correctness story.
  • The commit message lists everything: which levers were hard-wired (+ each one's Δ), which dead levers were reverted, which diagnostics were deleted, that the ABI was restored, the verification evidence, and an explicit pre-merge gate (if TP8 runtime validation was blocked by box capacity, write it into the message as a must-run item before merging). Include Co-Authored-By.

Key pitfalls (all hit in practice)

  • The default build is intentionally NOT byte-identical — that is the goal, not a bug; waive that one commit gate.
  • The ABI-revert is the most dangerous step — do it first and in isolation, grep it clean, diff against the last clean commit, and delete the consumer half together with it.
  • Structural wins go last — a path-selector is more dangerous than a leaf-opt (removing it deletes an entire alternate path).
  • Classification must be verified — some gates are already unconditionally ON, some are fallbacks; never assume "default-OFF".
  • Orphaned legacy functions — after deleting the #else call site, the __device__ function definition may remain (nvcc elides it; harmless but unclean); either delete it or flag it as a known nit in the PR.
  • The correctness gate = A/A envelope + coherence, not token-identity (the path is FP-nondeterministic).
  • The TP8 runtime gate may be blocked by box capacity — a commit meant for PR review may land with a documented pre-merge gate (a PR is review, not auto-merge); never fabricate numbers.
  • Sub-agents can contradict each other about the same fact (e.g. "the lever was deleted" vs "the lever was hard-wired") — verify yourself with grep -c <the win's body symbol> that the win's body is still present (zero refs to the macro ≠ the win was deleted; possibly only the gate was removed and the body became unconditional).

© mirage-project, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/mpk-lever-cleanup of mirage-project/mirage.

Open the folder on GitHubat commit f9eb70c

Compare with similar skills

Mpk Lever Cleanup next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Mpk Lever Cleanup compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Mpk Lever Cleanup this skillmirage-project/mirage2.5k—~2.2kAutomated safety check: PassApache-2.0
WooCommerce Code Reviewwoocommerce/woocommerce11k3 repos~1.1kAutomated safety check: PassCustom licence
Ponytail Lazy Developer ModeDietrichGebert/ponytail160k1 repos~873Automated safety check: PassMIT
Systematic Code Refactoringluongnv89/claude-howto42k—~3kAutomated safety check: PassMIT
Install Anti-Slop Oxlint Rulesdmmulroy/anti-slop5.4k—~2.2kAutomated safety check: PassMIT
Constraint-Driven Developmentaddyosmani/agent-skills105k2 repos~5.2kAutomated safety check: PassMIT

Similar skills

  • WooCommerce Code Review

    woocommerce/woocommerce

    Reviews WooCommerce code changes against the project's standards, flagging backend PHP architecture, naming, documentation, data integrity and testing violations.

    11k GitHub starsUsed in 3 repos~1.1k tokens
    DevelopmentAuto-check passed
  • Ponytail Lazy Developer Mode

    DietrichGebert/ponytail

    Makes the agent pick the laziest solution that works: skip unneeded work, reuse what exists, prefer the standard library and platform features, and keep diffs small.

    160k GitHub starsUsed in 1 repo~873 tokens
    DevelopmentAuto-check passed
  • Systematic Code Refactoring

    luongnv89/claude-howto

    Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.

    42k GitHub stars~3k tokensUpdated today
    DevelopmentAuto-check passed
  • Installs, updates or migrates the vendored anti-slop Oxlint plugin in a repository, keeping local rule changes and the plugin's license and provenance files.

    5.4k GitHub stars~2.2k tokensUpdated 1 mo ago
    DevelopmentAuto-check passed
  • Constraint-Driven Development

    addyosmani/agent-skills

    Records a project's quality bar in CONSTRAINTS.md and watches diffs for signs an agent quietly weakened it, such as suppressions, skipped tests or lowered thresholds.

    105k GitHub starsUsed in 2 repos~5.2k tokens
    DevelopmentAuto-check passed
  • Skill Doli Code Review

    Dolibarr/dolibarr

    Reviews Dolibarr PHP code for compliance with coding standards and security best practices, and fixes identified issues.

    7.7k GitHub starsUsed in 1 repo~1.1k tokens
    DevelopmentAuto-check passed

More from mirage-project/mirage

All 24 skills in this repo
  • V2 Perf Iteration

    mirage-project/mirage

    Runtime-V2 performance-iteration workflow. An agent skill from mirage-project/mirage.

    2.5k GitHub stars~4k tokensUpdated 3 days ago
    Auto-check passed
  • Add Mpk Task

    mirage-project/mirage

    Step-by-step guide for adding a new task implementation to Mirage Persistent Kernel (MPK).

    2.5k GitHub stars~4.5k tokensUpdated 3 days ago
    Auto-check passed
  • B200 Flash Attention4 Planner

    mirage-project/mirage

    A skill your agent uses when the user wants to design or extend a FlashAttention-style forward kernel on B200/Blackwell, involving the two MMAs QKᵀ and PV, online softmax, S/P/O in TMEM, warp roles…

    2.5k GitHub stars~1.9k tokensUpdated 3 days ago
    Auto-check passed
  • Mpk Faithful Gate

    mirage-project/mirage

    Build or run a FAITHFUL in-MPK per-task latency gate (slowCTA at the production grid + cos) for a DeepSeek-V3 MPK decode kernel or shape.

    2.5k GitHub stars~2.6k tokensUpdated 3 days ago
    Auto-check passed
  • Test Mode

    mirage-project/mirage

    Guide for using MPK test mode to unit-test individual layers or multi-layer pipelines through the full compilation pipeline.

    2.5k GitHub stars~4.6k tokensUpdated 3 days ago
    Auto-check passed
  • V2 Model Support

    mirage-project/mirage

    End-to-end pipeline for adding or porting a model to MPK Runtime-V2 — from a compute-graph spec (shapes + draw.io graph + HF checkpoint + TP/EP plan) to a working multi-GPU demo.

    2.5k GitHub stars~5.3k tokensUpdated 3 days ago
    Auto-check passed

Categories

Questions about Mpk Lever Cleanup

What does Mpk Lever Cleanup do?

A skill your agent uses when a batch of env-gated (ifdef MPKDSV3 / os.environ-controlled, default-OFF) MPK optimization levers needs to be consolidated into a single clean code path for a PR…. Mpk Lever Cleanup is an agent skill from mirage-project/mirage.environ-controlled, default-OFF) MPK optimization levers needs to be consolidated into a single clean code path for a PR: hard-wire every winning lever as the default, delete the legacy else branches, remove the env vars that select new-vs-old logic, revert dead levers that measured KILL/NULL/regress, delete diagnostic probes, then commit one clean version.

When should I use Mpk Lever Cleanup?

Mpk Lever Cleanup fits situations like: A batch of env-gated (ifdef MPKDSV3 / os.environ-controlled; delete the legacy else branches; remove the env vars that select new-vs-old logic; revert dead levers that measured KILL/NULL/regress.

How do I install Mpk Lever Cleanup in Claude Code?

Run `npx skills add mirage-project/mirage --skill mpk-lever-cleanup -a claude-code`. Or copy the skill folder (.claude/skills/mpk-lever-cleanup in mirage-project/mirage) into .claude/skills/mpk-lever-cleanup in your project. Claude Code loads it when a task matches its description.

How do I install Mpk Lever Cleanup in Codex?

Run `npx skills add mirage-project/mirage --skill mpk-lever-cleanup -a codex`. Or copy the skill folder (.claude/skills/mpk-lever-cleanup in mirage-project/mirage) into .agents/skills/mpk-lever-cleanup in your project. Codex loads it when a task matches its description.

Can I use Mpk Lever Cleanup in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add mirage-project/mirage --skill mpk-lever-cleanup -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/mpk-lever-cleanup, .gemini/skills/mpk-lever-cleanup, .github/skills/mpk-lever-cleanup and .opencode/skills/mpk-lever-cleanup in your project.

What does Mpk Lever Cleanup need to run?

Going by SKILL.md and its folder, Mpk Lever Cleanup needs the command-line tools its instructions call (git).

Does Mpk Lever Cleanup access the network?

SKILL.md contains no URLs. Its commands use git, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Mpk Lever Cleanup safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Mpk Lever Cleanup use?

Mpk Lever Cleanup is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Mpk Lever Cleanup use?

About 2.2k tokens (SKILL.md is roughly 8.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Mpk Lever Cleanup?

Skills that share tags, products or a category with Mpk Lever Cleanup: WooCommerce Code Review (woocommerce/woocommerce, 11k stars), Ponytail Lazy Developer Mode (DietrichGebert/ponytail, 160k stars), Systematic Code Refactoring (luongnv89/claude-howto, 42k stars) and Install Anti-Slop Oxlint Rules (dmmulroy/anti-slop, 5.4k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Mpk Lever Cleanup?

mirage-project (a GitHub organization) maintains it in mirage-project/mirage, which has 2,545 GitHub stars. The repository holds 24 skills in this directory. The repository was last updated on October 7, 2026.

Source: mirage-project/mirage on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.