Update AGENTS.md with verified safetensors sizes and PYTHONPATH=code
Browse files31 unmodified lines32333435363738394036 unmodified lines77787980818283848512 unmodified lines98991001011021031041051061078 unmodified lines11611711811912012112212312412516 unmodified lines14214314414514614714814915015115215315415531 unmodified lines## 2. Current State (End of Session 1)- **HF Repository**: `Cortex-Intelligence/Cortex-OSS-Flash-1.0` (private)- **Checkpoint Format**: Pure **`.safetensors` + JSON** (zero `.pt` pickle files):- `model.safetensors` (repo root & `checkpoint/latest/`): dense model weights & buffers (~340 MiB)- `checkpoint/latest/rank-{0..3}.safetensors`: 4-way sharded Engram + UltraMemV2 sparse tables & Adam states, sharded NorMuon/AdamW tensors, RNG state tensors (~8.3 GiB/rank, ~33.3 GiB total)- `checkpoint/latest/rank-{0..3}_meta.json`: exact step, tokens seen, per-source stream cursors (`file_idx`, `row_group_idx`, `doc_in_rg`, `epoch`, `seqs_consumed`), mixer RNG state, `depth_rng_state`, `opt_dense` metadata- `checkpoint/latest/train_state.json`: run summary & per-dataset token counts- **Progress**:36 unmodified lines- Use **`HF_XET_HIGH_PERFORMANCE=1`** instead β it achieves ~100 MB/s+ (33.3 GiB uploaded in ~3 minutes).7. **Always reserve ~20β25 minutes of wall-clock margin inside your GPU budget**:- Final validation + checkpoint save takes ~45s; uploading 33.3 GiB to HF takes ~3β4 minutes. Set `--max-wall-seconds` to `(remaining_gpu_seconds - 1500)`.8. **Never write `HF_TOKEN` into workspace files, logs, or chat messages**:- Pass `HF_TOKEN` only via environment variable at runtime.9. **Always use `PYTHONPATH=.` if running scripts under `scripts/`** (not needed when running `train_stage1_cortex.py` from workspace root).10. **Watch `TotL` vs `LML` when reading logs**:- `TotL` includes `0.25*ECHO + 0.15*r_mid + 0.25*mono_hinge + aux`. Compare **`LML`** (not `TotL`) against held-out validation loss.12 unmodified linespython -c 'import torch, safetensors, flash_attn, liger_kernel, fla; print("ALL KERNELS OK:", torch.cuda.device_count(), "GPUs")'```### Step 2: Download latest `.safetensors` checkpoint from HF Hub to local SSD (~3 minutes)(Skip this step if `~/cortex_ckpts/latest_safetensors` is already on the same node's local SSD.)```bashHF_TOKEN=<your_token> HF_XET_HIGH_PERFORMANCE=1 python -c 'import osfrom huggingface_hub import snapshot_downloadsnapshot_download(8 unmodified lines```The resume directory is `~/cortex_hf_resume/checkpoint/latest` (contains `model.safetensors`, `rank-{0..3}.safetensors`, `rank-{0..3}_meta.json`, `train_state.json`).### Step 3: Launch resumed Stage 1 pretraining (4Γ A100-80GB)Set `--max-wall-seconds` to `(your_gpu_budget_seconds - 1500)` (e.g., `14400` for a 4.5h budget after ~5 min setup/download):```bashHF_TOKEN=<your_token> HF_XET_HIGH_PERFORMANCE=1 TOKENIZERS_PARALLELISM=false PYTHONUNBUFFERED=1 \torchrun --nproc_per_node=4 --master_port=29500 train_stage1_cortex.py \--manifest data_manifests/stage1_manifest.json \--tokenizer-path tokenizer/tokenizer.json \16 unmodified lines--fim-rate-other 0.10 \--skip-preflight```**What to expect on resume**:- Step `15,522` will take ~10β13 minutes on a fresh node (one-time `torch.compile` autotune), then steady-state runs at **`~335β350k tok/s`** (~0.76s/step).- Step `15,522` should resume with **zero loss spike** (`LML ~ 2.2β2.5`, `MemEnt ~ 0.997`, `MaxLd ~ 3Γ`, `lr_scale = 1.000`, `tokens_seen_B = 4.069`).- Checkpoints save in pure `.safetensors` + JSON every 2,500 steps (~45s) and cleanly at `--max-wall-seconds` into `~/cortex_ckpts/latest`.### Step 4: Upload final `.safetensors` checkpoint to HF Hub (~3 minutes)```bashHF_TOKEN=<your_token> HF_XET_HIGH_PERFORMANCE=1 PYTHONUNBUFFERED=1 python scripts/upload_to_hf.py \--repo-id Cortex-Intelligence/Cortex-OSS-Flash-1.0 \--ckpt-dir ~/cortex_ckpts/latest \--tokenizer-dir tokenizer \31 unmodified lines32333435363738394036 unmodified lines77787980818283848512 unmodified lines98991001011021031041051061078 unmodified lines11611711811912012112212312412516 unmodified lines14214314414514614714814915015115215315415531 unmodified lines## 2. Current State (End of Session 1)- **HF Repository**: `Cortex-Intelligence/Cortex-OSS-Flash-1.0` (private)- **Checkpoint Format**: Pure **`.safetensors` + JSON** (zero `.pt` pickle files, end-to-end 4-rank resume β save β reload verified):- `model.safetensors` (repo root & `checkpoint/latest/`): dense model weights & buffers (**220.21 MiB**, 133 tensors)- `checkpoint/latest/rank-{0..3}.safetensors`: 4-way sharded Engram + UltraMemV2 sparse tables & Adam states, sharded NorMuon/AdamW tensors, RNG state tensors (`8.28 / 8.26 / 8.26 / 8.26 GiB`, `33.06 GiB` sharded + `0.22 GiB` dense = `33.29 GiB` total)- `checkpoint/latest/rank-{0..3}_meta.json`: exact step, tokens seen, per-source stream cursors (`file_idx`, `row_group_idx`, `doc_in_rg`, `epoch`, `seqs_consumed`), mixer RNG state, `depth_rng_state`, `opt_dense` metadata- `checkpoint/latest/train_state.json`: run summary & per-dataset token counts- **Progress**:36 unmodified lines- Use **`HF_XET_HIGH_PERFORMANCE=1`** instead β it achieves ~100 MB/s+ (33.3 GiB uploaded in ~3 minutes).7. **Always reserve ~20β25 minutes of wall-clock margin inside your GPU budget**:- Final validation + checkpoint save takes ~45s; uploading 33.3 GiB to HF takes ~3β4 minutes. Set `--max-wall-seconds` to `(remaining_gpu_seconds - 1500)`.8. **Never write `HF_TOKEN` into workspace files, chat messages, OR inline shell command strings**:- Passing `HF_TOKEN=...` inline on a bash command line exposes it in command logs (`.bg-logs/`). Always store `HF_TOKEN` as an environment secret (e.g., via Qualia Secrets / `request_secret`) so scripts read `os.environ["HF_TOKEN"]` without exposing it in logs. Rotate any token that was previously pasted in chat or shell commands.9. **Always use `PYTHONPATH=.` (or `PYTHONPATH=code` if running from a fresh HF snapshot)** so `train_stage1_cortex.py` can import `train_a100_wikipedia`, `a100_opt_patches`, and `stage1_dataloader`.10. **Watch `TotL` vs `LML` when reading logs**:- `TotL` includes `0.25*ECHO + 0.15*r_mid + 0.25*mono_hinge + aux`. Compare **`LML`** (not `TotL`) against held-out validation loss.12 unmodified linespython -c 'import torch, safetensors, flash_attn, liger_kernel, fla; print("ALL KERNELS OK:", torch.cuda.device_count(), "GPUs")'```### Step 2: Set `HF_TOKEN` via Secret/Env and Download Latest `.safetensors` Checkpoint (~3 minutes)Ensure `HF_TOKEN` is set in the environment via Qualia Secrets (do not paste inline on the command line). Skip the download if `~/cortex_ckpts/latest_safetensors` is already on the same node's local SSD. In a brand-new workspace, omit `allow_patterns` to also pull `code/`, `data_manifests/`, and `tokenizer/`:```bashHF_XET_HIGH_PERFORMANCE=1 python -c 'import osfrom huggingface_hub import snapshot_downloadsnapshot_download(8 unmodified lines```The resume directory is `~/cortex_hf_resume/checkpoint/latest` (contains `model.safetensors`, `rank-{0..3}.safetensors`, `rank-{0..3}_meta.json`, `train_state.json`).### Step 3: Launch Resumed Stage 1 Pretraining (4Γ A100-80GB)Set `--max-wall-seconds` to `(your_gpu_budget_seconds - 1500)` (e.g., `14400` for a 4.5h budget after ~5 min setup/download). From the workspace root (or with `PYTHONPATH=code` if running `code/train_stage1_cortex.py` from a fresh HF download):```bashHF_XET_HIGH_PERFORMANCE=1 TOKENIZERS_PARALLELISM=false PYTHONUNBUFFERED=1 \torchrun --nproc_per_node=4 --master_port=29500 train_stage1_cortex.py \--manifest data_manifests/stage1_manifest.json \--tokenizer-path tokenizer/tokenizer.json \16 unmodified lines--fim-rate-other 0.10 \--skip-preflight```**What to expect on resume (verified end-to-end across all 4 ranks)**:- Step `15,522` will take ~10β13 minutes on a fresh node (one-time `torch.compile` autotune), then steady-state runs at **`~335β350k tok/s`** (~0.76s/step).- Step `15,522` resumes with **zero loss spike** (`LML ~ 2.29`, `MemEnt ~ 0.997`, `MaxLd ~ 3.2Γ`, `lr_scale = 1.000`, `tokens_seen_B = 4.069`).- Checkpoints save in pure `.safetensors` + JSON every 2,500 steps (~41s) and cleanly at `--max-wall-seconds` into `~/cortex_ckpts/latest`.### Step 4: Upload Final `.safetensors` Checkpoint to HF Hub (~2β3 minutes)```bashHF_XET_HIGH_PERFORMANCE=1 PYTHONUNBUFFERED=1 python scripts/upload_to_hf.py \--repo-id Cortex-Intelligence/Cortex-OSS-Flash-1.0 \--ckpt-dir ~/cortex_ckpts/latest \--tokenizer-dir tokenizer \
AGENTS.md+17-17