{"owner":"alibaba","repo":"MNN","hasSkills":true,"totalSkillsCount":5,"totalTokensCount":3165,"categories":["root-instruction","claude-rule","mcp-config","marketplace","plugin-manifest"],"hasMcp":true,"mcpConfig":{"mcpServers":{"MNN":{"command":"npx","args":["-y","@modelcontextprotocol/server-MNN"]}}},"found":["AGENTS.md","CLAUDE.md",".cursor/mcp.json",".claude-plugin/marketplace.json",".claude-plugin/plugin.json"],"skills":{"AGENTS.md":"# MNN Project Instructions\n\nMNN is a lightweight deep learning **inference engine** (not a training framework), targeting mobile and server platforms. Supports CNN / Transformer / LLM / Diffusion models. Code must prioritize **performance and binary size**.\n\n## Restricted Access\n\n> The following directories contain internal proprietary code. **Do NOT read, modify, or reference** any files within:\n> - `schema/private/`\n> - `source/internal/`\n\n## Architecture Overview\n\nMNN uses a **graph optimization + heterogeneous backend scheduling** architecture.\n\nTwo inference APIs are available:\n- **Session API** (low-level): `Interpreter → createSession → runSession`, operates on Tensor directly\n- **Module API** (high-level, recommended): `Module::load → onForward(VARP)`, Express-based dynamic graph. Used by LLM / Diffusion and most modern workloads\n\n**Key abstractions** (see corresponding headers under `source/core/`):\n- **Interpreter** / **Session**: model loading and inference session management\n- **Backend** / **Execution**: hardware backend abstraction and per-op implementation (CPU/Metal/CUDA/OpenCL/Vulkan/...)\n- **Tensor**: data container; internally uses NC4HW4 format (channels packed by 4 for SIMD)\n- **Op / Schema**: FlatBuffers-defined operator descriptors (`schema/default/*.fbs`)\n\n**Op registration pattern**: Schema definition → shape inference (`source/shape/`) → Geometry decomposition (optional) → Backend Execution implementation\n\n## LLM Subsystem\n\nMNN supports end-to-end LLM export and inference:\n\n- **Python export** (`transformers/llm/export/`): HuggingFace model → MNN format. Core modules: `llmexport.py` entry point, `utils/model_mapper.py` (model field mapping), `utils/model.py` (unified LlmModel class), `utils/transformers.py` (Attention/Decoder/RoPE export)\n- **C++ inference** (`transformers/llm/engine/`): `llm.cpp` (text inference), `omni.cpp` (multimodal: vision/audio), includes KVCache management and sampling strategies\n\n## Repository Structure\n\n| Directory | Description |\n|-----------|-------------|\n| `include/MNN/` | Public C++ headers |\n| `source/core/` | Inference core (Interpreter, Session, Pipeline, Backend) |\n| `source/backend/` | Hardware backend implementations (cpu, arm82, metal, cuda, opencl, vulkan, ...) |\n| `source/shape/` | Shape inference |\n| `source/geometry/` | Geometry computation (op decomposition) |\n| `express/` | Express API (high-level dynamic graph, VARP) |\n| `schema/default/` | FlatBuffers schema (op definitions) |\n| `tools/converter/` | Model converter (ONNX/TF/Caffe → MNN) |\n| `transformers/llm/` | LLM export (Python) + inference engine (C++) |\n| `transformers/diffusion/` | Diffusion model support |\n| `pymnn/` | Python bindings |\n| `test/` | Test cases |\n| `skills/` | AI Agent Skills |\n\n## Coding Style\n\n- **C++**: Google Style variant, see `.clang-format`. 4-space indent, 120-char line width, attached braces. Class names `PascalCase`, functions `camelCase`, member variables `mCamelCase`. RTTI and exceptions disabled (`-fno-rtti -fno-exceptions`). Default standard: C++11.\n- **Python**: Standard Python conventions\n- **Formatting**: `clang-format -i -style=file <file>`\n- **Comments**: 注释要精简，一处注释尽量两句话以内说清楚。只写代码本身看不出来的\"为什么\"，不要逐个成员/逐行解释，也不要写修改过程（如\"替换了旧的 xxx\"、\"以前是 yyy\"），这些放到 commit message 里。struct/类只在开头给一段整体说明，函数按类别分组即可。注释过多会让代码 AI 味太浓，反而降低可读性。\n\n> ⚠️ **禁止 C++ 全局对象（动态初始化）**:不允许在命名空间作用域定义需要动态初始化的非 POD 对象（如 `static const std::string` / `static const json` / 全局 STL 容器，**头文件中同样禁止**,每个包含它的 TU 都会生成一份）。这类对象产生 `__GLOBAL__sub_I_*` 启动初始化函数，会被手淘等打包静态检查拦截（代码安全风险 + 启动性能下降）。替代方案:`constexpr`/POD 常量（直接进 .rodata)、函数内 `static`（懒初始化）、或按需构造返回。\n\n## Build & Test\n\n```bash\n# Build C++ (with LLM)\nmkdir build && cd build\ncmake .. -DMNN_BUILD_LLM=ON -DMNN_LOW_MEMORY=ON && make -j$(nproc)\n\n# Common CMake options: MNN_BUILD_TEST, MNN_BUILD_CONVERTER, MNN_METAL, MNN_OPENCL,\n# MNN_VULKAN, MNN_CUDA, MNN_ARM82, MNN_BUILD_QUANTOOLS, MNN_SUPPORT_TRANSFORMER_FUSE\n# Full list: see option() declarations at the top of CMakeLists.txt\n\n# Unit tests\ncd build && ./run_test.out\n\n# LLM export\ncd transformers/llm/export\npython llmexport.py --path /path/to/model --export mnn --hqq --dst_path ./MODEL\n\n# LLM test\ncd build\n./llm_demo /path/to/MODEL/config.json prompt.txt\n\n# LLM benchmark\n./llm_bench -m /path/to/MODEL/config.json\n```\n\nTest suite includes: unit tests (`run_test.out`), model tests, conversion tests (ONNX/TF/TFLite/Torch), quantization tests, LLM tests, PyMNN tests. See `test.sh`, `test_stages.json`, and `test/` directory for details.\n\n## Development Workflow\n\n- **Branch**: Use `feature/<short-description>`, for example `feature/llm-streaming`.\n- **Commit**: Use a concise, one-line English message: `[Module:Type] Summary`, for example `[LLM:Feature] Add streaming support`.\n  - Modules: `LLM`, `CPU`, `Metal`, `CUDA`, `OpenCL`, `Vulkan`, `Core`, `Infra`, `Doc`, etc.\n  - Types: `Feature`, `Bugfix`, `Perf`, `Refact`, `Style`, `Doc`, `Test`, `Chore`, `Release`.\n\n## Skills\n\nFor the following tasks, **read the Skill entry file first** and execute step by step. Each step must pass its tests before proceeding.\n\n**After non-trivial skill-driven tasks, run Retrospective only when there are reusable lessons.**\n\n上表可能未覆盖全部 skill。遇到打包/发布/摩天轮/MTL/crash/集成等关键词时，**先 `Glob skills/**/SKILL.md` 确认是否有对应 skill**，不要仅凭表格判断。\n\nPublic skills are listed below. Environment-dependent skills may exist under `skills/*/SKILL.md`.\n\n| Skill | Entry File | Trigger |\n|-------|-----------|---------|\n| Support new LLM | `skills/support-new-llm/SKILL.md` | Add / adapt a new LLM model |\n| Add new op | `skills/add-new-op/SKILL.md` | Add a new operator |\n| CPU (ARM & x86_64 & RISC-V) | `skills/cpu/SKILL.md` | Any CPU-side work. Router with two branches: `optimize/` — diagnose **why** a CPU op / LLM path is slow and **which layer to change**; `kernel/` — **write / port** a kernel once profiling has located it (SIMD intrinsics or asm, pack & ABI contracts, dispatch registration, correctness gate). Architecture is a sub-layer inside each branch: `optimize/arch/{arm,x86_64,riscv}.md` is the **diagnosis** face (which path am I actually on — on ARM two orthogonal axes: architecture level aarch32 / aarch64 NEON baseline / v8.2 sdot / v8.6 smmla / v9.2 SME2, times precision fp32 / fp16 arm82 / bf16; on x86_64 a single ISA axis plain-C++/SSE/AVX2+FMA/AVX512 No-VNNI/AVX512 VNNI; on RISC-V a single ISA axis plain-C++/standard RVV/SpacemiT IME2 vendor matrix extension — and how to prove it), `kernel/arch/{arm,x86_64,riscv}.md` is the **implementation** face. `shared/` holds the cross-branch tools: build & benchmark discipline, env switch registry, RISC-V dev-board remote validation |\n| OpenCL optimization | `skills/opencl-optimize/SKILL.md` | Optimize op performance on OpenCL |\n| Vulkan optimization | `skills/vulkan-optimize/SKILL.md` | Optimize op performance on Vulkan |\n| Metal optimization | `skills/metal-optimize/SKILL.md` | Optimize op performance on Metal |\n| Bugfix / debugging | `skills/general-debug/SKILL.md` | Diagnose correctness bugs / regressions in MNN — router that dispatches by symptom to per-category sub-docs (memory aliasing, export/quant, host-side concurrency & refcount races, fp16 range, GPU OOB, kernel assumptions, stale cache, nondeterminism). |\n| Run tests / CI | `skills/test-ci/SKILL.md` | Run the regression / CI suite (host or on-device), benchmark LLM on a real iPhone/iPad, or add / select / retune a test stage |\n| Retrospective | `skills/retrospective/SKILL.md` | After non-trivial tasks with reusable lessons |\n","CLAUDE.md":"See @AGENTS.md\n",".cursor/mcp.json":"# Model Context Protocol (MCP) Configuration\n\nPath: `.cursor/mcp.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.cursor/mcp.json)",".claude-plugin/marketplace.json":"# Claude Plugin Marketplace Catalog\n\nPath: `.claude-plugin/marketplace.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/marketplace.json)",".claude-plugin/plugin.json":"# claude-plugin Plugin Manifest\n\nPath: `.claude-plugin/plugin.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/plugin.json)"},"files":{"AGENTS.md":"# MNN Project Instructions\n\nMNN is a lightweight deep learning **inference engine** (not a training framework), targeting mobile and server platforms. Supports CNN / Transformer / LLM / Diffusion models. Code must prioritize **performance and binary size**.\n\n## Restricted Access\n\n> The following directories contain internal proprietary code. **Do NOT read, modify, or reference** any files within:\n> - `schema/private/`\n> - `source/internal/`\n\n## Architecture Overview\n\nMNN uses a **graph optimization + heterogeneous backend scheduling** architecture.\n\nTwo inference APIs are available:\n- **Session API** (low-level): `Interpreter → createSession → runSession`, operates on Tensor directly\n- **Module API** (high-level, recommended): `Module::load → onForward(VARP)`, Express-based dynamic graph. Used by LLM / Diffusion and most modern workloads\n\n**Key abstractions** (see corresponding headers under `source/core/`):\n- **Interpreter** / **Session**: model loading and inference session management\n- **Backend** / **Execution**: hardware backend abstraction and per-op implementation (CPU/Metal/CUDA/OpenCL/Vulkan/...)\n- **Tensor**: data container; internally uses NC4HW4 format (channels packed by 4 for SIMD)\n- **Op / Schema**: FlatBuffers-defined operator descriptors (`schema/default/*.fbs`)\n\n**Op registration pattern**: Schema definition → shape inference (`source/shape/`) → Geometry decomposition (optional) → Backend Execution implementation\n\n## LLM Subsystem\n\nMNN supports end-to-end LLM export and inference:\n\n- **Python export** (`transformers/llm/export/`): HuggingFace model → MNN format. Core modules: `llmexport.py` entry point, `utils/model_mapper.py` (model field mapping), `utils/model.py` (unified LlmModel class), `utils/transformers.py` (Attention/Decoder/RoPE export)\n- **C++ inference** (`transformers/llm/engine/`): `llm.cpp` (text inference), `omni.cpp` (multimodal: vision/audio), includes KVCache management and sampling strategies\n\n## Repository Structure\n\n| Directory | Description |\n|-----------|-------------|\n| `include/MNN/` | Public C++ headers |\n| `source/core/` | Inference core (Interpreter, Session, Pipeline, Backend) |\n| `source/backend/` | Hardware backend implementations (cpu, arm82, metal, cuda, opencl, vulkan, ...) |\n| `source/shape/` | Shape inference |\n| `source/geometry/` | Geometry computation (op decomposition) |\n| `express/` | Express API (high-level dynamic graph, VARP) |\n| `schema/default/` | FlatBuffers schema (op definitions) |\n| `tools/converter/` | Model converter (ONNX/TF/Caffe → MNN) |\n| `transformers/llm/` | LLM export (Python) + inference engine (C++) |\n| `transformers/diffusion/` | Diffusion model support |\n| `pymnn/` | Python bindings |\n| `test/` | Test cases |\n| `skills/` | AI Agent Skills |\n\n## Coding Style\n\n- **C++**: Google Style variant, see `.clang-format`. 4-space indent, 120-char line width, attached braces. Class names `PascalCase`, functions `camelCase`, member variables `mCamelCase`. RTTI and exceptions disabled (`-fno-rtti -fno-exceptions`). Default standard: C++11.\n- **Python**: Standard Python conventions\n- **Formatting**: `clang-format -i -style=file <file>`\n- **Comments**: 注释要精简，一处注释尽量两句话以内说清楚。只写代码本身看不出来的\"为什么\"，不要逐个成员/逐行解释，也不要写修改过程（如\"替换了旧的 xxx\"、\"以前是 yyy\"），这些放到 commit message 里。struct/类只在开头给一段整体说明，函数按类别分组即可。注释过多会让代码 AI 味太浓，反而降低可读性。\n\n> ⚠️ **禁止 C++ 全局对象（动态初始化）**:不允许在命名空间作用域定义需要动态初始化的非 POD 对象（如 `static const std::string` / `static const json` / 全局 STL 容器，**头文件中同样禁止**,每个包含它的 TU 都会生成一份）。这类对象产生 `__GLOBAL__sub_I_*` 启动初始化函数，会被手淘等打包静态检查拦截（代码安全风险 + 启动性能下降）。替代方案:`constexpr`/POD 常量（直接进 .rodata)、函数内 `static`（懒初始化）、或按需构造返回。\n\n## Build & Test\n\n```bash\n# Build C++ (with LLM)\nmkdir build && cd build\ncmake .. -DMNN_BUILD_LLM=ON -DMNN_LOW_MEMORY=ON && make -j$(nproc)\n\n# Common CMake options: MNN_BUILD_TEST, MNN_BUILD_CONVERTER, MNN_METAL, MNN_OPENCL,\n# MNN_VULKAN, MNN_CUDA, MNN_ARM82, MNN_BUILD_QUANTOOLS, MNN_SUPPORT_TRANSFORMER_FUSE\n# Full list: see option() declarations at the top of CMakeLists.txt\n\n# Unit tests\ncd build && ./run_test.out\n\n# LLM export\ncd transformers/llm/export\npython llmexport.py --path /path/to/model --export mnn --hqq --dst_path ./MODEL\n\n# LLM test\ncd build\n./llm_demo /path/to/MODEL/config.json prompt.txt\n\n# LLM benchmark\n./llm_bench -m /path/to/MODEL/config.json\n```\n\nTest suite includes: unit tests (`run_test.out`), model tests, conversion tests (ONNX/TF/TFLite/Torch), quantization tests, LLM tests, PyMNN tests. See `test.sh`, `test_stages.json`, and `test/` directory for details.\n\n## Development Workflow\n\n- **Branch**: Use `feature/<short-description>`, for example `feature/llm-streaming`.\n- **Commit**: Use a concise, one-line English message: `[Module:Type] Summary`, for example `[LLM:Feature] Add streaming support`.\n  - Modules: `LLM`, `CPU`, `Metal`, `CUDA`, `OpenCL`, `Vulkan`, `Core`, `Infra`, `Doc`, etc.\n  - Types: `Feature`, `Bugfix`, `Perf`, `Refact`, `Style`, `Doc`, `Test`, `Chore`, `Release`.\n\n## Skills\n\nFor the following tasks, **read the Skill entry file first** and execute step by step. Each step must pass its tests before proceeding.\n\n**After non-trivial skill-driven tasks, run Retrospective only when there are reusable lessons.**\n\n上表可能未覆盖全部 skill。遇到打包/发布/摩天轮/MTL/crash/集成等关键词时，**先 `Glob skills/**/SKILL.md` 确认是否有对应 skill**，不要仅凭表格判断。\n\nPublic skills are listed below. Environment-dependent skills may exist under `skills/*/SKILL.md`.\n\n| Skill | Entry File | Trigger |\n|-------|-----------|---------|\n| Support new LLM | `skills/support-new-llm/SKILL.md` | Add / adapt a new LLM model |\n| Add new op | `skills/add-new-op/SKILL.md` | Add a new operator |\n| CPU (ARM & x86_64 & RISC-V) | `skills/cpu/SKILL.md` | Any CPU-side work. Router with two branches: `optimize/` — diagnose **why** a CPU op / LLM path is slow and **which layer to change**; `kernel/` — **write / port** a kernel once profiling has located it (SIMD intrinsics or asm, pack & ABI contracts, dispatch registration, correctness gate). Architecture is a sub-layer inside each branch: `optimize/arch/{arm,x86_64,riscv}.md` is the **diagnosis** face (which path am I actually on — on ARM two orthogonal axes: architecture level aarch32 / aarch64 NEON baseline / v8.2 sdot / v8.6 smmla / v9.2 SME2, times precision fp32 / fp16 arm82 / bf16; on x86_64 a single ISA axis plain-C++/SSE/AVX2+FMA/AVX512 No-VNNI/AVX512 VNNI; on RISC-V a single ISA axis plain-C++/standard RVV/SpacemiT IME2 vendor matrix extension — and how to prove it), `kernel/arch/{arm,x86_64,riscv}.md` is the **implementation** face. `shared/` holds the cross-branch tools: build & benchmark discipline, env switch registry, RISC-V dev-board remote validation |\n| OpenCL optimization | `skills/opencl-optimize/SKILL.md` | Optimize op performance on OpenCL |\n| Vulkan optimization | `skills/vulkan-optimize/SKILL.md` | Optimize op performance on Vulkan |\n| Metal optimization | `skills/metal-optimize/SKILL.md` | Optimize op performance on Metal |\n| Bugfix / debugging | `skills/general-debug/SKILL.md` | Diagnose correctness bugs / regressions in MNN — router that dispatches by symptom to per-category sub-docs (memory aliasing, export/quant, host-side concurrency & refcount races, fp16 range, GPU OOB, kernel assumptions, stale cache, nondeterminism). |\n| Run tests / CI | `skills/test-ci/SKILL.md` | Run the regression / CI suite (host or on-device), benchmark LLM on a real iPhone/iPad, or add / select / retune a test stage |\n| Retrospective | `skills/retrospective/SKILL.md` | After non-trivial tasks with reusable lessons |\n","CLAUDE.md":"See @AGENTS.md\n",".cursor/mcp.json":"# Model Context Protocol (MCP) Configuration\n\nPath: `.cursor/mcp.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.cursor/mcp.json)",".claude-plugin/marketplace.json":"# Claude Plugin Marketplace Catalog\n\nPath: `.claude-plugin/marketplace.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/marketplace.json)",".claude-plugin/plugin.json":"# claude-plugin Plugin Manifest\n\nPath: `.claude-plugin/plugin.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/plugin.json)"},"items":[{"name":"AGENTS.md","path":"AGENTS.md","rawUrl":"https://raw.githubusercontent.com/alibaba/MNN/HEAD/AGENTS.md","title":"AI Agent Protocol & Instructions","category":"root-instruction","format":"markdown","content":"# MNN Project Instructions\n\nMNN is a lightweight deep learning **inference engine** (not a training framework), targeting mobile and server platforms. Supports CNN / Transformer / LLM / Diffusion models. Code must prioritize **performance and binary size**.\n\n## Restricted Access\n\n> The following directories contain internal proprietary code. **Do NOT read, modify, or reference** any files within:\n> - `schema/private/`\n> - `source/internal/`\n\n## Architecture Overview\n\nMNN uses a **graph optimization + heterogeneous backend scheduling** architecture.\n\nTwo inference APIs are available:\n- **Session API** (low-level): `Interpreter → createSession → runSession`, operates on Tensor directly\n- **Module API** (high-level, recommended): `Module::load → onForward(VARP)`, Express-based dynamic graph. Used by LLM / Diffusion and most modern workloads\n\n**Key abstractions** (see corresponding headers under `source/core/`):\n- **Interpreter** / **Session**: model loading and inference session management\n- **Backend** / **Execution**: hardware backend abstraction and per-op implementation (CPU/Metal/CUDA/OpenCL/Vulkan/...)\n- **Tensor**: data container; internally uses NC4HW4 format (channels packed by 4 for SIMD)\n- **Op / Schema**: FlatBuffers-defined operator descriptors (`schema/default/*.fbs`)\n\n**Op registration pattern**: Schema definition → shape inference (`source/shape/`) → Geometry decomposition (optional) → Backend Execution implementation\n\n## LLM Subsystem\n\nMNN supports end-to-end LLM export and inference:\n\n- **Python export** (`transformers/llm/export/`): HuggingFace model → MNN format. Core modules: `llmexport.py` entry point, `utils/model_mapper.py` (model field mapping), `utils/model.py` (unified LlmModel class), `utils/transformers.py` (Attention/Decoder/RoPE export)\n- **C++ inference** (`transformers/llm/engine/`): `llm.cpp` (text inference), `omni.cpp` (multimodal: vision/audio), includes KVCache management and sampling strategies\n\n## Repository Structure\n\n| Directory | Description |\n|-----------|-------------|\n| `include/MNN/` | Public C++ headers |\n| `source/core/` | Inference core (Interpreter, Session, Pipeline, Backend) |\n| `source/backend/` | Hardware backend implementations (cpu, arm82, metal, cuda, opencl, vulkan, ...) |\n| `source/shape/` | Shape inference |\n| `source/geometry/` | Geometry computation (op decomposition) |\n| `express/` | Express API (high-level dynamic graph, VARP) |\n| `schema/default/` | FlatBuffers schema (op definitions) |\n| `tools/converter/` | Model converter (ONNX/TF/Caffe → MNN) |\n| `transformers/llm/` | LLM export (Python) + inference engine (C++) |\n| `transformers/diffusion/` | Diffusion model support |\n| `pymnn/` | Python bindings |\n| `test/` | Test cases |\n| `skills/` | AI Agent Skills |\n\n## Coding Style\n\n- **C++**: Google Style variant, see `.clang-format`. 4-space indent, 120-char line width, attached braces. Class names `PascalCase`, functions `camelCase`, member variables `mCamelCase`. RTTI and exceptions disabled (`-fno-rtti -fno-exceptions`). Default standard: C++11.\n- **Python**: Standard Python conventions\n- **Formatting**: `clang-format -i -style=file <file>`\n- **Comments**: 注释要精简，一处注释尽量两句话以内说清楚。只写代码本身看不出来的\"为什么\"，不要逐个成员/逐行解释，也不要写修改过程（如\"替换了旧的 xxx\"、\"以前是 yyy\"），这些放到 commit message 里。struct/类只在开头给一段整体说明，函数按类别分组即可。注释过多会让代码 AI 味太浓，反而降低可读性。\n\n> ⚠️ **禁止 C++ 全局对象（动态初始化）**:不允许在命名空间作用域定义需要动态初始化的非 POD 对象（如 `static const std::string` / `static const json` / 全局 STL 容器，**头文件中同样禁止**,每个包含它的 TU 都会生成一份）。这类对象产生 `__GLOBAL__sub_I_*` 启动初始化函数，会被手淘等打包静态检查拦截（代码安全风险 + 启动性能下降）。替代方案:`constexpr`/POD 常量（直接进 .rodata)、函数内 `static`（懒初始化）、或按需构造返回。\n\n## Build & Test\n\n```bash\n# Build C++ (with LLM)\nmkdir build && cd build\ncmake .. -DMNN_BUILD_LLM=ON -DMNN_LOW_MEMORY=ON && make -j$(nproc)\n\n# Common CMake options: MNN_BUILD_TEST, MNN_BUILD_CONVERTER, MNN_METAL, MNN_OPENCL,\n# MNN_VULKAN, MNN_CUDA, MNN_ARM82, MNN_BUILD_QUANTOOLS, MNN_SUPPORT_TRANSFORMER_FUSE\n# Full list: see option() declarations at the top of CMakeLists.txt\n\n# Unit tests\ncd build && ./run_test.out\n\n# LLM export\ncd transformers/llm/export\npython llmexport.py --path /path/to/model --export mnn --hqq --dst_path ./MODEL\n\n# LLM test\ncd build\n./llm_demo /path/to/MODEL/config.json prompt.txt\n\n# LLM benchmark\n./llm_bench -m /path/to/MODEL/config.json\n```\n\nTest suite includes: unit tests (`run_test.out`), model tests, conversion tests (ONNX/TF/TFLite/Torch), quantization tests, LLM tests, PyMNN tests. See `test.sh`, `test_stages.json`, and `test/` directory for details.\n\n## Development Workflow\n\n- **Branch**: Use `feature/<short-description>`, for example `feature/llm-streaming`.\n- **Commit**: Use a concise, one-line English message: `[Module:Type] Summary`, for example `[LLM:Feature] Add streaming support`.\n  - Modules: `LLM`, `CPU`, `Metal`, `CUDA`, `OpenCL`, `Vulkan`, `Core`, `Infra`, `Doc`, etc.\n  - Types: `Feature`, `Bugfix`, `Perf`, `Refact`, `Style`, `Doc`, `Test`, `Chore`, `Release`.\n\n## Skills\n\nFor the following tasks, **read the Skill entry file first** and execute step by step. Each step must pass its tests before proceeding.\n\n**After non-trivial skill-driven tasks, run Retrospective only when there are reusable lessons.**\n\n上表可能未覆盖全部 skill。遇到打包/发布/摩天轮/MTL/crash/集成等关键词时，**先 `Glob skills/**/SKILL.md` 确认是否有对应 skill**，不要仅凭表格判断。\n\nPublic skills are listed below. Environment-dependent skills may exist under `skills/*/SKILL.md`.\n\n| Skill | Entry File | Trigger |\n|-------|-----------|---------|\n| Support new LLM | `skills/support-new-llm/SKILL.md` | Add / adapt a new LLM model |\n| Add new op | `skills/add-new-op/SKILL.md` | Add a new operator |\n| CPU (ARM & x86_64 & RISC-V) | `skills/cpu/SKILL.md` | Any CPU-side work. Router with two branches: `optimize/` — diagnose **why** a CPU op / LLM path is slow and **which layer to change**; `kernel/` — **write / port** a kernel once profiling has located it (SIMD intrinsics or asm, pack & ABI contracts, dispatch registration, correctness gate). Architecture is a sub-layer inside each branch: `optimize/arch/{arm,x86_64,riscv}.md` is the **diagnosis** face (which path am I actually on — on ARM two orthogonal axes: architecture level aarch32 / aarch64 NEON baseline / v8.2 sdot / v8.6 smmla / v9.2 SME2, times precision fp32 / fp16 arm82 / bf16; on x86_64 a single ISA axis plain-C++/SSE/AVX2+FMA/AVX512 No-VNNI/AVX512 VNNI; on RISC-V a single ISA axis plain-C++/standard RVV/SpacemiT IME2 vendor matrix extension — and how to prove it), `kernel/arch/{arm,x86_64,riscv}.md` is the **implementation** face. `shared/` holds the cross-branch tools: build & benchmark discipline, env switch registry, RISC-V dev-board remote validation |\n| OpenCL optimization | `skills/opencl-optimize/SKILL.md` | Optimize op performance on OpenCL |\n| Vulkan optimization | `skills/vulkan-optimize/SKILL.md` | Optimize op performance on Vulkan |\n| Metal optimization | `skills/metal-optimize/SKILL.md` | Optimize op performance on Metal |\n| Bugfix / debugging | `skills/general-debug/SKILL.md` | Diagnose correctness bugs / regressions in MNN — router that dispatches by symptom to per-category sub-docs (memory aliasing, export/quant, host-side concurrency & refcount races, fp16 range, GPU OOB, kernel assumptions, stale cache, nondeterminism). |\n| Run tests / CI | `skills/test-ci/SKILL.md` | Run the regression / CI suite (host or on-device), benchmark LLM on a real iPhone/iPad, or add / select / retune a test stage |\n| Retrospective | `skills/retrospective/SKILL.md` | After non-trivial tasks with reusable lessons |\n","isInternal":false,"tokens":2259,"sizeBytes":8145},{"name":"CLAUDE.md","path":"CLAUDE.md","rawUrl":"https://raw.githubusercontent.com/alibaba/MNN/HEAD/CLAUDE.md","title":"Claude Agent Guidelines & System Prompt","category":"claude-rule","format":"markdown","content":"See @AGENTS.md\n","isInternal":false,"tokens":6,"sizeBytes":15},{"name":"marketplace.json","path":".claude-plugin/marketplace.json","rawUrl":"https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/marketplace.json","title":"Claude Plugin Marketplace Catalog","category":"marketplace","format":"json","content":"# Claude Plugin Marketplace Catalog\n\nPath: `.claude-plugin/marketplace.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/marketplace.json)","tokens":300,"sizeBytes":190},{"name":"plugin.json","path":".claude-plugin/plugin.json","rawUrl":"https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/plugin.json","title":"claude-plugin Plugin Manifest","category":"plugin-manifest","format":"json","content":"# claude-plugin Plugin Manifest\n\nPath: `.claude-plugin/plugin.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/plugin.json)","tokens":300,"sizeBytes":176},{"name":"mcp.json","path":".cursor/mcp.json","rawUrl":"https://raw.githubusercontent.com/alibaba/MNN/HEAD/.cursor/mcp.json","title":"Model Context Protocol (MCP) Configuration","category":"mcp-config","format":"json","content":"# Model Context Protocol (MCP) Configuration\n\nPath: `.cursor/mcp.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.cursor/mcp.json)","tokens":300,"sizeBytes":169}],"systemPromptSnippet":"<yakaai_skills repo=\"alibaba/MNN\">\n<!-- File: AGENTS.md (Tokens: ~2259 | Category: root-instruction) -->\n# MNN Project Instructions\n\nMNN is a lightweight deep learning **inference engine** (not a training framework), targeting mobile and server platforms. Supports CNN / Transformer / LLM / Diffusion models. Code must prioritize **performance and binary size**.\n\n## Restricted Access\n\n> The following directories contain internal proprietary code. **Do NOT read, modify, or reference** any files within:\n> - `schema/private/`\n> - `source/internal/`\n\n## Architecture Overview\n\nMNN uses a **graph optimization + heterogeneous backend scheduling** architecture.\n\nTwo inference APIs are available:\n- **Session API** (low-level): `Interpreter → createSession → runSession`, operates on Tensor directly\n- **Module API** (high-level, recommended): `Module::load → onForward(VARP)`, Express-based dynamic graph. Used by LLM / Diffusion and most modern workloads\n\n**Key abstractions** (see corresponding headers under `source/core/`):\n- **Interpreter** / **Session**: model loading and inference session management\n- **Backend** / **Execution**: hardware backend abstraction and per-op implementation (CPU/Metal/CUDA/OpenCL/Vulkan/...)\n- **Tensor**: data container; internally uses NC4HW4 format (channels packed by 4 for SIMD)\n- **Op / Schema**: FlatBuffers-defined operator descriptors (`schema/default/*.fbs`)\n\n**Op registration pattern**: Schema definition → shape inference (`source/shape/`) → Geometry decomposition (optional) → Backend Execution implementation\n\n## LLM Subsystem\n\nMNN supports end-to-end LLM export and inference:\n\n- **Python export** (`transformers/llm/export/`): HuggingFace model → MNN format. Core modules: `llmexport.py` entry point, `utils/model_mapper.py` (model field mapping), `utils/model.py` (unified LlmModel class), `utils/transformers.py` (Attention/Decoder/RoPE export)\n- **C++ inference** (`transformers/llm/engine/`): `llm.cpp` (text inference), `omni.cpp` (multimodal: vision/audio), includes KVCache management and sampling strategies\n\n## Repository Structure\n\n| Directory | Description |\n|-----------|-------------|\n| `include/MNN/` | Public C++ headers |\n| `source/core/` | Inference core (Interpreter, Session, Pipeline, Backend) |\n| `source/backend/` | Hardware backend implementations (cpu, arm82, metal, cuda, opencl, vulkan, ...) |\n| `source/shape/` | Shape inference |\n| `source/geometry/` | Geometry computation (op decomposition) |\n| `express/` | Express API (high-level dynamic graph, VARP) |\n| `schema/default/` | FlatBuffers schema (op definitions) |\n| `tools/converter/` | Model converter (ONNX/TF/Caffe → MNN) |\n| `transformers/llm/` | LLM export (Python) + inference engine (C++) |\n| `transformers/diffusion/` | Diffusion model support |\n| `pymnn/` | Python bindings |\n| `test/` | Test cases |\n| `skills/` | AI Agent Skills |\n\n## Coding Style\n\n- **C++**: Google Style variant, see `.clang-format`. 4-space indent, 120-char line width, attached braces. Class names `PascalCase`, functions `camelCase`, member variables `mCamelCase`. RTTI and exceptions disabled (`-fno-rtti -fno-exceptions`). Default standard: C++11.\n- **Python**: Standard Python conventions\n- **Formatting**: `clang-format -i -style=file <file>`\n- **Comments**: 注释要精简，一处注释尽量两句话以内说清楚。只写代码本身看不出来的\"为什么\"，不要逐个成员/逐行解释，也不要写修改过程（如\"替换了旧的 xxx\"、\"以前是 yyy\"），这些放到 commit message 里。struct/类只在开头给一段整体说明，函数按类别分组即可。注释过多会让代码 AI 味太浓，反而降低可读性。\n\n> ⚠️ **禁止 C++ 全局对象（动态初始化）**:不允许在命名空间作用域定义需要动态初始化的非 POD 对象（如 `static const std::string` / `static const json` / 全局 STL 容器，**头文件中同样禁止**,每个包含它的 TU 都会生成一份）。这类对象产生 `__GLOBAL__sub_I_*` 启动初始化函数，会被手淘等打包静态检查拦截（代码安全风险 + 启动性能下降）。替代方案:`constexpr`/POD 常量（直接进 .rodata)、函数内 `static`（懒初始化）、或按需构造返回。\n\n## Build & Test\n\n```bash\n# Build C++ (with LLM)\nmkdir build && cd build\ncmake .. -DMNN_BUILD_LLM=ON -DMNN_LOW_MEMORY=ON && make -j$(nproc)\n\n# Common CMake options: MNN_BUILD_TEST, MNN_BUILD_CONVERTER, MNN_METAL, MNN_OPENCL,\n# MNN_VULKAN, MNN_CUDA, MNN_ARM82, MNN_BUILD_QUANTOOLS, MNN_SUPPORT_TRANSFORMER_FUSE\n# Full list: see option() declarations at the top of CMakeLists.txt\n\n# Unit tests\ncd build && ./run_test.out\n\n# LLM export\ncd transformers/llm/export\npython llmexport.py --path /path/to/model --export mnn --hqq --dst_path ./MODEL\n\n# LLM test\ncd build\n./llm_demo /path/to/MODEL/config.json prompt.txt\n\n# LLM benchmark\n./llm_bench -m /path/to/MODEL/config.json\n```\n\nTest suite includes: unit tests (`run_test.out`), model tests, conversion tests (ONNX/TF/TFLite/Torch), quantization tests, LLM tests, PyMNN tests. See `test.sh`, `test_stages.json`, and `test/` directory for details.\n\n## Development Workflow\n\n- **Branch**: Use `feature/<short-description>`, for example `feature/llm-streaming`.\n- **Commit**: Use a concise, one-line English message: `[Module:Type] Summary`, for example `[LLM:Feature] Add streaming support`.\n  - Modules: `LLM`, `CPU`, `Metal`, `CUDA`, `OpenCL`, `Vulkan`, `Core`, `Infra`, `Doc`, etc.\n  - Types: `Feature`, `Bugfix`, `Perf`, `Refact`, `Style`, `Doc`, `Test`, `Chore`, `Release`.\n\n## Skills\n\nFor the following tasks, **read the Skill entry file first** and execute step by step. Each step must pass its tests before proceeding.\n\n**After non-trivial skill-driven tasks, run Retrospective only when there are reusable lessons.**\n\n上表可能未覆盖全部 skill。遇到打包/发布/摩天轮/MTL/crash/集成等关键词时，**先 `Glob skills/**/SKILL.md` 确认是否有对应 skill**，不要仅凭表格判断。\n\nPublic skills are listed below. Environment-dependent skills may exist under `skills/*/SKILL.md`.\n\n| Skill | Entry File | Trigger |\n|-------|-----------|---------|\n| Support new LLM | `skills/support-new-llm/SKILL.md` | Add / adapt a new LLM model |\n| Add new op | `skills/add-new-op/SKILL.md` | Add a new operator |\n| CPU (ARM & x86_64 & RISC-V) | `skills/cpu/SKILL.md` | Any CPU-side work. Router with two branches: `optimize/` — diagnose **why** a CPU op / LLM path is slow and **which layer to change**; `kernel/` — **write / port** a kernel once profiling has located it (SIMD intrinsics or asm, pack & ABI contracts, dispatch registration, correctness gate). Architecture is a sub-layer inside each branch: `optimize/arch/{arm,x86_64,riscv}.md` is the **diagnosis** face (which path am I actually on — on ARM two orthogonal axes: architecture level aarch32 / aarch64 NEON baseline / v8.2 sdot / v8.6 smmla / v9.2 SME2, times precision fp32 / fp16 arm82 / bf16; on x86_64 a single ISA axis plain-C++/SSE/AVX2+FMA/AVX512 No-VNNI/AVX512 VNNI; on RISC-V a single ISA axis plain-C++/standard RVV/SpacemiT IME2 vendor matrix extension — and how to prove it), `kernel/arch/{arm,x86_64,riscv}.md` is the **implementation** face. `shared/` holds the cross-branch tools: build & benchmark discipline, env switch registry, RISC-V dev-board remote validation |\n| OpenCL optimization | `skills/opencl-optimize/SKILL.md` | Optimize op performance on OpenCL |\n| Vulkan optimization | `skills/vulkan-optimize/SKILL.md` | Optimize op performance on Vulkan |\n| Metal optimization | `skills/metal-optimize/SKILL.md` | Optimize op performance on Metal |\n| Bugfix / debugging | `skills/general-debug/SKILL.md` | Diagnose correctness bugs / regressions in MNN — router that dispatches by symptom to per-category sub-docs (memory aliasing, export/quant, host-side concurrency & refcount races, fp16 range, GPU OOB, kernel assumptions, stale cache, nondeterminism). |\n| Run tests / CI | `skills/test-ci/SKILL.md` | Run the regression / CI suite (host or on-device), benchmark LLM on a real iPhone/iPad, or add / select / retune a test stage |\n| Retrospective | `skills/retrospective/SKILL.md` | After non-trivial tasks with reusable lessons |\n\n<!-- File: CLAUDE.md (Tokens: ~6 | Category: claude-rule) -->\nSee @AGENTS.md\n\n<!-- File: .claude-plugin/marketplace.json (Tokens: ~300 | Category: marketplace) -->\n# Claude Plugin Marketplace Catalog\n\nPath: `.claude-plugin/marketplace.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/marketplace.json)\n\n<!-- File: .claude-plugin/plugin.json (Tokens: ~300 | Category: plugin-manifest) -->\n# claude-plugin Plugin Manifest\n\nPath: `.claude-plugin/plugin.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.claude-plugin/plugin.json)\n\n<!-- File: .cursor/mcp.json (Tokens: ~300 | Category: mcp-config) -->\n# Model Context Protocol (MCP) Configuration\n\nPath: `.cursor/mcp.json`\n\n[View Raw Content on GitHub](https://raw.githubusercontent.com/alibaba/MNN/HEAD/.cursor/mcp.json)\n</yakaai_skills>"}