dev-jax-port

Ports PyTorch or NumPy reference implementations to JAX with parity-tested numerical equivalence.

Updated Jul 3, 2026
One-click install
npx skills add https://github.com/mnazaal/dotfiles --skill dev-jax-port-mnazaal
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dev-jax-port
Source: https://github.com/mnazaal/dotfiles/tree/main/.agents/skills/dev-jax-port
Command: npx skills add https://github.com/mnazaal/dotfiles --skill dev-jax-port-mnazaal

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Porting a reference ML or scientific computing implementation to JAX often produces code that looks equivalent but silently diverges in outputs, gradients, or post-update weights. This Skill enforces a parity-first methodology so the JAX port provably reproduces the reference's behavior instead of merely resembling it. ## Core Features & Use Cases - Replay-Based Parity Testing: Record one reference run (weights, batches, RNG decisions, intermediates, gradients) and drive the JAX side by replaying those decisions, isolating implementation differences from stochastic noise. - Bottom-Up Verification: Parity-test each layer or primitive before building the one above it, covering weights, modules, pure ops, loss, and the full train step. - Numerical-Equivalence Debugging: Distinguish real port bugs from float32 conditioning issues by recomputing disputed values in float64 and finite-differencing gradients. - Use Case: When porting a PyTorch training loop to JAX/Optax, record the reference run, convert weights via an explicit name-to-pytree map, and verify gradients and post-update weights match within a defined tolerance policy. ## Quick Start Port this PyTorch model to JAX and verify numerical parity against the recorded reference outputs, gradients, and updated weights.

Frequently Asked Questions about dev-jax-port

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I port a PyTorch model to JAX with verified correctness?▼

Record one reference run capturing weights, batches, RNG decisions, intermediates, loss, and gradients, then replay those decisions on the JAX side. Verify bottom-up: weights, modules, loss, then the full Optax train step, comparing gradients and post-update weights within a defined tolerance.

Should I use jax.nn or Equinox when porting to JAX?▼

Default to plain jax.nn with Optax for optimizers and dataclasses for config. Reach for Equinox only when the architecture is complex enough that hand-rolling modules becomes error-prone, and prefer reusing a library over reimplementing from scratch.

Why do my JAX and PyTorch gradients disagree in float32?▼

The mismatch is often float32 conditioning, such as catastrophic cancellation from a near-one-hot softmax, not a port bug. Recompute the disputed value in float64 on both sides; if float64 agrees to about 1e-6, keep float32 for the forward path and check gradient parity in float64.

How do I verify gradients when porting a NumPy optimization algorithm to JAX?▼

Compute jax.grad of the ported objective and compare against central finite differences with a tolerance loose enough for truncation error. Also test at nonzero inputs, since primitives correct at zero can still be wrong due to reshape or indexing bugs.

Can I port a reference that uses an inner solver like SciPy Brent?▼

Not bit-for-bit: a small fit difference moves the next query and trajectories diverge by construction. Parity the estimator on replayed inputs, verify the selection policy statistically across seeds, and treat the reference as the oracle for solver-produced numbers.