Agent skill

Add Mpk Model

by mirage-project in mirage-project/mirage

Guide for adding a new model (e.g., Llama4, DeepSeek V3) to the MPK persistent kernel.

Apache-2.0Auto-check passed

Install Add Mpk Model

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

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

GitHub CLI
$ gh skill install mirage-project/mirage add-mpk-model --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/add-mpk-model .claude/skills/add-mpk-model && 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
add-mpk-model
GitHub stars
2.5k
Token cost
~1.6k tokens
SKILL.md length
510 words
Files
1
Skills in repo
24
Repo updated
First seen
Licence
Apache-2.0

At a glance

Guide for adding a new model (e.g., Llama4, DeepSeek V3) to the MPK persistent kernel.

  • Works in 5 steps: List the model's layers: embedding,… → Check which layer methods already exist… → For any missing layers: use the… → …
  • SKILL.md covers Prerequisites Check, Where Model Code Lives, How to Build the Demo and Wiring Layers in the Builder, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Add Mpk Model is an agent skill from mirage-project/mirage. Guide for adding a new model (e.g., Llama4, DeepSeek V3) to the MPK persistent kernel. Covers prerequisites check, demo structure, layer wiring, and testing.

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

It works with DeepSeek and Python. The repository describes itself as: Mirage Persistent Kernel: Compiling LLMs into a MegaKernel. The licence is Apache-2.0.

Example prompts

  • “/add-mpk-model”

Requirements

  • Python 3

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. List the model's layers: embedding, normalization, attention (what variant?), feed-forward (dense or MoE?), output head.
  2. Check which layer methods already exist in python/mirage/mpk/persistent_kernel.py. Search for def *_layer methods. Common ones…
  3. For any missing layers: use the /add-mpk-task skill to add them first. Each missing layer requires implementing a CUDA task kernel and…
  4. Check the model's attention mechanism: GQA (grouped-query attention) is standard for Qwen3/Llama. MLA (multi-latent attention) requires…
  5. Check weight naming: You'll need to map HuggingFace weight names to MPK names for the weight shard loader.

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

    No scripts in the folder and no shell commands in SKILL.md (its code samples are python).

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

  • Network

    No URLs in SKILL.md.

    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

Add Mpk Model loads about 1.6k tokens when it runs. Until then it costs about 43 tokens; SKILL.md has 510 words of instructions outside code blocks.

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

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). 510 words, ~1,591 tokens.

