From 81c03988779899291fa87de5fb609cc88b34467b Mon Sep 17 00:00:00 2001 From: NeuralNotwerk Date: Thu, 16 Jul 2026 06:57:36 +0000 Subject: [PATCH] =?UTF-8?q?PIN=3Dauto=20=E2=80=94=20seed=20the=20pin=20fro?= =?UTF-8?q?m=20the=20live=20usage=20history?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PIN=auto resolves to /.coli_usage, the history that serve mode appends after every turn, so each restart's hot-store placement follows the accumulated REAL workload instead of a frozen one-shot profile; stats.txt is the fallback for a virgin model dir, and with neither present the run simply starts unpinned. Same magic-value convention as PIN_GB=all (#80); explicit paths and the AUTOPIN flow are untouched (PIN set skips AUTOPIN as before). This lifts deployment entrypoints' "prefer .coli_usage over stats.txt" shell plumbing into the engine, plus the ENVIRONMENT.md row. Co-Authored-By: Claude Fable 5 --- c/glm.c | 23 +++++++++++++++++++++-- docs/ENVIRONMENT.md | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/c/glm.c b/c/glm.c index 7e05ad9..fd302d1 100644 --- a/c/glm.c +++ b/c/glm.c @@ -5915,8 +5915,27 @@ int main(int argc, char **argv){ /* HOT-STORE: PIN= [PIN_GB=g] -> top expert per frequenza fissi in RAM. * Va PRIMA di cap_for_ram: i pinnati contano nel residente. */ if(getenv("PIN")){ - const char *pin_gb=getenv("PIN_GB"); - pin_load(&m,getenv("PIN"),pin_gb&&!strcmp(pin_gb,"all")?-1.0:pin_gb?atof(pin_gb):10.0); /* PIN_GB=all (#80) */ + const char *pin=getenv("PIN"); char pauto[2100]; + if(!strcmp(pin,"auto")){ + /* PIN=auto: la storia VIVA /.coli_usage (appesa a ogni turno) batte il + * profilo congelato stats.txt — il pin di ogni riavvio riflette il carico reale + * accumulato, non il prompt di bootstrap. Fallback stats.txt per una dir vergine; + * nessuno dei due -> nessun pin (AUTOPIN piu' sotto resta escluso: PIN e' settato). + * EN: prefer the live usage history over the frozen one-shot profile, so each + * reload's pin placement follows the accumulated real workload. */ + snprintf(pauto,sizeof(pauto),"%s/.coli_usage",snap); + FILE *pf=fopen(pauto,"rb"); long psz=0; + if(pf){ fseek(pf,0,SEEK_END); psz=ftell(pf); fclose(pf); } + if(psz<=0){ snprintf(pauto,sizeof(pauto),"%s/stats.txt",snap); + pf=fopen(pauto,"rb"); psz=0; + if(pf){ fseek(pf,0,SEEK_END); psz=ftell(pf); fclose(pf); } } + if(psz>0){ pin=pauto; fprintf(stderr,"[PIN] auto: seeding from %s\n",pauto); } + else { pin=NULL; fprintf(stderr,"[PIN] auto: no .coli_usage or stats.txt in %s yet (no pin this run)\n",snap); } + } + if(pin){ + const char *pin_gb=getenv("PIN_GB"); + pin_load(&m,pin,pin_gb&&!strcmp(pin_gb,"all")?-1.0:pin_gb?atof(pin_gb):10.0); /* PIN_GB=all (#80) */ + } } if(getenv("COUPLE")&&*getenv("COUPLE")){ /* coupling-scored cross-layer prefetch (#176) */ g_couple_k=getenv("COUPLE_K")?atoi(getenv("COUPLE_K")):8; diff --git a/docs/ENVIRONMENT.md b/docs/ENVIRONMENT.md index dab656b..d345b7b 100644 --- a/docs/ENVIRONMENT.md +++ b/docs/ENVIRONMENT.md @@ -47,7 +47,7 @@ Format: `VAR` — default — effect. | `CAP_RAISE` | `1` (on) | Let the engine raise the expert-cache cap above `topk` when RAM allows (bigger batches). `0` fixes the cap. | | `PREFETCH` | `0` | Prefetch depth for streamed experts. | | `COLI_MMAP` | `0` | `mmap` the weights instead of read()-ing into slabs. | -| `PIN` | unset | Path to a `.coli_usage` file; pins the hottest experts into a resident "hot store" at startup. | +| `PIN` | unset | Path to a `.coli_usage`/stats file; pins the hottest experts into a resident "hot store" at startup. **`PIN=auto`** seeds from the model dir's live `.coli_usage` (appended after every turn, so each restart's pin placement follows the accumulated real workload) with `stats.txt` as the fallback for a virgin model dir; neither present → no pin this run. | | `PIN_GB` | `10.0` | Size budget (GB) for the pinned hot store when `PIN` is set. | | `AUTOPIN` | `1` (on) | Auto-pin the hot store from usage history once ≥5000 selections are recorded. | | `REPIN` | `0` (off) | Live re-pin the hot store every N emitted tokens (RFC). |