serve: :piu resumes a truncated answer from live KV; ngen default 1024 (stops end turns now)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -200,7 +200,7 @@ def cmd_chat(a):
|
|||||||
if mload: print(f" {C.grn}✓{C.r} pronto in {mload.group(1)}s {C.dim}· residente {float(mload.group(2))/1000:.1f} GB · RSS {st.get('rss','?')} GB{C.r}")
|
if mload: print(f" {C.grn}✓{C.r} pronto in {mload.group(1)}s {C.dim}· residente {float(mload.group(2))/1000:.1f} GB · RSS {st.get('rss','?')} GB{C.r}")
|
||||||
if extra: print(f" {C.dgray}{extra}{C.r}")
|
if extra: print(f" {C.dgray}{extra}{C.r}")
|
||||||
except Exception: pass
|
except Exception: pass
|
||||||
print(f" {C.dim}scrivi e premi invio · :reset memoria · :q esci{C.r}\n")
|
print(f" {C.dim}scrivi e premi invio · :piu continua risposta · :reset memoria · :q esci{C.r}\n")
|
||||||
w=term_w()-4
|
w=term_w()-4
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
@@ -219,6 +219,9 @@ def cmd_chat(a):
|
|||||||
p.stdin.write(b"\x02RESET\n"); p.stdin.flush()
|
p.stdin.write(b"\x02RESET\n"); p.stdin.flush()
|
||||||
stream_turn(p, END, lambda b: None)
|
stream_turn(p, END, lambda b: None)
|
||||||
print(f" {C.dim}✦ memoria azzerata{C.r}\n"); continue
|
print(f" {C.dim}✦ memoria azzerata{C.r}\n"); continue
|
||||||
|
if msg in (":piu",":più",":more",":continua"):
|
||||||
|
p.stdin.write(b"\x02MORE\n"); p.stdin.flush()
|
||||||
|
else:
|
||||||
p.stdin.write((msg.replace("\n"," ")+"\n").encode()); p.stdin.flush()
|
p.stdin.write((msg.replace("\n"," ")+"\n").encode()); p.stdin.flush()
|
||||||
print(f"\n {C.teal}◆ colibrì{C.r}")
|
print(f"\n {C.teal}◆ colibrì{C.r}")
|
||||||
dec=codecs.getincrementaldecoder("utf-8")("replace")
|
dec=codecs.getincrementaldecoder("utf-8")("replace")
|
||||||
@@ -236,7 +239,10 @@ def cmd_chat(a):
|
|||||||
if st is None: print(f"\n {C.yel}[motore terminato]{C.r}"); break
|
if st is None: print(f"\n {C.yel}[motore terminato]{C.r}"); break
|
||||||
el=time.time()-t0
|
el=time.time()-t0
|
||||||
if st.get("tok"):
|
if st.get("tok"):
|
||||||
print(f"\r {C.dgray}└─ {st['tok']} tok · {st['tps']:.2f} tok/s · hit {st['hit']:.0f}% · RSS {st['rss']:.1f} GB · {el:.0f}s{C.r}\n")
|
print(f"\r {C.dgray}└─ {st['tok']} tok · {st['tps']:.2f} tok/s · hit {st['hit']:.0f}% · RSS {st['rss']:.1f} GB · {el:.0f}s{C.r}")
|
||||||
|
if st["tok"]>=a.ngen:
|
||||||
|
print(f" {C.yel}…troncato al limite --ngen ({a.ngen}): scrivi :piu per far continuare la risposta{C.r}")
|
||||||
|
print()
|
||||||
else:
|
else:
|
||||||
print()
|
print()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@@ -271,7 +277,7 @@ def cmd_convert(a):
|
|||||||
def main():
|
def main():
|
||||||
common=argparse.ArgumentParser(add_help=False)
|
common=argparse.ArgumentParser(add_help=False)
|
||||||
common.add_argument("--model", default=DEF_MODEL); common.add_argument("--ram", type=int, default=0) # 0 = auto (il motore usa l'88% della RAM disponibile)
|
common.add_argument("--model", default=DEF_MODEL); common.add_argument("--ram", type=int, default=0) # 0 = auto (il motore usa l'88% della RAM disponibile)
|
||||||
common.add_argument("--cap", type=int, default=8); common.add_argument("--ngen", type=int, default=256)
|
common.add_argument("--cap", type=int, default=8); common.add_argument("--ngen", type=int, default=1024) # rete di sicurezza: la fine vera la decidono gli stop token
|
||||||
common.add_argument("--topp", type=float, default=0); common.add_argument("--topk", type=int, default=0)
|
common.add_argument("--topp", type=float, default=0); common.add_argument("--topk", type=int, default=0)
|
||||||
ap=argparse.ArgumentParser(prog="coli", parents=[common], description="colibrì — GLM-5.2 in locale")
|
ap=argparse.ArgumentParser(prog="coli", parents=[common], description="colibrì — GLM-5.2 in locale")
|
||||||
sub=ap.add_subparsers(dest="cmd")
|
sub=ap.add_subparsers(dest="cmd")
|
||||||
|
|||||||
@@ -1052,6 +1052,21 @@ static void run_serve(Model *m, const char *snap){
|
|||||||
if(nr>0 && line[nr-1]=='\n') line[--nr]=0;
|
if(nr>0 && line[nr-1]=='\n') line[--nr]=0;
|
||||||
if(!strcmp(line,"\x02RESET")){ len=0; first=1; if(m->has_mtp) m->kv_start[m->c.n_layers]=-1;
|
if(!strcmp(line,"\x02RESET")){ len=0; first=1; if(m->has_mtp) m->kv_start[m->c.n_layers]=-1;
|
||||||
printf("\x01\x01" "END" "\x01\x01\n"); printf("STAT 0 0.00 0.0 %.2f\n", rss_gb()); fflush(stdout); continue; }
|
printf("\x01\x01" "END" "\x01\x01\n"); printf("STAT 0 0.00 0.0 %.2f\n", rss_gb()); fflush(stdout); continue; }
|
||||||
|
if(!strcmp(line,"\x02MORE")){ /* continua la risposta troncata da NGEN:
|
||||||
|
la storia e' gia' in KV, basta ri-forwardare l'ULTIMO token per riavere i logits */
|
||||||
|
if(len<1){ printf("\x01\x01" "END" "\x01\x01\n"); printf("STAT 0 0.00 0.0 %.2f\n", rss_gb()); fflush(stdout); continue; }
|
||||||
|
int cur=ngen; if(len+cur+g_draft+2>=maxctx) cur=maxctx-len-g_draft-2;
|
||||||
|
uint64_t h0=m->hits, ms0=m->miss; double tt0=now_s();
|
||||||
|
float *logit=step(m,hist+len-1,1,len-1);
|
||||||
|
EmitStream es={&T,m,now_s(),0,1};
|
||||||
|
int prod=0;
|
||||||
|
if(cur>0) prod=spec_decode(m,hist,len,cur,eos,logit,emit_stream,&es,&len);
|
||||||
|
else free(logit);
|
||||||
|
double tdt=now_s()-tt0; if(tdt<1e-6) tdt=1e-6;
|
||||||
|
double dh=(double)(m->hits-h0), dm=(double)(m->miss-ms0);
|
||||||
|
printf("\n\x01\x01" "END" "\x01\x01\n");
|
||||||
|
printf("STAT %d %.2f %.1f %.2f\n", prod, prod/tdt, (dh+dm)>0?100.0*dh/(dh+dm):0.0, rss_gb());
|
||||||
|
fflush(stdout); continue; }
|
||||||
if(nr<1){ printf("\x01\x01" "END" "\x01\x01\n"); printf("STAT 0 0.00 0.0 %.2f\n", rss_gb()); fflush(stdout); continue; }
|
if(nr<1){ printf("\x01\x01" "END" "\x01\x01\n"); printf("STAT 0 0.00 0.0 %.2f\n", rss_gb()); fflush(stdout); continue; }
|
||||||
int bl=0; /* costruisce il testo del turno (con template) */
|
int bl=0; /* costruisce il testo del turno (con template) */
|
||||||
/* template UFFICIALE GLM-5.2 (chat_template.jinja): niente \n dopo i ruoli, e dopo
|
/* template UFFICIALE GLM-5.2 (chat_template.jinja): niente \n dopo i ruoli, e dopo
|
||||||
|
|||||||
Reference in New Issue
Block a user