You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extend docs/AGENTS.md with code-integration patterns for the Experiment API
(RAG/eval, SFT, DPO, GRPO), the AutoML config-group reference, and the
experiment lifecycle, so AI coding agents can wire rapidfireai into a user's
own project, not just install it.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/AGENTS.md
+123-8Lines changed: 123 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
# RapidFire AI — Agent Install & Setup Guide
1
+
# RapidFire AI — Agent Integration Guide
2
2
3
-
Operational instructions for **AI coding agents** (Claude Code, Cursor, Codex, GitHub Copilot, Windsurf, Aider, Junie, and similar) that are helping an end user install, configure, and run the `rapidfireai` Python package.
3
+
Operational instructions for **AI coding agents** (Claude Code, Cursor, Codex, GitHub Copilot, Windsurf, Aider, Junie, and similar) that are helping an end user install, configure, and integrate the `rapidfireai` Python package into the user's own project.
4
4
5
5
This file is **not** for rapidfireai contributors. If you are working *on* rapidfireai itself, stop and read the repo's root [`AGENTS.md`](https://github.com/RapidFireAI/rapidfireai/blob/main/AGENTS.md) and [`CONTRIBUTING.md`](https://github.com/RapidFireAI/rapidfireai/blob/main/CONTRIBUTING.md) instead.
6
6
@@ -13,6 +13,7 @@ This guide does **not** restate version-specific install commands, package versi
13
13
What this guide *does* provide that the README does not:
14
14
15
15
- A workflow decision tree (RAG vs fine-tuning vs post-training; OpenAI vs self-hosted; lite vs full).
16
+
- Code integration patterns for the `Experiment` API and the AutoML config groups.
16
17
- Trainer-type taxonomy for fine-tuning (`SFT` / `DPO` / `GRPO`).
17
18
- Safety rules for handling user secrets, GPU assumptions, and gated model access.
18
19
@@ -39,7 +40,7 @@ Pick a branch **before** running any install commands — the two workflows inst
39
40
### Environment selectors
40
41
41
42
-**Remote / cloud machine** → an SSH port-forward is required to view the dashboard locally. The set of ports differs by workflow (smaller for fit, larger for evals because Jupyter and MLflow are also exposed). The current port set and the exact `ssh` command are in the README §Install — read them from there, do not memorize.
42
-
-**GPU issues** (CUDA absent, OOM, driver mismatch) → run `rapidfireai doctor` and act on its output. For OOM, switch the user to a *lite* tutorial variant (see §6).
43
+
-**GPU issues** (CUDA absent, OOM, driver mismatch) → run `rapidfireai doctor` and act on its output. For OOM, switch the user to a *lite* tutorial variant (see §9).
43
44
-**Hugging Face permission issues** → confirm the user has run the README's HF auth step and has been granted access on the gated model's HF page. If access is blocked, suggest an open-license substitute (TinyLlama, Qwen-0.5B/3B) where licensing permits.
44
45
45
46
The exact CLI flag name for the evals init mode and the exact set of port numbers are intentionally not restated here — see the README, which is the authoritative install reference.
@@ -60,7 +61,7 @@ Run the steps in the order below. The **commands** are in the README; the **deci
60
61
8.**Run `rapidfireai doctor`** and confirm no critical failures (Python, GPU/CUDA where applicable, ports, packages). Do not proceed past failures without diagnosing the root cause.
61
62
9.**Start the dashboard stack** with `rapidfireai start` (frontend, MLflow, dispatcher). For the RAG/evals workflow, also start a Jupyter listener as documented in the README — the evals tutorials run inside Jupyter rather than an arbitrary IDE notebook.
62
63
10.**(Remote/cloud machines only) Port-forward** the workflow-appropriate set with `ssh`*before* clicking the dashboard URL. The current set and SSH syntax are in README §Install. VS Code typically auto-forwards the dashboard port; other clients require the explicit `ssh -L` invocation. Skip this step on a local machine.
63
-
11.**Open the tutorial notebook** under `./tutorial_notebooks/` (see §6 for the filename matching the workflow). Two non-obvious requirements:
64
+
11.**Open the tutorial notebook** under `./tutorial_notebooks/` (see §9 for the filename matching the workflow). Two non-obvious requirements:
64
65
- Notebooks **cannot** run via `python notebook.ipynb` — there is a multiprocessing restriction. Open the notebook in an IDE that supports Jupyter (VS Code, Cursor, JetBrains), or use `rapidfireai jupyter` (mandatory for the RAG/evals tutorials).
65
66
- The notebook's kernel **must** be set to the `.venv` you created in step 2, not the system Python; otherwise `import rapidfireai` fails. In VS Code / Cursor, click the kernel selector in the upper-right of the notebook and pick the venv interpreter.
66
67
- The dashboard URL printed by `rapidfireai start` (or by `rapidfireai jupyter` for evals) shows live run progress as cells execute.
@@ -81,7 +82,119 @@ Run the steps in the order below. The **commands** are in the README; the **deci
81
82
82
83
---
83
84
84
-
## 5. Troubleshooting
85
+
## 5. Code integration patterns
86
+
87
+
The four patterns below cover every supported workflow. Each is the *minimum* a user needs.
88
+
89
+
### A. RAG / evaluation
90
+
91
+
```python
92
+
from rapidfireai import Experiment
93
+
from rapidfireai.automl import RFGridSearch, List, RFvLLMModelConfig
-`create_model_fn(model_config) -> (model, tokenizer)` — required. Loads model and tokenizer from the per-run config dict.
144
+
-`formatting_func(row) -> dict` — optional. Returned in `RFModelConfig`. Maps a dataset row to `{"prompt": ..., "completion": ...}`.
145
+
-`compute_metrics(preds, labels) -> dict[str, float]` — optional. Returned in `RFModelConfig`.
146
+
147
+
### C. DPO (preference alignment)
148
+
149
+
Same shape as SFT but `trainer_type="DPO"`. The training dataset must have `chosen` and `rejected` columns (or whatever the chosen DPO config maps to). A reference model is handled internally; the user does not have to construct one explicitly.
150
+
151
+
### D. GRPO (RL-based post-training)
152
+
153
+
Same shape as SFT but `trainer_type="GRPO"`. Reward functions are passed via the trainer config, not as a separate argument. Use a small model and a small dataset for first runs — GRPO samples multiple generations per prompt and is significantly slower than SFT/DPO.
154
+
155
+
---
156
+
157
+
## 6. Config groups and search
158
+
159
+
Imports:
160
+
161
+
```python
162
+
from rapidfireai.automl import RFGridSearch, RFRandomSearch, List, Range
-**Evals mode**: `RFGridSearch({"vllm_config": List([...]), "preprocess_fn": ..., ...})` — dict form. **No `trainer_type`** (evals does inference, not training).
167
+
-`RFRandomSearch(configs, num_runs, trainer_type=...)` — sampled variant. `trainer_type` is again fit-only.
168
+
-`List([a, b, c])` and `Range(min=..., max=...)` define sweep dimensions and work in both modes.
169
+
170
+
Fit-mode config classes (from `rapidfireai.automl`): `RFModelConfig`, `RFLoraConfig`, `RFSFTConfig`, `RFDPOConfig`, `RFGRPOConfig`. Evals-mode config classes: `RFvLLMModelConfig`, `RFAPIModelConfig`, plus helpers `RFLangChainRagSpec` and `RFPromptManager`.
171
+
172
+
---
173
+
174
+
## 7. Experiment lifecycle
175
+
176
+
`rapidfireai start` (the CLI command) and `Experiment(...)` (the Python constructor) are distinct concerns:
177
+
178
+
-`rapidfireai start` brings up the **visual stack** (frontend dashboard, MLflow tracking, dispatcher API) so the user can watch runs live.
179
+
-`Experiment(...)` separately starts an in-process dispatcher thread for the API calls it needs internally.
180
+
181
+
Users typically run `rapidfireai start` first (to get the dashboard), then run their notebook or script which constructs `Experiment(...)`. The CLI `start` is **not strictly required** for `Experiment(...)` to function — but without it the dashboard UI is unavailable.
182
+
183
+
API surface (from `rapidfireai.experiment`):
184
+
185
+
-`Experiment(name, mode="fit" | "evals")` — `mode` defaults to `"fit"`. `name` is required.
186
+
-`run_fit(...)` — fit mode only. Blocking on non-Colab; async on Colab.
-`get_results()` — fit mode only. Returns a pandas `DataFrame` of metrics.
189
+
-`get_runs_info()` — fit mode only. Returns a pandas `DataFrame` of run metadata.
190
+
-`cancel_current()` — both modes. Cancels an in-flight task.
191
+
-`end()` — both modes. **Required** for clean shutdown of worker processes / Ray.
192
+
193
+
Only `Experiment` is exported at the top level. AutoML primitives are imported from `rapidfireai.automl`.
194
+
195
+
---
196
+
197
+
## 8. Troubleshooting
85
198
86
199
Match the symptom to the diagnostic direction. Specific commands (kill-by-port, SSH-forward, hf-xet uninstall, etc.) are in README §Troubleshooting and §Install — do not paste them from memory.
87
200
@@ -100,7 +213,7 @@ Match the symptom to the diagnostic direction. Specific commands (kill-by-port,
100
213
101
214
---
102
215
103
-
## 6. Tutorials
216
+
## 9. Tutorials
104
217
105
218
After `rapidfireai init`, tutorial notebooks are copied to `./tutorial_notebooks/`. Always prefer the on-disk copy — it matches the installed version.
## 7. Validation checklist (run before reporting "done")
233
+
## 10. Validation checklist (run before reporting "done")
121
234
122
235
Before telling the user setup is complete, confirm each:
123
236
@@ -128,12 +241,14 @@ Before telling the user setup is complete, confirm each:
128
241
5.`rapidfireai start` brought up the stack without errors. The user can reach the dashboard URL printed by `start`.
129
242
6. (Remote/cloud) The `ssh -L` forward is active in a separate terminal.
130
243
7. (Tutorial path) The notebook's kernel is the project `.venv`, not the system Python. The first import cell (`from rapidfireai import Experiment`) runs without `ImportError`.
244
+
8. (Code-integration done) `Experiment(...)` constructs without raising; the user's `create_model_fn` (fit) or `preprocess_fn` (evals) runs on a single example without error.
245
+
9.`experiment.end()` is called at the end of the user's script/notebook.
131
246
132
247
If any check fails, stop and diagnose — do not paper over with retries.
133
248
134
249
---
135
250
136
-
## 8. References
251
+
## 11. References
137
252
138
253
-**Canonical install instructions and troubleshooting**: <https://github.com/RapidFireAI/rapidfireai/blob/main/README.md>
0 commit comments