mlx
- Repo stars 33
- License MIT
- Author updated Live
- Author repo mlx-LLM-cheatsheet
- Domain
- Other
- Compatible agents
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- Trust score
- 94 / 100 · audit passed
- Author / version / license
- @cavit99 · MIT
- Token usage
- Lean
- Setup complexity
- Guided setup
- External API key
- Not required
- Operating systems
- macOS
- Runtime requirements
- Python
- Permissions
-
- Read-only
- Write / modify
- Shell exec
- Network behavior
- Local-only
- Install commands
- 26 variants
Profile is derived at build time from SKILL.md and install vectors. Subject to drift from author intent.
Heads up: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: mlx
description: Use when working with Apple's MLX or MLX-LM: fact-checking current behavior against upstream sou…
category: other
runtime: Python
---
# mlx output preview
## PART A: Task fit
- Use case: Use when working with Apple's MLX or MLX-LM: fact-checking current behavior against upstream source/runtime, patching MLX-based repos, porting PyTorch/JAX code to MLX, validating lazy evaluation, indexing, compilation, streams, channels-last layouts, Metal kernels, quantization, caches, and local MLX model loading or generation on Apple silicon. Use this ….
- Inputs: target material, constraints, expected output, and acceptance criteria.
- Evidence boundary: follow “When to Use / Core Rules / Quick Start” and do not present inference as author intent.
## PART B: Execution result
- **01** The card summarizes the use case; runtime output centers on “Use when working with Apple's MLX or MLX-LM: fact-checking current behavior against upstream source/runtime, patching MLX-based repos, porting PyTorch/JAX code to MLX, validating lazy evaluation, indexing, compilation, streams, channels-last layouts, Metal kernels, quantization, caches, and local MLX model loading or generation on Apple silicon. Use this …”.
- **02** When the source has headings, the agent prioritizes “When to Use / Core Rules / Quick Start” so the result follows the author’s structure.
- **03** Typical output includes task judgment, concrete steps, required commands or file edits, validation, and follow-up options.
- **04** Risk context follows the fingerprint: read files, write/modify files, run shell commands; mostly runs locally; usually needs no extra API key.
## Running Rules
- read files, write/modify files, run shell commands; mostly runs locally; usually needs no extra API key.
- Validate with a small sample before expanding scope.
- Return the result, validation criteria, and next iteration options. The source mentions slash commands such as `/tmp`; use them first when your agent supports command triggers.
Name target files or source material, expected output, forbidden changes, and whether network or shell access is allowed. Permission fingerprint: read files, write/modify files, run shell commands.
Start with a small task and check whether the result follows “When to Use / Core Rules / Quick Start”. Inspect diffs, logs, previews, or tests before expanding scope.
Confirm the final output includes a concrete result, evidence, and next action. If it stays generic, tighten inputs, boundaries, and acceptance criteria.
---
name: mlx
description: Use when working with Apple's MLX or MLX-LM: fact-checking current behavior against upstream sou…
category: other
source: cavit99/mlx-LLM-cheatsheet
---
# mlx
## When to use
- Use when working with Apple's MLX or MLX-LM: fact-checking current behavior against upstream source/runtime, patching…
- Use it when the task has clear inputs, repeatable steps, and validation criteria.
## What to provide
- Target material, scope, expected result, and forbidden changes.
- Whether network, commands, file writes, or external services are allowed.
## Execution rules
- Organize steps around “When to Use / Core Rules / Quick Start” and keep inference separate from source facts.
- read files, write/modify files, run shell commands; mostly runs locally; usually needs no extra API key.
- Validate with a small sample before expanding the task.
## Output requirements
- Return the deliverable, key evidence, validation method, and next action.
- Mark missing information as unknown; do not invent commands, platforms, or dependencies. The author source anchors workflow facts; repository files anchor sources and commands; Fluxly only adds fit, limitations, and quality judgment.
skill "mlx" {
input -> user goal + target files + boundaries + acceptance criteria
context -> When to Use / Core Rules / Quick Start
rules -> SKILL.md triggers / order / output contract
runtime -> Python | read files, write/modify files, run shell commands | mostly runs locally
guardrails -> usually needs no extra API key + small-sample validation + diff/log review
output -> copyable result + checklist + next iteration
} 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
Decide Fit First
Design Intent
How To Use It
Boundaries And Review