Scott/Codex commited on
Commit
4396074
·
1 Parent(s): 78c46ca

Add VRAM-first cache release hook

Browse files
README.md CHANGED
@@ -73,7 +73,6 @@ Structured-mask update 2026-05-29: the sublinear backend now accepts symbolic ca
73
  SAT block-causal, and unrestricted/NAT mask rules. This removes dense O(T^2) mask
74
  allocation for long context, and also gathers ALiBi bias directly for selected
75
  local/anchor keys instead of materializing dense `[heads x T x T]` bias tensors.
76
- A trainer heartbeat and post-checkpoint CUDA cache clear were added for easier
77
- long-running Vast monitoring.
78
 
79
  License: Apache-2.0 (matching the upstream method).
 
73
  SAT block-causal, and unrestricted/NAT mask rules. This removes dense O(T^2) mask
74
  allocation for long context, and also gathers ALiBi bias directly for selected
75
  local/anchor keys instead of materializing dense `[heads x T x T]` bias tensors.
76
+ A trainer heartbeat, post-checkpoint CUDA cache clear, and optional `--empty_cache_every_steps` hook were added for easier long-running Vast monitoring and VRAM-first allocator behavior.
 
77
 
78
  License: Apache-2.0 (matching the upstream method).
nB300_agillm4_vram_dblock.py CHANGED
@@ -2376,6 +2376,12 @@ def _train_phase(
2376
  seen_tok += toks_processed
2377
  pbar.set_postfix(loss=f"{loss_value:.3f}", B=BATCH, L=BLOCK)
2378
  pbar.update(toks_processed)
 
 
 
 
 
 
2379
  heartbeat_every = int(getattr(args, "heartbeat_every_sec", 300) or 0)
2380
  now_mono = time.monotonic()
2381
  if heartbeat_every > 0 and now_mono - last_heartbeat_mono >= heartbeat_every:
@@ -2893,6 +2899,8 @@ def main():
2893
  tr.add_argument("--save_every_sec", type=int, default=DEFAULT_SAVE_SEC)
2894
  tr.add_argument("--heartbeat_every_sec", type=int, default=300,
2895
  help="Print lightweight trainer heartbeat/status lines every N seconds; 0 disables.")
 
 
2896
  tr.add_argument("--delta_every_steps", type=int, default=DEFAULT_DELTA_STEPS, help="Weight-only delta save every N steps (0=off)")
2897
  tr.add_argument("--delta_max_keep", type=int, default=DEFAULT_MAX_DELTAS, help="Max delta checkpoints to keep")
2898
  tr.add_argument("--resume_delta", type=str, help="Resume from a delta (weight-only, no optimizer state)")
 
2376
  seen_tok += toks_processed
2377
  pbar.set_postfix(loss=f"{loss_value:.3f}", B=BATCH, L=BLOCK)
2378
  pbar.update(toks_processed)
2379
+ empty_cache_every = int(getattr(args, "empty_cache_every_steps", 0) or 0)
2380
+ if DEV.type == "cuda" and empty_cache_every > 0 and (step % empty_cache_every) == 0:
2381
+ try:
2382
+ torch.cuda.empty_cache()
2383
+ except Exception:
2384
+ pass
2385
  heartbeat_every = int(getattr(args, "heartbeat_every_sec", 300) or 0)
2386
  now_mono = time.monotonic()
2387
  if heartbeat_every > 0 and now_mono - last_heartbeat_mono >= heartbeat_every:
 
2899
  tr.add_argument("--save_every_sec", type=int, default=DEFAULT_SAVE_SEC)
2900
  tr.add_argument("--heartbeat_every_sec", type=int, default=300,
2901
  help="Print lightweight trainer heartbeat/status lines every N seconds; 0 disables.")
2902
+ tr.add_argument("--empty_cache_every_steps", type=int, default=0,
2903
+ help="Call torch.cuda.empty_cache() every N train steps; useful for VRAM-first runs where lower reserved VRAM matters more than speed.")
2904
  tr.add_argument("--delta_every_steps", type=int, default=DEFAULT_DELTA_STEPS, help="Weight-only delta save every N steps (0=off)")
2905
  tr.add_argument("--delta_max_keep", type=int, default=DEFAULT_MAX_DELTAS, help="Max delta checkpoints to keep")
2906
  tr.add_argument("--resume_delta", type=str, help="Resume from a delta (weight-only, no optimizer state)")
relaunch_agillm4_dblock.sh CHANGED
@@ -20,4 +20,5 @@ exec python -u nB300_agillm4.py train --preset agillm4_floor --resume "$CKPT" \
20
  --optimizer paged_adamw8bit --sat_every 1 --nat_every 1 --nat_max_tokens 768 --nat_mask_ratio 0.5 \
21
  --token_param_ratio 100 --save_dir "$SAVE_DIR" \
22
  --save_every_sec 86400 --heartbeat_every_sec "${AGILLM4_HEARTBEAT_EVERY_SEC:-300}" \
 
23
  --delta_every_steps 25000 --delta_max_keep 1 --max_ckpts 1
 
20
  --optimizer paged_adamw8bit --sat_every 1 --nat_every 1 --nat_max_tokens 768 --nat_mask_ratio 0.5 \
21
  --token_param_ratio 100 --save_dir "$SAVE_DIR" \
22
  --save_every_sec 86400 --heartbeat_every_sec "${AGILLM4_HEARTBEAT_EVERY_SEC:-300}" \
23
+ --empty_cache_every_steps "${AGILLM4_EMPTY_CACHE_EVERY_STEPS:-1}" \
24
  --delta_every_steps 25000 --delta_max_keep 1 --max_ckpts 1
relaunch_agillm4_dblock_tied.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -Eeuo pipefail
3
+ cd /workspace/agillm-4
4
+ export TOKENIZERS_PARALLELISM=false
5
+ export TOKENIZER_ID="${TOKENIZER_ID:-deepseek-ai/DeepSeek-V4-Pro}"
6
+ export PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512,expandable_segments:True
7
+ export AGILLM_ATTN_BACKEND=sublinear
8
+ [ -f /root/.cache/huggingface/token ] && { export HF_TOKEN="$(tr -d '\r\n' </root/.cache/huggingface/token)"; export HUGGING_FACE_HUB_TOKEN="$HF_TOKEN"; }
9
+ SAVE_DIR=/workspace/agillm4_4090_ckpts
10
+ CKPT="$(ls -1t "$SAVE_DIR"/pretrain_step*.pt 2>/dev/null | head -1)"
11
+ exec >> /workspace/agillm4_floor_train.log 2>&1
12
+ echo "RELAUNCH_AGILLM4_DBLOCK_TIED $(date -u +%Y-%m-%dT%H:%M:%SZ) resume=$CKPT --dblock --tie_weights --attn_backend sublinear (fused_ce fixed)"
13
+ exec python -u nB300_agillm4.py train --preset agillm4_floor --resume "$CKPT" \
14
+ --dblock --dblock_blocks "${AGILLM4_DBLOCKS:-4}" --dblock_schedule "${AGILLM4_DBLOCK_SCHEDULE:-loss_balanced}" \
15
+ --dblock_warmup_steps "${AGILLM4_DBLOCK_WARMUP:-16}" --dblock_sigma_curriculum_steps "${AGILLM4_DBLOCK_SIGMA_CURRICULUM:-2000}" \
16
+ --dblock_log_every "${AGILLM4_DBLOCK_LOG_EVERY:-25}" --tie_weights \
17
+ --batch_size 1 --block 1280 --amp --attn_backend sublinear --grad_checkpoint \
18
+ --optimizer paged_adamw8bit --sat_every 1 --nat_every 1 --nat_max_tokens 768 --nat_mask_ratio 0.5 \
19
+ --token_param_ratio 100 --save_dir "$SAVE_DIR" \
20
+ --save_every_sec 86400 --heartbeat_every_sec "${AGILLM4_HEARTBEAT_EVERY_SEC:-300}" \
21
+ --empty_cache_every_steps "${AGILLM4_EMPTY_CACHE_EVERY_STEPS:-1}" \
22
+ --delta_every_steps 25000 --delta_max_keep 1 --max_ckpts 1