文档测试
- 作者仓库星标 33
- 许可证 MIT
- 作者更新于 实时读取
- 作者仓库 mlx-LLM-cheatsheet
- 领域
- 通用
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 94 / 100 · 已通过审计
- 作者 / 版本 / 许可
- @cavit99 · MIT
- Token 消耗评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- macOS
- 底层运行要求
- Python
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 网络行为
- 仅限本地
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: mlx
description: Use when working with Apple's MLX or MLX-LM: fact-checking current behavior against upstream sou…
category: 通用
runtime: Python
---
# mlx 输出预览
## PART A: 任务判断
- 适用问题:通用任务拆解、检查和交付。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“When to Use / Core Rules / Quick Start”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于通用任务拆解、检查和交付,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“When to Use / Core Rules / Quick Start”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、主要在本地完成、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文出现了 `/tmp` 这类斜杠命令;如果你的 Agent 支持命令触发,优先用命令开场,再补充目标和边界。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令。
先用一个小任务确认它会围绕“When to Use / Core Rules / Quick Start”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: mlx
description: Use when working with Apple's MLX or MLX-LM: fact-checking current behavior against upstream sou…
category: 通用
source: cavit99/mlx-LLM-cheatsheet
---
# mlx
## 什么时候使用
- 把通用方向的常用动作沉淀成 Agent 可调用的技能 适合处理通用任务拆解、检查、交付和复盘,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代的步骤;通常不需要额外…
- 面向通用任务拆解、检查和交付,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「When to Use / Core Rules / Quick Start」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "mlx" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> When to Use / Core Rules / Quick Start
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Python | 读取文件、写入/修改文件、执行终端命令 | 主要在本地完成
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} MLX
Use this skill for MLX or MLX-LM engineering work where correctness depends on current upstream behavior, not model memory.
When to Use
- Auditing or patching MLX or MLX-LM repos
- Fact-checking "latest" MLX or MLX-LM behavior
- Porting PyTorch or JAX code to MLX
- Debugging MLX indexing, lazy evaluation, compilation, or stream behavior
- Deciding when to use stock ops,
mx.fast.*,mx.fast.metal_kernel(...), or a deeper extension path - Profiling or debugging MLX GPU execution with Metal capture hooks
- Profiling MLX memory usage or allocator/cache behavior on Apple silicon
- Reviewing MLX-LM model load, cache, prompt-cache, quantization, or generation code
- Validating local MLX model paths on Apple silicon
Core Rules
- If the user asks for current or latest MLX facts, verify releases and source first.
- Prefer upstream docs/source plus runtime checks over memory.
- Treat undocumented runtime behavior as unstable.
- Distinguish documented contracts from observed caveats.
- Keep MLX-LM inference checks local and minimal:
lazy=True, short prompts, smallmax_tokens.
Quick Start
Set the skill path once:
export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
export MLX_SKILL="$CODEX_HOME/skills/mlx"
Check latest upstream releases:
"$MLX_SKILL/scripts/mlx_release_info.sh"
Run the bundled runtime probe:
"$MLX_SKILL/scripts/mlx_probe.sh"
The launcher checks both python3 and python and picks one that can import
mlx.
Run the probe with a local MLX model:
MLX_LM_LOCAL_MODEL=/path/to/model "$MLX_SKILL/scripts/mlx_probe.sh"
Workflow
1. Classify the task
- Current facts: verify latest
mlx/mlx-lmreleases, then inspect source - Repo validation: run the repo's own validator if it exists; otherwise use the bundled probe
- Porting or debugging: check the current facts reference, then validate the specific behavior locally
- Local model inference: use a local MLX model path and keep decode checks short
2. For current upstream facts
Use authenticated GitHub workflows when possible:
"$MLX_SKILL/scripts/mlx_release_info.sh"
gh repo clone ml-explore/mlx /tmp/mlx-upstream -- --depth 1
gh repo clone ml-explore/mlx-lm /tmp/mlx-lm-upstream -- --depth 1
Inspect only the files relevant to the question. Typical targets:
- MLX:
docs/src/usage/indexing.rst,lazy_evaluation.rst,compile.rst,numpy.rst,python/data_types.rst,python/memory_management.rst,python/mlx/nn/layers/convolution.py,docs/src/dev/custom_metal_kernels.rst,docs/src/dev/metal_debugger.rst,docs/src/dev/extensions.rst - MLX-LM:
mlx_lm/generate.py,mlx_lm/utils.py,mlx_lm/models/base.py,mlx_lm/models/cache.py
3. For runtime validation
If the repo already has an MLX validator, prefer that first.
Otherwise run:
"$MLX_SKILL/scripts/mlx_probe.sh"
The bundled probe checks high-signal MLX and MLX-LM behavior:
- indexing and mask limitations
- slice-copy vs aliasing
- compile and retracing rules
- training flow and optimizer semantics
- channels-last inputs
- stream APIs
- custom Metal kernel and capture-hook surface
- MLX-LM API surface, attention mask, caches, prompt-cache roundtrip
- AutoAWQ/GPTQ transform helpers
4. For local model checks
Use a local MLX model path when load/generate behavior matters:
MLX_LM_LOCAL_MODEL=/path/to/model "$MLX_SKILL/scripts/mlx_probe.sh"
This adds:
- real
load(..., lazy=True) - one-step
generate(...) stream_generate(...)response validation- prompt-cache save/load on the actual model cache
- generation-stream /
async_eval/clear_cachechecks
5. For porting or reviews
Check current-facts.md first.
Then use porting-checklist.md for the common MLX-specific failure modes:
- boolean mask selection unsupported
- slices are copies, not views
- no tensor
backward()pattern - explicit
mx.eval(...)required in training and timing - channels-last activations
- stream-aware benchmarking
- MLX-LM cache and generation API differences
Kernel Escalation Path
- Start with stock MLX ops.
- If there is already a tuned kernel in
mx.fast.*, prefer that first. - Use
mx.fast.metal_kernel(...)for Apple-only fused hot paths when the stock op graph is the bottleneck. - Be explicit about contiguity:
ensure_row_contiguous=Truecan hide copies. - Use
@mx.custom_functionwhen the custom kernel also needs custom gradient logic. - Move to C++
Primitiveextensions only when Python-level Metal kernels are not enough. - For serious GPU profiling, capture a
.gputracewithmx.metal.start_capture(...)/mx.metal.stop_capture()and inspect it in Xcode.
High-Signal MLX Differences
- Training is
nn.value_and_grad(...)plusoptimizer.update(...)plusmx.eval(model.parameters(), optimizer.state). - Module parameters are created lazily; explicit
mx.eval(model.parameters())matters before timing and export. - Conv inputs are channels-last:
NLC,NHWC,NDHWC. mx.compile(...)retraces on dtype, rank, and input-arity changes.shapeless=Trueavoids shape-only retracing but can break shape-dependent code.- Streams are first-class, and timing without
mx.eval(...)ormx.synchronize(...)is often wrong. - Memory profiling should use the top-level
mx.get_*_memory()helpers andmx.device_info(), not deprecatedmx.metal.*aliases. - MLX has a real Python-level fused-kernel escape hatch in
mx.fast.metal_kernel(...).
High-Signal MLX-LM Differences
generate(...)andstream_generate(...)accept strings or token IDs.batch_generate(...)expects token ID lists, not raw strings.stream_generate(...)yieldsGenerationResponseobjects.- Prompt caches are not always pure KV caches; hybrid models can mix
ArraysCacheandKVCache. - Current
mlx-lm==0.31.0caveat:batch_generate(..., max_tokens=1)can hit aZeroDivisionError.
References
- Current validated facts and caveats: current-facts.md
- Porting and review checklist: porting-checklist.md
Helpers
- Release helper: scripts/mlx_release_info.sh
- Runtime probe launcher: scripts/mlx_probe.sh
- Runtime probe implementation: scripts/mlx_probe.py
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核