Back to Home

nanocode: coding agent pipeline on JAX

The nanocode library allows training a coding agent from scratch on JAX and TPU. The pipeline includes pretraining, synthetic generation, SFT and DPO. Models from 4 million to 1.3 billion parameters for experiments.

Train a coding agent for $200: nanocode on JAX
Advertisement 728x90

nanocode: Open Implementation of a Pipeline for a Coding Agent Based on Constitutional AI

Developer Salman Mohammadi from the torchtune team has released the nanocode library—an open framework in JAX for the full training cycle of a coding agent. The pipeline covers the tokenizer, pretraining, synthetic data generation, agentic SFT, and alignment via DPO with constitutional criticism. The main model with 1.3 billion parameters trains in 9 hours on TPU for $200. Smaller variants: 477 million parameters—1.5 hours ($34), 4 million—for CPU debugging.

The library is optimized for free TPUs via Google TRC and supports NVIDIA GPUs. All configurations run with a single bash script. The project continues Andrej Karpathy's nano series, focusing on agentic behavior: reading files, writing code, and executing terminal commands.

Full Pipeline Based on Constitutional AI Principles

nanocode replicates the Claude approach: five training stages from scratch.

Google AdInline article slot
  • Tokenizer: Trained on a coding corpus.
  • Pretraining: FineWeb-edu + The Stack v2.
  • Synthetic data: 120k short and 2k long multi-turn examples of agentic behavior.
  • Agentic SFT: Continued training with tools.
  • DPO alignment: Constitutional criticism for an RLHF-like effect.

This is the first open recipe for a full Constitutional AI pipeline for coding agents. The code is minimalist, reproducible, and free of external dependencies beyond JAX and the TPU ecosystem.

The models don't compete with commercial ones (hundreds of billions of parameters) but demonstrate end-to-end mechanics. For senior developers, it's a base for experiments with custom agents.

Configurations and Resources

| Model | Parameters | Time | Cost | Hardware |

Google AdInline article slot

|-----------|------------|--------|-------|-------------------|

| Main | 1.3B | 9h | $200 | TPU (Google TRC) |

| Medium | 477M | 1.5h | $34 | TPU/GPU |

Google AdInline article slot

| Debug | 4M | minutes| $0 | CPU |

  • TPU advantages: Free access, high JAX efficiency on multi-chip setups.
  • GPU support: Single cards; multi-chip in the works.
  • Running: bash run.sh --model_size=1.3B—all stages automated.

The library lets you dissect every stage: from tokenization to criticism generation in DPO.

Practical Use for Developers

For mid-level and senior specialists, nanocode is a tool for understanding the internals of coding agents. Capabilities:

  • Testing hypotheses on synthetic data (120k+ examples).
  • Customizing the tokenizer for a domain (e.g., Rust/Python).
  • Experiments with DPO: Tuning the constitution for ethical coding.
  • Scaling to local clusters.

The code is well-documented and modular. No black box—full control over the pipeline. Ideal for R&D in companies building internal tools.

Key Takeaways

  • Full open Constitutional AI pipeline for coding agents: from tokenizer to DPO.
  • 1.3B model for $200/9h on free TPUs—minimal barriers to entry.
  • Generation of 122k synthetic examples of agentic behavior.
  • JAX optimization, TPU/GPU, bash automation.
  • Not a Claude replacement, but an educational tool for dissecting the mechanics.

— Editorial Team

Advertisement 728x90

Read Next