Download SKILL.mdSave it as .claude/skills/add-mpk-model/SKILL.md (or your agent's skills folder).
name
add-mpk-model
description
Guide for adding a new model (e.g., Llama4, DeepSeek V3) to the MPK persistent kernel. Covers prerequisites check, demo structure, layer wiring, and testing.

You are helping the user add a new model to MPK. This is a context + guidelines skill (not a step-by-step recipe) because model implementations vary significantly depending on architecture (dense vs MoE, GQA vs MLA, etc.).

Read mpk-development-norms FIRST. This skill is the HOW; that one is the WHERE + the PR-shape gate — model code stays in models/<model>/builder.py + demo/<model>/, shared persistent_kernel.py gets only GENERIC ops named by operation (never <model>_*), no experiment env-vars land, and runtime fixes are separate PRs. A model bring-up that sprawls into persistent_kernel.cuh/multigpu.py/model-specific shared methods is exactly what it flags.

Prerequisites Check

Before writing any model code, identify what the new model needs:

  1. List the model's layers: embedding, normalization, attention (what variant?), feed-forward (dense or MoE?), output head.
  2. Check which layer methods already exist in python/mirage/mpk/persistent_kernel.py. Search for def *_layer methods. Common ones: embed_layer, rmsnorm_layer, linear_layer, silu_mul_layer, paged_attention_layer, moe_topk_softmax_routing_layer, moe_w13_linear_layer, etc.
  3. For any missing layers: use the /add-mpk-task skill to add them first. Each missing layer requires implementing a CUDA task kernel and Python layer method.
  4. Check the model's attention mechanism: GQA (grouped-query attention) is standard for Qwen3/Llama. MLA (multi-latent attention) requires mla_prefill_layer/mla_decode_layer. Novel attention variants need new tasks.
  5. Check weight naming: You'll need to map HuggingFace weight names to MPK names for the weight shard loader.

Where Model Code Lives

Model implementations live in demo/<model_name>/, NOT in python/mirage/mpk/models/. The models/ directory holds only base infrastructure (GraphBuilder, MirageModelConfig, model registry).

demo/<model_name>/
  demo.py                    # End-to-end inference demo
  models/                    # HuggingFace model files
    modeling_<model>.py      # HF model definition (for reference)
    configuration_<model>.py # HF config class
  <model>_shard_loader.py    # Weight name mapping + sharding (if multi-GPU)

Reference implementations:

  • demo/qwen3/ — Canonical dense transformer model
  • demo/deepseek_v3/ — MoE model (DeepSeek V3 with MLA + MoE)

How to Build the Demo

The demo script follows this pattern (see demo/qwen3/demo.py):

python
# 1. Parse args (model path, batching config, profiling flags)
# 2. Load model config from HuggingFace
# 3. Create MPKMetadata with runtime configuration
metadata = MPKMetadata(
    mode="offline",
    model_name="org/Model-Name",
    weight_from_model=True,
    max_num_batched_tokens=...,
    max_num_batched_requests=...,
    page_size=..., max_num_pages=...,
    # ...
)
# 4. Create MPK and build the computation graph
mpk = MPK(metadata)
mpk.build()    # Calls the model builder to wire layers
# 5. Compile the megakernel
mpk.compile()
# 6. Load request and run inference
mpk.load_new_request("Your prompt here")
mpk()

Wiring Layers in the Builder

The builder (subclass of GraphBuilder or custom code in the demo) constructs the computation graph by calling layer methods on PersistentKernel:

python
# Attach weight tensors from state dict
w_norm = pk.attach_input(state_dict["model.layers.0.input_layernorm.weight"], name="layer_0_norm")
w_qkv = pk.attach_input(qkv_weight, name="layer_0_wqkv")

# Create intermediate buffers
norm_out = pk.new_tensor(dims=(...), name="norm_out", io_category="cuda_tensor")

# Chain layer calls
pk.rmsnorm_layer(input=x, weight=w_norm, output=norm_out, grid_dim=(...), block_dim=(...))
pk.linear_layer(input=norm_out, weight=w_qkv, output=qkv_out, grid_dim=(...), block_dim=(...))
pk.paged_attention_layer(...)
# ... etc for each layer in the model
Show full SKILL.md (218 more words)Show less
grid_dim / block_dim Selection
  • block_dim: Always (128,1,1) for Ampere, (256,1,1) for Hopper/Blackwell. Use pk.target_cc >= 90 to choose.
  • grid_dim: Depends on the layer. For batch-parallel layers (rmsnorm, embedding): (max_num_batched_tokens, 1, 1). For linear layers, use the grid_for_rmsnorm_linear_layer() helper from the Qwen3 demo.
Weight Shard Loader (Multi-GPU)

If the model uses tensor parallelism, create a shard loader mapping HuggingFace weight names to MPK names with sharding types:

python
mapping = {
    "q_proj": {"name": "wq", "shard_type": [(ShardType.COL_PARALLEL,)]},
    "o_proj": {"name": "wo", "shard_type": [(ShardType.ROW_PARALLEL,)]},
    "input_layernorm": {"name": "attn_norm", "shard_type": [(ShardType.NONE,)]},
    # ...
}

See demo/qwen3/qwen3_shard_loader.py for the complete pattern.

Attention Patterns

  • Standard GQA (Llama, Qwen3): Use paged_attention_layer or paged_attention_split_kv_layer.
  • MLA (DeepSeek V3): Use mla_prefill_layer / mla_decode_layer.
  • Novel attention: Implement as a new task via /add-mpk-task.

MoE Models

For Mixture-of-Experts models, the available layer methods are:

  • moe_topk_softmax_routing_layer — Router (top-k gating with softmax)
  • moe_sigmoid_topk_routing_layer — Router (sigmoid gating, DeepSeek V3 style)
  • moe_w13_linear_layer / moe_w13_fp8_layer — First expert linear (gate+up fused)
  • moe_silu_mul_layer — SiLU activation between expert linear layers
  • moe_w2_linear_layer / moe_w2_fp8_layer — Second expert linear (down projection)
  • moe_mul_sum_add_layer — Combine expert outputs with routing weights + residual

Verification

  1. Test individual layers using test mode before wiring the full model. See tests/runtime_python/test_mode/test_qwen3_mlp_testmode.py for the canonical pattern — it tests gate+up linear, silu_mul, and down+residual individually and as a pipeline.
  2. Compile test: mpk.compile(output_dir="./debug_output") to inspect generated CUDA code and task graph JSON.
  3. Correctness test: Compare MPK output against a HuggingFace reference model on the same prompt. Outputs should match within bfloat16 tolerance (~1e-2 max abs error per token).

© 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/add-mpk-model of mirage-project/mirage.

Open the folder on GitHubat commit f9eb70c

Compare with similar skills

Add Mpk Model 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.

Add Mpk Model compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Add Mpk Model this skillmirage-project/mirage2.5k—~1.6kAutomated safety check: PassApache-2.0
Mindmemos CLImindscale-noah/MindMemOS1k—~3.4kAutomated safety check: PassNone
Readable Verilog GeneratorEriemon/verilog-generator312—~5.4kAutomated safety check: PassApache-2.0
Bridgic LLMsbitsky-tech/bridgic155—~839Automated safety check: NotesMIT
K8e Sandboxxiaods/k8e500—~6kAutomated safety check: PassApache-2.0
Excel Workbookadongwanai/learn-workbuddy412—~597Automated safety check: NotesMIT

Similar skills

  • Mindmemos CLI

    mindscale-noah/MindMemOS

    Give an AI agent persistent, cross-session long-term memory through MindMemOS.

    1k GitHub stars~3.4k tokensUpdated 10 days ago
    Agent WorkflowsAuto-check passed
  • Readable Verilog Generator

    Eriemon/verilog-generator

    A skill your agent uses when creating, writing, reviewing, annotating, repairing, refactoring, or validating readable Verilog RTL, including synthesizable Verilog-2001 .v files, existing-RTL…

    312 GitHub stars~5.4k tokensUpdated 1 mo ago
    DevelopmentAuto-check passed
  • Bridgic LLMs

    bitsky-tech/bridgic

    LLM provider initialization for bridgic projects. An agent skill from bitsky-tech/bridgic.

    155 GitHub stars~839 tokensUpdated 2 mo ago
    AI & LLM EngineeringAuto-check: notes
  • K8e Sandbox

    xiaods/k8e

    Run a goal end to end inside an isolated K8E sandbox pod (gVisor / Kata / Firecracker) instead of on the host: exec bash / Python / Node / TypeScript, install packages, move files in and out, reuse…

    500 GitHub stars~6k tokensUpdated 11 days ago
    Backend & APIsAuto-check passed
  • Excel Workbook

    adongwanai/learn-workbuddy

    使用此 Skill 创建、检查、编辑和验证 XLSX 工作簿。用户提到 Excel、xlsx、工作簿、工作表、表格,或要求修改、汇总、检查 Excel 文件时使用。只支持基础 XLSX 操作,不处理宏、VBA、图表、数据透视表或外部工作簿引用。

    412 GitHub stars~597 tokensUpdated yesterday
    Documents & OfficeAuto-check: notes
  • Photo Abstract Editorial

    kwhi6693-web/photo-abstract-editorial

    A skill your agent uses when one or more photographs must become adaptive photo-plus-abstraction editorial compositions while source facts, spatial relationships, and strict photo preservation…

    113 GitHub stars~870 tokensUpdated 1 mo ago
    Media & CreativeAuto-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 2 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 2 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 2 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 2 days ago
    Auto-check passed
  • Mpk Lever Cleanup

    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…

    2.5k GitHub stars~2.2k tokensUpdated 2 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 2 days ago
    Auto-check passed

Works with

Questions about Add Mpk Model

What does Add Mpk Model do?

Guide for adding a new model (e.g., Llama4, DeepSeek V3) to the MPK persistent kernel. Add Mpk Model is an agent skill from mirage-project/mirage., Llama4, DeepSeek V3) to the MPK persistent kernel.

How do I install Add Mpk Model in Claude Code?

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

How do I install Add Mpk Model in Codex?

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

Can I use Add Mpk Model 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 add-mpk-model -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/add-mpk-model, .gemini/skills/add-mpk-model, .github/skills/add-mpk-model and .opencode/skills/add-mpk-model in your project.

What does Add Mpk Model need to run?

SKILL.md names no scripts, command-line tools or credentials: Add Mpk Model is instructions for the agent only. Our summary lists: Python 3.

Does Add Mpk Model access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Add Mpk Model 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 Add Mpk Model use?

Add Mpk Model 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 Add Mpk Model use?

About 1.6k tokens (SKILL.md is roughly 6.4k 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 Add Mpk Model?

Skills that share tags, products or a category with Add Mpk Model: Mindmemos CLI (mindscale-noah/MindMemOS, 1k stars), Readable Verilog Generator (Eriemon/verilog-generator, 312 stars), Bridgic LLMs (bitsky-tech/bridgic, 155 stars) and K8e Sandbox (xiaods/k8e, 500 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Add Mpk Model?

mirage-project (a GitHub organization) maintains it in mirage-project/mirage, which has 2,543 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.