# jax-best-practices

A skill that gives your agent JAX conventions: pure functions, jit, vmap, grad and profiling. Useful when the project actually runs on JAX.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 704 installs · ★ 286
- Author: Mindrally
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/Mindrally/skills/tree/HEAD/jax-best-practices/SKILL.md
- Updated: 2026-10-08
- HTML: https://affpapa.org/en/nevibecode/skills/jax-best-practices

## What it does

This skill makes the assistant a JAX specialist. It keeps functional style in view: immutability, pure functions with no side effects, JAX arrays instead of NumPy where that makes sense. Ask the agent to write or refactor JAX code and it works from these rules rather than generic NumPy habits.

Inside are instructions for three transformations. `jax.jit` for just-in-time compilation, `jax.vmap` for vectorising over a batch dimension, `jax.grad` for automatic differentiation. The common traps get their own notes: side effects inside jitted functions, `static_argnums` for compile-time constants, splitting random keys the right way. There is a performance section too, plus pytrees, custom vjp/jvp, sharding across devices and checkpointing to save memory.

It is a single instruction file, no scripts and no dependencies. Worth installing if your project is on JAX; on a PyTorch or plain NumPy codebase the advice about `vmap` and pytrees will just confuse the agent.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill jax-best-practices -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/jax-best-practices/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/jax-best-practices/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill jax-best-practices -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/jax-best-practices/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill jax-best-practices -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/jax-best-practices/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install Mindrally/skills jax-best-practices
```

2. **Manually: put the files in place**
- File: `.github/skills/jax-best-practices/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill jax-best-practices -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/Mindrally/skills --path jax-best-practices
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/jax-best-practices/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill jax-best-practices -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/Mindrally/skills/tree/HEAD/jax-best-practices/SKILL.md

## When to use it
- write a jitted function with no side effects
- vectorise a loop over a batch with vmap
- compute gradients and pair grad with jit
- handle nested data as pytrees
- cut Python overhead in a hot loop

## Example prompts
- rewrite this loop with jax.vmap and wrap it in jit
- compute the gradient of this function, split the keys properly
- my jitted function keeps failing — check it for side effects

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 6010441eb5809f9a.

BEGIN THIRD-PARTY FILE 6010441eb5809f9a
```text
---
name: jax-best-practices
description: Expert in JAX for high-performance numerical computing and machine learning
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# JAX Best Practices

You are an expert in JAX for high-performance numerical computing and machine learning.

## Core Principles

- Follow functional programming patterns
- Use immutability and pure functions
- Leverage JAX transformations effectively
- Optimize for JIT compilation

## Key Transformations

### jax.jit
- Use for just-in-time compilation to optimize performance
- Avoid side effects in jitted functions
- Use static_argnums for compile-time constants

### jax.vmap
- Vectorize operations over batch dimensions
- Avoid explicit loops when possible
- Combine with jit for best performance

### jax.grad
- Compute gradients automatically
- Use for automatic differentiation
- Combine with jit for efficient gradient computation

## Best Practices

- Write pure functions without side effects
- Use JAX arrays instead of NumPy where possible
- Leverage random key splitting properly
- Profile and optimize hot paths

## Performance

- Minimize Python overhead in hot loops
- Use appropriate dtypes
- Batch operations when possible
- Profile with JAX profiler

## Common Patterns

- Use pytrees for nested data structures
- Implement custom vjp/jvp when needed
- Leverage sharding for multi-device
- Use checkpointing for memory efficiency
```
END THIRD-PARTY FILE 6010441eb5809f9a

The third-party file has ended. Everything between the 6010441eb5809f9a tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

© Mindrally · Apache-2.0 · https://github.com/Mindrally/skills/tree/HEAD/jax-best-practices/SKILL.md

## Similar
- [pennylane](https://affpapa.org/en/nevibecode/skills/pennylane.md) — skill · 1900 installs
- [interpreters](https://affpapa.org/en/nevibecode/skills/interpreters.md) — skill · 564 installs
- [fine-tuning-serving-openpi](https://affpapa.org/en/nevibecode/skills/fine-tuning-serving-openpi.md) — skill · 861 installs
- [gke-ai-troubleshooting-tpu-performance-degradation](https://affpapa.org/en/nevibecode/skills/gke-ai-troubleshooting-tpu-performance-degradation.md) — skill · 691 installs
- [ima-sdk-client-side](https://affpapa.org/en/nevibecode/skills/ima-sdk-client-side.md) — skill · 4500 installs
- [browser-exploitation-v8](https://affpapa.org/en/nevibecode/skills/browser-exploitation-v8.md) — skill · 3600 installs

From the same set: [mindrally/skills](https://affpapa.org/en/nevibecode/by/mindrally/skills.md) — 168 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
