Organize project tools and local workflows: c/tools, c/scripts, c/tests, root Makefile (flat C core untouched) (#22)

This commit is contained in:
ZacharyZcR
2026-07-10 16:08:39 +08:00
committed by GitHub
parent a2942b2172
commit 13e8f09ffc
23 changed files with 87 additions and 52 deletions
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Pipeline GLM-5.2 (int4, streaming, 15 GB RAM) — tutto in WSL, modello su ext4.
# uso da c/: scripts/run.sh ["prompt"] [n_token]
# Fa: (1) attende lo spostamento su ext4, (2) riprende la conversione fino a completarla,
# (3) compila il motore, (4) genera testo restando nel budget RAM.
set -euo pipefail
DIR="${COLI_MODEL:-/home/vincenzo/glm52_i4}" # modello int4 su ext4 (NON /mnt/c!)
REPO="${COLI_REPO:-zai-org/GLM-5.2-FP8}"
CODE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
RAM_GB="${RAM_GB:-15}"
PROMPT="${1:-Ciao, chi sei?}"
NGEN="${2:-64}"
cd "$CODE"
# 0) sanity: il modello deve stare su ext4, non su 9p/Windows
case "$DIR" in /mnt/*) echo "ERRORE: $DIR e' su /mnt (9p/Windows). Mettilo su ext4."; exit 1;; esac
# 1) se un rsync di spostamento e' ancora vivo, aspettalo
while pgrep -f "rsync.*glm52_i4" >/dev/null 2>&1; do
echo "[1/4] attendo lo spostamento su ext4... ($(du -sh "$DIR" 2>/dev/null | cut -f1))"; sleep 20
done
echo "[1/4] spostamento completato: $(du -sh "$DIR" | cut -f1), shard $(ls "$DIR"/*.safetensors 2>/dev/null | wc -l)"
# 2) riprende+completa la conversione (ripartibile: salta gli shard gia' fatti)
echo "[2/4] conversione (riprende da dove era): output -> $DIR"
python3 tools/convert_fp8_to_int4.py --repo "$REPO" --outdir "$DIR" --ebits 4 --io-bits 8
# 3) il motore richiede tokenizer.json + config.json nella dir del modello
for f in config.json tokenizer.json; do
[ -f "$DIR/$f" ] || { echo "ERRORE: manca $DIR/$f"; exit 1; }
done
echo "[3/4] compilo il motore"; make -s glm
# 4) generazione reale, con auto-cap dal budget RAM e heartbeat RSS su stderr
echo "[4/4] genero (RAM_GB=$RAM_GB, NGEN=$NGEN)"; echo "------"
SNAP="$DIR" RAM_GB="$RAM_GB" PROMPT="$PROMPT" NGEN="$NGEN" ./glm 64
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Supervisore della conversione GLM-5.2 — a prova di rete WSL che si blocca.
# - tiene SEMPRE vivo un (solo) convertitore
# - se un download resta FERMO >180s (connessione zombie), lo ammazza e lo rilancia:
# hf_hub riprende il .incomplete dal punto esatto, non si perde nulla
# - esce da solo quando tutti i 141 shard sono fatti
# uso da c/: nohup scripts/supervisor.sh > supervisor.log 2>&1 &
set -u
DIR="${COLI_MODEL:-/home/vincenzo/glm52_i4}"
CODE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TOTAL="${TOTAL_SHARDS:-141}"
STALL_S=180 # secondi senza crescita del download -> riavvio
CONVLOG=/tmp/convert_supervised.log
exec 9>"$DIR/.supervisor.lock"
flock -n 9 || { echo "supervisore gia' attivo, esco"; exit 1; }
log(){ echo "[$(date +%H:%M:%S)] $*"; }
start_conv(){
cd "$CODE"
nohup python3 tools/convert_fp8_to_int4.py --repo zai-org/GLM-5.2-FP8 \
--outdir "$DIR" --ebits 4 --io-bits 8 >> "$CONVLOG" 2>&1 &
log "convertitore avviato (PID $!)"
}
last_size=-1; stall=0
while :; do
done_n=$(ls "$DIR"/out-*.safetensors 2>/dev/null | wc -l)
if [ "$done_n" -ge "$TOTAL" ]; then log "FATTO: $done_n/$TOTAL shard. Esco."; pkill -f convert_fp8 2>/dev/null; exit 0; fi
if ! pgrep -f convert_fp8 >/dev/null; then
log "convertitore non attivo ($done_n/$TOTAL): lo avvio"
start_conv; last_size=-1; stall=0; sleep 20; continue
fi
inc=$(find "$DIR/_inflight" -name "*.incomplete" 2>/dev/null | head -1)
if [ -n "$inc" ]; then
size=$(stat -c%s "$inc" 2>/dev/null || echo 0)
if [ "$size" = "$last_size" ]; then
stall=$((stall+30))
if [ "$stall" -ge "$STALL_S" ]; then
log "download FERMO da ${stall}s a $((size/1000000)) MB ($done_n/$TOTAL): riavvio il convertitore"
pkill -f convert_fp8; sleep 5
start_conv; last_size=-1; stall=0
fi
else
[ "$last_size" -ge 0 ] && [ "$stall" -ge 60 ] && log "download ripreso ($((size/1000000)) MB)"
last_size=$size; stall=0
fi
else
last_size=-1; stall=0 # niente .incomplete = sta convertendo/salvando: tutto ok
fi
sleep 30
done