MarxistLeninist commited on
Commit
9e3d361
·
verified ·
1 Parent(s): abf63b5

Upload dashboard.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. dashboard.py +146 -0
dashboard.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Lightweight web dashboard for the Binary Looped Hybrid trainer.
3
+
4
+ Stdlib-only HTTP server. Serves:
5
+ / auto-refreshing HTML monitor (loss curve + live stats)
6
+ /state current state.json
7
+ /history history.jsonl (for the curve)
8
+ Run: python3 dashboard.py [port] (default 8080)
9
+ """
10
+
11
+ import json
12
+ import os
13
+ import sys
14
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
15
+
16
+ HERE = os.path.dirname(os.path.abspath(__file__))
17
+ STATE = os.path.join(HERE, "state.json")
18
+ HISTORY = os.path.join(HERE, "history.jsonl")
19
+
20
+ PAGE = """<!DOCTYPE html>
21
+ <html><head><meta charset="utf-8">
22
+ <title>Binary Looped Hybrid - LIVE TRAINING</title>
23
+ <meta name="viewport" content="width=device-width, initial-scale=1">
24
+ <style>
25
+ body{background:#101418;color:#e8eef4;font-family:Consolas,Menlo,monospace;
26
+ margin:16px}
27
+ h1{color:#ffb000;font-size:17px;margin:0 0 4px}
28
+ .muted{color:#8fa3b8;font-size:12px}
29
+ .grid{display:flex;flex-wrap:wrap;gap:6px;margin:10px 0}
30
+ .cell{background:#171d24;padding:8px 12px;min-width:104px}
31
+ .cell .lab{color:#8fa3b8;font-size:10px}
32
+ .cell .val{font-size:19px;font-weight:bold}
33
+ canvas{background:#171d24;width:100%;height:300px}
34
+ #sample{background:#171d24;padding:10px;white-space:pre-wrap;font-size:13px}
35
+ </style></head><body>
36
+ <h1>BINARY LOOPED (INTERNAL-REASONING) TRANSFORMER - MAMBA HYBRID</h1>
37
+ <div class="muted" id="cfg">waiting for trainer...</div>
38
+ <div class="grid" id="stats"></div>
39
+ <canvas id="cv" width="1100" height="300"></canvas>
40
+ <div class="muted" style="margin-top:10px">LATEST GREEDY SAMPLE (prompt: 'The ')</div>
41
+ <div id="sample">(none yet)</div>
42
+ <div class="muted" id="foot" style="margin-top:8px"></div>
43
+ <script>
44
+ const FIELDS=[["step","STEP"],["loss","LOSS"],["ema_loss","EMA LOSS"],
45
+ ["tok_s","TOKENS/S"],["lr","LR"],["gpu_mem_mb","GPU MEM MB"],
46
+ ["elapsed_s","ELAPSED S"]];
47
+ let hist=[];
48
+ function draw(){
49
+ const cv=document.getElementById('cv'),ctx=cv.getContext('2d');
50
+ const W=cv.width,H=cv.height;ctx.clearRect(0,0,W,H);
51
+ if(hist.length<2){ctx.fillStyle='#8fa3b8';ctx.font='14px monospace';
52
+ ctx.fillText('collecting loss points...',20,30);return;}
53
+ const pts=hist.slice(-1500);
54
+ const xs=pts.map(p=>p[0]),ys=pts.map(p=>p[1]),es=pts.map(p=>p[2]);
55
+ const x0=Math.min(...xs),x1=Math.max(...xs);
56
+ let y1=Math.max(...ys,...es)*1.05,y0=Math.min(...ys,...es)*0.95;
57
+ const L=48,R=10,T=10,B=22;
58
+ const X=x=>L+(x-x0)/Math.max(1,x1-x0)*(W-L-R);
59
+ const Y=y=>T+(y1-y)/(y1-y0)*(H-T-B);
60
+ ctx.strokeStyle='#232b34';ctx.fillStyle='#8fa3b8';ctx.font='11px monospace';
61
+ for(const f of [0,0.5,1]){const yv=y0+f*(y1-y0);
62
+ ctx.beginPath();ctx.moveTo(L,Y(yv));ctx.lineTo(W-R,Y(yv));ctx.stroke();
63
+ ctx.fillText(yv.toFixed(2),4,Y(yv)+4);}
64
+ ctx.fillText('step '+x0,L,H-6);
65
+ const lbl='step '+x1;ctx.fillText(lbl,W-R-ctx.measureText(lbl).width,H-6);
66
+ ctx.strokeStyle='#54677c';ctx.lineWidth=1;ctx.beginPath();
67
+ pts.forEach((p,i)=>{const px=X(p[0]),py=Y(p[1]);
68
+ i?ctx.lineTo(px,py):ctx.moveTo(px,py);});ctx.stroke();
69
+ ctx.strokeStyle='#39d0c4';ctx.lineWidth=2;ctx.beginPath();
70
+ pts.forEach((p,i)=>{const px=X(p[0]),py=Y(p[2]);
71
+ i?ctx.lineTo(px,py):ctx.moveTo(px,py);});ctx.stroke();
72
+ ctx.fillStyle='#39d0c4';ctx.fillText('EMA loss',W-R-70,T+12);
73
+ }
74
+ async function tick(){
75
+ try{
76
+ const s=await (await fetch('/state')).json();
77
+ document.getElementById('cfg').textContent=
78
+ 'params '+s.params.toLocaleString()+' | binary-latent params '+
79
+ s.binary_latent_params.toLocaleString()+' | reasoning loops R='+
80
+ s.loops+' per looped block | d_model '+s.d_model+' | batch '+
81
+ s.batch_size+' x seq '+s.seq_len+' | data: '+s.dataset+
82
+ ' (HF streaming) | device '+s.device+' | trainer pid '+s.pid+
83
+ ' | RTX 2080 Ti (Vast 61918457)';
84
+ document.getElementById('stats').innerHTML=FIELDS.map(([k,lab])=>{
85
+ let v=s[k];if(k==='lr')v=v.toExponential(2);
86
+ if(k==='elapsed_s')v=Math.floor(v);
87
+ return '<div class="cell"><div class="lab">'+lab+
88
+ '</div><div class="val">'+v+'</div></div>';}).join('');
89
+ document.getElementById('sample').textContent=s.sample||'(none yet)';
90
+ document.getElementById('foot').textContent=
91
+ 'auto-refreshing every 2s - state step '+s.step;
92
+ if(!hist.length||hist[hist.length-1][0]!==s.step){
93
+ hist.push([s.step,s.loss,s.ema_loss]);draw();}
94
+ }catch(e){
95
+ document.getElementById('foot').textContent='waiting for state... '+e;
96
+ }
97
+ }
98
+ async function seed(){
99
+ try{
100
+ const txt=await (await fetch('/history')).text();
101
+ hist=txt.trim().split('\\n').filter(Boolean).map(l=>{
102
+ const s=JSON.parse(l);return [s.step,s.loss,s.ema_loss];});
103
+ }catch(e){}
104
+ draw();
105
+ }
106
+ seed();tick();setInterval(tick,2000);
107
+ </script></body></html>
108
+ """
109
+
110
+
111
+ class Handler(BaseHTTPRequestHandler):
112
+ def log_message(self, *a): # quiet
113
+ pass
114
+
115
+ def _send(self, body, ctype):
116
+ data = body.encode("utf-8") if isinstance(body, str) else body
117
+ self.send_response(200)
118
+ self.send_header("Content-Type", ctype)
119
+ self.send_header("Content-Length", str(len(data)))
120
+ self.send_header("Cache-Control", "no-store")
121
+ self.end_headers()
122
+ self.wfile.write(data)
123
+
124
+ def do_GET(self):
125
+ if self.path == "/":
126
+ self._send(PAGE, "text/html; charset=utf-8")
127
+ elif self.path == "/state":
128
+ try:
129
+ with open(STATE, "rb") as f:
130
+ self._send(f.read(), "application/json")
131
+ except FileNotFoundError:
132
+ self._send("{}", "application/json")
133
+ elif self.path == "/history":
134
+ try:
135
+ with open(HISTORY, "rb") as f:
136
+ self._send(f.read(), "text/plain; charset=utf-8")
137
+ except FileNotFoundError:
138
+ self._send("", "text/plain; charset=utf-8")
139
+ else:
140
+ self.send_response(404)
141
+ self.end_headers()
142
+
143
+
144
+ if __name__ == "__main__":
145
+ port = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
146
+ ThreadingHTTPServer(("0.0.0.0", port), Handler).serve_forever()