simply
AGENTS.md584 starsChanged 43 days agoApache-2.0View on GitHub
Simply is a minimal JAX-based research codebase for LLM training and inference. It emphasizes minimal abstractions for rapid iteration on frontier research. The codebase supports Gemma, Qwen, and DeepSeek model families with multi-host distributed training.
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,843 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
The file
We split this AGENTS.md into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 99
Registry Pattern: All extensible components use dataclass + registry decorator:
- Very specific: line 191
Registry patterns: Use Registry.register_value() for instances (call with Registry.get_instance(name))
- Distinctive: line 203
Line length: Keep lines under 80 characters
- Distinctive: line 204
Hanging indents: Use 4 spaces for continuation lines.
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
This file provides guidance to AI coding agents working with code in this repository.
Project Overview
Simply is a minimal JAX-based research codebase for LLM training and inference. It emphasizes minimal abstractions for rapid iteration on frontier research. The codebase supports Gemma, Qwen, and DeepSeek model families with multi-host distributed training.
Common Commands
Installation
# Install JAX (environment-specific)
pip install -U jax # CPU
pip install -U "jax[cuda13]" # GPU
pip install -U "jax[tpu]" # TPU
# Install Simply and the extras you need
pip install ".[dev,agent,tfds,math-eval,serving,zoo,assets]"
# Download the tokenizers (~100 MB), or everything (~10 GB)
python setup/setup_assets.py --vocabs-only
python setup/setup_assets.pyRunning Experiments
# Local test run (needs the Qwen3 tokenizer and TFDS imdb_reviews)
python -m simply.main --experiment_config lm_test --experiment_dir /tmp/exp_1 --alsologtostderr
# Same model on synthetic data: no tokenizer, no dataset download
python -m simply.main --experiment_config lm_smoke_test --experiment_dir /tmp/exp_0 --alsologtostderr
# Debug mode (disable JIT for printing arrays)
export JAX_DISABLE_JIT=True
python -m simply.main --experiment_config lm_no_scan_test --experiment_dir /tmp/exp_1 --alsologtostderr
# TensorBoard monitoring
tensorboard --logdir /tmp/exp_1Testing
# Serving tests need the generated gRPC stubs (one-off, see setup/gen_protos.py)
pip install ".[serving]" && python setup/gen_protos.py
# Run all tests (`*_multi_device_test.py` files need their own process, below)
pytest simply/ --ignore-glob='*multi_device_test.py'
# Run specific test file
pytest simply/model_lib_test.py
# Run specific test
pytest simply/model_lib_test.py::ModelTest::test_forward_pass
# One process each: every `*_multi_device_test.py` forces its own CPU device
# count before JAX initializes its backend, which only works in a fresh
# process. A test that needs more than one device belongs in such a file.
for t in $(find simply -name '*multi_device_test.py'); do pytest "$t"; doneArchitecture
Core Modules (simply/)
- main.py - Entry point for training runs
- config_lib.py - Experiment and sharding configurations via registries
- model_lib.py - LLM architectures (Attention, TransformerBlock, TransformerLM, MoE)
- data_lib.py - Data pipeline setup using SeqIO and Grain
- rl_lib.py - RL training components (reward normalization, batching)
- colocate_async_rl_lib.py - Async RL train loop that colocates training and sampling on the same devices (uses the paged serving batcher; optional, it needs the generated gRPC stubs)
- tool_lib.py - Tool use and execution framework
Subpackages (simply/)
- agent/ - Minimal agent harness (Bash tool, context management, LiteLLM)
- eval/ - Decode-based evaluation entry points and model backends
- kernels/ - Pallas kernels (ragged paged attention, grouped matmul, remote-DMA reshard)
- serving/ - gRPC serving stack (paged/vanilla servers, batching,
KV prefix cache). Stubs are generated from
serving/*.proto. - tools/ - Offline utilities (checkpoint conversion, dataset serialization)
- zoo/ - Self-contained model plugins (
glm5,kimi_k3,qwen3p8); each registers its modules/configs on import
Utilities (simply/utils/)
- module.py - SimplyModule base class with registry pattern
- common.py - AnnotatedArray wrapper for metadata, PyTree types
- checkpoint_lib.py - Orbax-based checkpoint management
- sharding.py - Multi-host sharding patterns (FSDP, TP, Expert Parallelism)
- sampling_lib.py - Sampling schedules and input processing
- optimizers.py - Adam, AdamW, SGD with learning rate schedules
- moe_lib.py - MoE routing/dispatch, including pipelined expert parallelism
- quant.py - Quantization helpers (clip-scale search, packing)
- sweep.py - Config overlays and hyperparameter sweep expansion
Key Design Patterns
Registry Pattern: All extensible components use dataclass + registry decorator:
@SomeRegistry.register
@dataclasses.dataclass
class MyComponent:
param: intRegistries include: ExperimentConfigRegistry, ShardingConfigRegistry, ModuleRegistry, OptimizerRegistry, TrainLoopRegistry, ToolRegistry, TokenizerRegistry
AnnotatedArray: Model parameters are wrapped in AnnotatedArray for sharding annotations and metadata tracking throughout the codebase.
Configuration-Driven: Experiments are defined via registered configs in config_lib.py. Use --experiment_config <name> to select, or --experiment_config_path for external config files.
Environment Variables
SIMPLY_MODELS- Model checkpoint directory (default:~/.cache/simply/models/)SIMPLY_DATASETS- Dataset directory (default:~/.cache/simply/datasets/)SIMPLY_VOCABS- Vocabulary directory (default:~/.cache/simply/vocabs/)JAX_DISABLE_JIT- Set toTrueto disable JIT for debugging
Data Pipeline (data_lib.py)
The Grain-native data pipeline is in data_lib.py. Key concepts:
Registries
DataSourceRegistry- Raw data sources with__len__/__getitem__methods. Used viaDatasetConfig(source='name').DatasetConfigRegistry- Config dataclasses (for serialization) and preset config factory functions. Usedataset_config='preset_name'for string shorthand.
Configuration Classes
TFDSSource- TFDS dataset name and splitHFSource- HuggingFace datasets (name, split, subset)ArrayRecordSource- ArrayRecord files (supports glob patterns)DatasetConfig- Single dataset configurationMixtureConfig- Multiple datasets with weights
DatasetConfig Fields
@dataclasses.dataclass
class DatasetConfig:
source: str | TFDSSource | HFSource | ArrayRecordSource
lm_format_name: str | None = 'Pretrain' # None = raw
packing: str = 'concat_split'
data_key: str = 'text'
tokenizer_name: str | None = None
add_eos: bool = True
add_bos: bool = True
trainable_roles: tuple[str, ...] | None = None # For chat: roles in losslm_format_name (Tokenization Control)
None- Raw: skip tokenization, data passed through as-is'Pretrain'- TokenizeTransform + NextTokenPredTransform'SimplyV1Chat'etc. - ChatFormatTransform + NextTokenPredTransform
packing (Packing Control)
'concat_split'- Concatenate then split (best throughput, for pretraining)'first_fit'- Bin packing preserving boundaries (for chat/SFT)'pad_or_truncate'- Simple pad/truncate (for validation)'none'- No packing (for raw data)
Note: Validation mode automatically overrides packing to 'pad_or_truncate'.
MixtureConfig
MixtureConfig(
datasets=((DatasetConfig(...), 0.7), (DatasetConfig(...), 0.3)),
pack_before_mix=False, # False = mix then pack, True = pack then mix
)String Shorthand for dataset_config
dataset_config can be a string that looks up a preset from DataConfigRegistry:
# Register a preset
@DatasetConfigRegistry.register
def c4_train_pt():
return DatasetConfig(
source=TFDSSource(name='c4:3.1.0', split='train'),
lm_format_name='Pretrain',
)
# Use in experiment config
dataset_config = 'c4_train_pt'Key Learnings
- Token IDs from tokenizer:
bos_id,eos_id,pad_idcome from tokenizer - Grain mp_prefetch: Handles 0 workers gracefully (no-op)
- Registry patterns: Use
Registry.register_value()for instances (call withRegistry.get_instance(name)) - Chat tokenization:
LMFormat.format_tokens()is the single source of truth for chat formatting + tokenization.ChatFormatTransformdelegates to it. - ArrayRecord glob:
ArrayRecordSourcesupports glob patterns (expanded before passing toArrayRecordDataSource) - Registry serialization:
pytree.dump()/load()serializes dataclass instances using__registered_name__. Factory functions in same registry are fine - they return instances that serialize correctly (same pattern as ExperimentConfigRegistry).
Code Style
- Line length: Keep lines under 80 characters
- Hanging indents: Use 4 spaces for continuation lines. When arguments to a function call or items in a list/dictionary span multiple lines, indent continuation lines by exactly 4 spaces relative to the start of the line that begins the statement.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

