-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Karpathy's AutoResearch with Memory-in-the-Loop States by The Adimension #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
habanwer
wants to merge
11
commits into
karpathy:master
Choose a base branch
from
habanwer:autoresearch/memory-in-the-loop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+621
−190
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
331367c
ground.json [NEW] — externalize platform config from karpathy/autores…
habanwer 1aa243a
model.json [NEW] — externalize hyperparameters from karpathy/autorese…
habanwer 235bc5c
prepare.py [MODIFIED +125/-17] — add GPU platform detection, read con…
habanwer 1ac6081
train.py [MODIFIED +194/-55] — load from model.json, import PLATFORM,…
habanwer 059b937
program.md [MODIFIED +96/-114] — structured agent protocol replacing …
habanwer 849b0fd
.gitignore [MODIFIED +5/-2] — update ignore rules for multi-GPU workflow
habanwer 64850c1
analysis.ipynb [MODIFIED metadata] — update kernel to Python 3.12.10
habanwer e382d90
README.md [MODIFIED] — add Memory-in-the-Loop fork introduction with …
habanwer 6181369
Address review feedback: fix eval_steps guard, ground.json validation…
habanwer ecab7a7
Agent Instructions - Experiment AutoResearch with Memory in the Loop
habanwer 1d3afbc
Merge branch 'karpathy:master' into autoresearch/memory-in-the-loop
habanwer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # autoresearch — agent instructions for https://github.com/habanwer/autoresearch/tree/autoresearch/memory-in-the-loop | ||
|
|
||
| ## 1. Orientation (do this first, every run) | ||
|
|
||
| Before making any changes, read and understand the codebase: | ||
|
|
||
| 1. Read `ground.json` — the user-owned, read-only configuration: | ||
| - `mode`: `"test"` or `"train"` — determines which time budget applies. | ||
| - `training.time_budget_test` / `training.time_budget_train` — the wall-clock seconds the training loop is allowed to run. **Respect this strictly.** | ||
| - `training.max_seq_len` — sequence length, fixed. | ||
| - `processor` — dtype, compile, flash_attention, peak_flops overrides (all `"auto"` by default). | ||
| 2. Read `model.json` — your hyperparameter file (you own this): | ||
| - `architecture`: depth, aspect_ratio, head_dim, window_pattern. | ||
| - `optimization`: batch sizes, learning rates, weight decay, adam betas, warmup/warmdown ratios, final_lr_frac. | ||
| - `evaluation`: batch_size, tokens (for the fast eval after training). | ||
| 3. Read `prepare.py` — understand but **never edit**: | ||
| - Exports: `MAX_SEQ_LEN`, `TIME_BUDGET`, `PLATFORM`, `Tokenizer`, `make_dataloader`, `evaluate_bpb`, `get_token_bytes`. | ||
| - `PLATFORM` dict: device, dtype, use_grad_scaler, attention, compile, peak_flops (auto-detected from GPU hardware specs). | ||
| 4. Read `train.py` — the model and training loop (you own this): | ||
| - Loads all hyperparameters from `model.json` at startup. | ||
| - Imports platform config from `prepare.py`. | ||
| - Prints a `---` separator followed by key=value summary lines at the end of training. | ||
| 5. Note the key metric: **`val_bpb`** (bits per byte) — lower is better. This is printed by `train.py` after the training loop completes. | ||
|
|
||
| ## 2. Decision metrics | ||
|
|
||
| Use these to guide your experiment choices: | ||
|
|
||
| | Metric | Source | Meaning | | ||
| |---|---|---| | ||
| | `val_bpb` | train.py stdout | Primary objective — minimize this | | ||
| | `peak_vram_mb` | train.py stdout | Must not OOM — watch this when increasing batch/model size | | ||
| | `mfu_percent` | train.py stdout | Hardware utilization — indicates if compute is bottlenecked | | ||
| | `training_seconds` | train.py stdout | Must stay within `TIME_BUDGET` | | ||
| | `total_tokens_M` | train.py stdout | Throughput — more tokens = more learning within budget | | ||
| | `num_params_M` | train.py stdout | Model capacity — larger is not always better under time constraint | | ||
|
|
||
| ## 3. File ownership | ||
|
|
||
| | File | Owner | Editable | Purpose | | ||
| |---|---|---|---| | ||
| | `ground.json` | User | **NO** | Platform config, data paths, time budgets | | ||
| | `prepare.py` | User | **NO** | Data prep, tokenizer, dataloader, eval, platform detection | | ||
| | `model.json` | Agent | **YES** | Architecture + optimization hyperparameters | | ||
| | `train.py` | Agent | **YES** | Model definition, optimizer, training loop | | ||
| | `results.tsv` | Agent | **YES** | Experiment log — append only | | ||
| | `program.md` | User | **NO** | This document | | ||
|
|
||
| ## 4. Execution sequence | ||
|
|
||
| ### First run (setup) | ||
|
|
||
| 1. Run `uv run prepare.py` to ensure data and tokenizer are cached. | ||
| 2. Initialize `results.tsv` with this exact header (tab-separated): | ||
|
|
||
| ``` | ||
| run_id\tval_bpb\tpeak_vram_mb\tmfu_percent\ttraining_seconds\ttotal_tokens_M\tnum_params_M\tstatus\tdescription | ||
| ``` | ||
|
|
||
| (Each `\t` above represents a literal tab character.) | ||
|
|
||
| 3. Run `uv run train.py`, capturing stdout to `sessions/<run_id>.log`. | ||
| - `run_id` = short git commit hash or a timestamp tag — unique per run. | ||
| 4. Parse the `---` block from the log to extract metrics. | ||
| 5. Append one row to `results.tsv` with the extracted values and `status=baseline`. | ||
|
|
||
| ### Subsequent runs (experiment loop) | ||
|
|
||
| 1. Form one hypothesis from the current code and most recent run metrics. | ||
| 2. Edit `model.json` and/or `train.py`. | ||
| 3. Commit with a message describing the hypothesis. | ||
| 4. Run `uv run train.py`, capturing stdout to `sessions/<run_id>.log` (use the new commit hash as `run_id`). | ||
| 5. Parse the `---` block. Extract `val_bpb`, `peak_vram_mb`, `mfu_percent`, `training_seconds`, `total_tokens_M`, `num_params_M`. | ||
| 6. Append one row to `results.tsv`: | ||
| - `status=keep` if val_bpb improved. | ||
| - `status=discard` if val_bpb did not improve. | ||
| - `status=crash` if the run failed. | ||
| 7. If `discard` or `crash`: revert with `git reset --hard HEAD~1`. | ||
| 8. Continue to next hypothesis. | ||
|
|
||
| ## 5. Logging rules | ||
|
|
||
| - Every run MUST have its own log file: `sessions/<run_id>.log`. | ||
| - Every run MUST have exactly one row appended to `results.tsv`. | ||
| - The `run_id` in `results.tsv` must match the log filename (without `.log`). | ||
| - Never overwrite or delete previous log files or results rows. | ||
|
|
||
| ## 6. Constraints | ||
|
|
||
| 1. **Time budget**: `train.py` self-enforces via `TIME_BUDGET` from `ground.json`. Do not circumvent this. | ||
| 2. **No new packages**: use only what is already installed in the environment. | ||
| 3. **Do not edit** `ground.json`, `prepare.py`, or `program.md`. | ||
| 4. **Prefer simpler changes** when two options yield similar `val_bpb`. | ||
| 5. **VRAM**: if a run OOMs, reduce `device_batch_size` in `model.json` or model size before retrying. | ||
|
|
||
| ## 7. Autonomy | ||
|
|
||
| Continue iterating experiments until manually stopped. Do not pause for permission between runs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "codename": "mar15-2-rtx5000", | ||
| "mode": "test", | ||
|
|
||
| "data": { | ||
| "cache_dir": "~/.cache/autoresearch", | ||
| "base_url": "https://huggingface.co/datasets/karpathy/climbmix-400b-shuffle/resolve/main", | ||
| "max_shard": 6542, | ||
| "val_shard": 6542, | ||
| "num_shards": 10, | ||
| "download_workers": 8 | ||
| }, | ||
|
|
||
| "tokenizer": { | ||
| "vocab_size": 8192, | ||
| "split_pattern": "'(?i:[sdmt]|ll|ve|re)|[^\\r\\n\\p{L}\\p{N}]?+\\p{L}+|\\p{N}{1,2}| ?[^\\s\\p{L}\\p{N}]++[\\r\\n]*|\\s*[\\r\\n]|\\s+(?!\\S)|\\s+", | ||
| "special_tokens_count": 4, | ||
| "bos_token": "<|reserved_0|>" | ||
| }, | ||
|
|
||
| "training": { | ||
| "max_seq_len": 2048, | ||
| "time_budget_test": 60, | ||
| "time_budget_train": 300, | ||
| "eval_tokens_multiplier": 40, | ||
| "eval_tokens_unit": 524288, | ||
| "max_run_wall_seconds": 30 | ||
| }, | ||
|
|
||
| "processor": { | ||
| "dtype": "auto", | ||
| "compile": "auto", | ||
| "flash_attention": "auto", | ||
| "peak_flops": "auto" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "architecture": { | ||
| "depth": 8, | ||
| "aspect_ratio": 128, | ||
| "head_dim": 64, | ||
| "window_pattern": "SL" | ||
| }, | ||
|
|
||
| "optimization": { | ||
| "total_batch_size_power": 17, | ||
| "device_batch_size": 16, | ||
| "embedding_lr": 0.1, | ||
| "unembedding_lr": 0.002, | ||
| "matrix_lr": 0.01, | ||
| "scalar_lr": 0.25, | ||
| "weight_decay": 0.01, | ||
| "adam_betas": [0.8, 0.95], | ||
| "warmup_ratio": 0.2, | ||
| "warmdown_ratio": 0.75, | ||
| "final_lr_frac": 0.1 | ||
| }, | ||
|
|
||
| "evaluation": { | ||
| "batch_size": 16, | ||
| "tokens": 3145728 | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.