Skip to content

Commit 654f446

Browse files
Adopt AGENTS.md convention for maintainer docs
Move maintainer guidance into AGENTS.md files (at the repo root and under rapidfireai/fit/{backend,db,dispatcher,ml,utils} and rapidfireai/frontend) and leave each CLAUDE.md as a thin `@AGENTS.md` pointer, so every agent that follows the AGENTS.md convention reads the same project rules as Claude Code. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent beca285 commit 654f446

14 files changed

Lines changed: 2306 additions & 2210 deletions

File tree

AGENTS.md

Lines changed: 402 additions & 0 deletions
Large diffs are not rendered by default.

CLAUDE.md

Lines changed: 1 addition & 373 deletions
Original file line numberDiff line numberDiff line change
@@ -1,373 +1 @@
1-
# CLAUDE.md
2-
3-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4-
5-
## Project Overview
6-
7-
RapidFire AI is an experiment execution framework for LLM fine-tuning and post-training that enables hyperparallelized training, dynamic real-time experiment control (IC Ops), and automatic multi-GPU orchestration. The system uses chunk-based scheduling to allow concurrent training of multiple configurations even on a single GPU.
8-
9-
## Key Commands
10-
11-
### Development Setup
12-
13-
```bash
14-
# Create and activate virtual environment
15-
python3 -m venv .venv
16-
source .venv/bin/activate
17-
18-
# Install dependencies from source
19-
pip install -r requirements.txt
20-
21-
# Install Node.js 22.x and build frontend
22-
cd rapidfireai/frontend
23-
node ./yarn/releases/yarn-4.9.1.cjs install
24-
node ./yarn/releases/yarn-4.9.1.cjs build
25-
cd ../..
26-
27-
# Start all services in development mode
28-
chmod +x ./rapidfireai/start_dev.sh
29-
./rapidfireai/start_dev.sh start
30-
31-
# Stop services
32-
./rapidfireai/start_dev.sh stop
33-
```
34-
35-
### Running from Installed Package
36-
37-
```bash
38-
# Initialize RapidFire (installs dependencies, copies tutorials)
39-
rapidfireai init
40-
41-
# Start RapidFire servers (dispatcher, mlflow, frontend)
42-
rapidfireai start
43-
44-
# Stop all servers
45-
rapidfireai stop
46-
47-
# System diagnostics (GPU, CUDA, Python env)
48-
rapidfireai doctor
49-
50-
# Check version
51-
rapidfireai --version
52-
```
53-
54-
### Testing
55-
56-
```bash
57-
# Run all tests
58-
pytest
59-
60-
# Run specific test file
61-
pytest tests/test_chunks.py
62-
63-
# Run with verbose output
64-
pytest -v
65-
```
66-
67-
### Code Quality
68-
69-
```bash
70-
# Format code with ruff (line-length: 120)
71-
ruff format .
72-
73-
# Run linter
74-
ruff check .
75-
76-
# Fix auto-fixable issues
77-
ruff check --fix .
78-
```
79-
80-
### Building and Releasing
81-
82-
```bash
83-
# Build PyPI package (requires frontend build first)
84-
rm -rf dist/ *.egg-info/ .eggs/ && python -m build
85-
86-
# Bump version (creates commit and tag)
87-
./bump_version.sh patch # 0.10.1 → 0.10.2
88-
./bump_version.sh minor # 0.10.1 → 0.11.0
89-
./bump_version.sh major # 0.10.1 → 1.0.0
90-
91-
# Push version tag to trigger TestPyPI deployment
92-
git push origin test0.10.2
93-
```
94-
95-
### Port Management
96-
97-
```bash
98-
# Kill services on specific ports if conflicts occur
99-
lsof -t -i:8851 | xargs kill -9 # dispatcher
100-
lsof -t -i:8852 | xargs kill -9 # mlflow
101-
lsof -t -i:8853 | xargs kill -9 # frontend
102-
```
103-
104-
## Architecture
105-
106-
RapidFire AI uses a microservices-inspired distributed architecture:
107-
108-
### Core Components
109-
110-
1. **Experiment** (`experiment.py`): Top-level API for users. Manages experiment lifecycle, creates database tables, sets up logging and signal handlers. Entry point for `run_fit()` and `get_results()`.
111-
112-
2. **Controller** (`backend/controller.py`): Orchestrates the entire training lifecycle. Runs in the user's process. Responsible for:
113-
- Creating models from parameter configurations
114-
- Initializing and managing Workers
115-
- Running the Scheduler to assign chunks to workers
116-
- Handling Interactive Control Operations (IC Ops)
117-
- Monitoring training progress
118-
119-
3. **Scheduler** (`backend/scheduler.py`): Pure scheduling logic that assigns runs to available workers for specific chunks. Uses round-robin and fairness algorithms to ensure optimal GPU utilization. Tracks which runs have completed which chunks.
120-
121-
4. **Worker** (`backend/worker.py`): Separate GPU processes that execute actual training. Each worker:
122-
- Polls database for assigned tasks
123-
- Loads model checkpoints from shared memory or disk
124-
- Trains on assigned data chunks
125-
- Saves checkpoints back to shared memory/disk
126-
- Reports progress to MLflow
127-
128-
5. **Dispatcher** (`dispatcher/dispatcher.py`): Flask-based REST API for UI communication. Provides endpoints for:
129-
- Viewing experiment status
130-
- Interactive Control Operations (stop, resume, clone, delete runs)
131-
- Real-time run metrics
132-
133-
6. **Database** (`db/rf_db.py`): SQLite-based persistence layer with async operations. Stores:
134-
- Experiment metadata
135-
- Run configurations and status
136-
- Task scheduling state
137-
- Checkpoint locations
138-
139-
7. **Frontend** (`frontend/`): React-based dashboard (MLflow fork) with IC Ops panel. Displays live experiment tracking and enables dynamic control.
140-
141-
### Data Flow
142-
143-
1. User creates `Experiment` and calls `run_fit()` with configs and datasets
144-
2. Controller creates runs in database and spawns Worker processes
145-
3. Controller runs Scheduler loop to assign (run_id, chunk_id) to available workers
146-
4. Workers poll database, load models, train on chunks, save checkpoints
147-
5. Workers report metrics to MLflow and update database task status
148-
6. Scheduler continues until all runs complete all chunks (epochs)
149-
7. User can invoke IC Ops through UI to stop/resume/clone runs mid-training
150-
151-
### Shared Memory System
152-
153-
RapidFire uses shared memory (`utils/shm_manager.py`) to avoid disk I/O bottlenecks:
154-
- Model checkpoints stored in shared memory between chunks (configurable via `USE_SHARED_MEMORY`)
155-
- Registry tracks which models are in memory
156-
- Process locks prevent concurrent access issues
157-
- Fallback to disk for larger models
158-
159-
### Interactive Control (IC Ops)
160-
161-
Unique feature enabling real-time experiment control:
162-
- **Stop**: Pause a run, saves checkpoint
163-
- **Resume**: Restart a stopped run from checkpoint
164-
- **Clone**: Create new run from existing, optionally warm-start from parent's weights
165-
- **Delete**: Remove unwanted runs
166-
167-
Implemented via database state changes that Controller/Workers poll.
168-
169-
## Directory Structure
170-
171-
```
172-
rapidfireai/
173-
├── automl/ # Grid search, random search, AutoML algorithms
174-
├── backend/ # Controller, Scheduler, Worker, Chunks
175-
├── db/ # SQLite database interface
176-
├── dispatcher/ # Flask REST API for UI
177-
├── frontend/ # React dashboard (MLflow fork with IC Ops)
178-
├── ml/ # Trainer classes, checkpoint utils, callbacks
179-
├── utils/ # Logging, MLflow manager, shared memory, serialization
180-
├── experiment.py # Main Experiment class (user-facing API)
181-
├── cli.py # CLI commands (rapidfireai start/stop/init/doctor)
182-
├── start.sh # Production server startup script
183-
├── start_dev.sh # Development mode startup script
184-
└── version.py # Version number
185-
```
186-
187-
## Key Concepts
188-
189-
### Chunk-Based Training
190-
191-
Instead of training one model at a time for full epochs, RapidFire splits datasets into chunks and interleaves training:
192-
- Dataset divided into N chunks (user configurable)
193-
- Multiple runs train on different chunks concurrently
194-
- Scheduler ensures fair distribution across GPUs
195-
- Enables side-by-side comparison of hyperparameters with minimal latency
196-
197-
### Run Configuration
198-
199-
Runs are created from parameter configurations:
200-
- Single dict: creates one run
201-
- AutoML algorithms (GridSearch, RandomSearch): create multiple runs
202-
- Each run gets unique ID, tracked in database
203-
- Supports warm starting from parent runs (clone-modify)
204-
205-
### Task System
206-
207-
Database tracks tasks for coordination:
208-
- **ExperimentTask**: High-level experiment state
209-
- **ControllerTask**: Controller operations (create_models, schedule, etc.)
210-
- **WorkerTask**: Worker operations (fit, validate, etc.)
211-
- Status: PENDING → IN_PROGRESS → COMPLETED/FAILED
212-
213-
## MLflow Integration
214-
215-
RapidFire wraps MLflow for experiment tracking:
216-
- Each RapidFire Experiment maps to an MLflow experiment
217-
- Runs tracked with metrics, parameters, artifacts
218-
- Checkpoints saved as MLflow artifacts
219-
- UI extends MLflow with IC Ops panel
220-
- Access MLflow directly at `http://localhost:8852`
221-
222-
## Development Notes
223-
224-
### Python Version
225-
226-
Requires Python 3.12.x (specified in pyproject.toml and README).
227-
228-
### Frontend Development
229-
230-
The frontend is a fork of MLflow. For frontend-specific guidance, see `rapidfireai/frontend/CLAUDE.md`.
231-
232-
To run frontend in development mode with hot reload:
233-
```bash
234-
cd rapidfireai/frontend
235-
node ./yarn/releases/yarn-4.9.1.cjs start # Runs on localhost:8853
236-
```
237-
238-
### Database Schema
239-
240-
Defined in `db/*.sql` files. Tables include:
241-
- experiments: Experiment metadata and paths
242-
- runs: Run configurations, status, metrics
243-
- tasks: Task queue for controller-worker coordination
244-
- checkpoints: Checkpoint locations and metadata
245-
246-
### Environment Variables
247-
248-
- `RF_EXPERIMENT_PATH`: Base path for experiments (default: `./rapidfire_experiments`)
249-
- `RF_TUTORIAL_PATH`: Path for tutorial notebooks (default: `./tutorial_notebooks`)
250-
- `RF_MLFLOW_HOST`: MLflow tracking server Host (default: `localhost`)
251-
- `RF_MLFLOW_PORT`: MLflow tracking server Port (default: `8852`)
252-
- `USE_SHARED_MEMORY`: Enable shared memory for checkpoints (default: True)
253-
254-
### Logging
255-
256-
Multi-logger system using loguru:
257-
- `experiment`: Experiment-level logs
258-
- `controller`: Controller operations
259-
- `worker_{N}`: Per-worker training logs
260-
- `user`: User-facing messages
261-
- `interactive-control`: IC Ops operations
262-
263-
Logs written to experiment directory.
264-
265-
### Testing Notebooks
266-
267-
Tutorial notebooks in `tutorial_notebooks/` demonstrate usage:
268-
- Require HuggingFace token for model downloads
269-
- Run via `jupyter notebook` or IDE with proper kernel
270-
- Cannot run directly from CLI due to multiprocessing restrictions
271-
272-
## Common Patterns
273-
274-
### Creating an Experiment
275-
276-
```python
277-
from rapidfireai import Experiment
278-
279-
exp = Experiment("my_experiment")
280-
exp.run_fit(
281-
param_config=config_dict_or_automl,
282-
create_model_fn=my_model_factory,
283-
train_dataset=train_data,
284-
eval_dataset=eval_data,
285-
num_chunks=8,
286-
seed=42
287-
)
288-
results_df = exp.get_results()
289-
```
290-
291-
### Defining Model Factory
292-
293-
```python
294-
def create_model_fn(config):
295-
# config contains hyperparameters for this run
296-
model = YourModel(**config)
297-
return model, optimizer, loss_fn, trainer_config
298-
```
299-
300-
### AutoML Usage
301-
302-
```python
303-
from rapidfireai.automl import GridSearch
304-
305-
param_config = GridSearch({
306-
'learning_rate': [1e-4, 1e-5, 1e-6],
307-
'batch_size': [8, 16],
308-
'epochs': [3]
309-
})
310-
```
311-
312-
## Git Workflow
313-
314-
Current branch: `feat/enable-colab`
315-
Main branch: `main`
316-
317-
Use standard PR workflow to merge features into main.
318-
319-
## Dependencies
320-
321-
Core dependencies (see pyproject.toml for full list):
322-
- torch >= 2.8.0
323-
- transformers >= 4.55.2
324-
- peft >= 0.17.0
325-
- trl == 0.21.0
326-
- mlflow >= 3.2.0
327-
- flask >= 3.1.1
328-
329-
Dev dependencies:
330-
- pytest >= 8.4.1
331-
- black >= 21.0
332-
- ruff (via ruff.toml)
333-
- mypy >= 0.800
334-
335-
## README Guidelines
336-
337-
### Image URLs Must Be Absolute
338-
339-
Always use absolute URLs for images in `README.md`, not relative paths. The README is rendered on multiple platforms (GitHub, PyPI, npm, etc.), and relative paths only work on GitHub where the repository file structure is accessible.
340-
341-
**Correct:**
342-
```markdown
343-
<img src="https://raw.githubusercontent.com/RapidFireAI/rapidfireai/main/docs/images/example.svg">
344-
```
345-
346-
**Incorrect:**
347-
```markdown
348-
<img src="docs/images/example.svg">
349-
```
350-
351-
Use the pattern `https://raw.githubusercontent.com/RapidFireAI/rapidfireai/main/...` for all image references to ensure cross-platform compatibility.
352-
353-
## Troubleshooting
354-
355-
### GPU Issues
356-
357-
Run `rapidfireai doctor` to diagnose:
358-
- CUDA installation
359-
- GPU availability
360-
- Driver version compatibility
361-
362-
### Port Conflicts
363-
364-
Common ports:
365-
- 8853: Frontend dashboard
366-
- 8852: MLflow tracking server
367-
- 8851: Dispatcher API
368-
369-
Use port killing commands above if conflicts occur.
370-
371-
### Multiprocessing Issues
372-
373-
RapidFire uses `spawn` method for multiprocessing. Notebooks must be run through IDE or Jupyter, not CLI.
1+
@AGENTS.md

0 commit comments

Comments
 (0)