import json, socket, subprocess, time, glob, re class S(socket.socket): def connect(self, a): try: self.setsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG, 1200) except OSError: pass return super().connect(a) socket.socket = S from huggingface_hub import HfApi tok = open('/tmp/phd01/hf/token').read().strip() api = HfApi(token=tok) host = subprocess.run(['hostname'], capture_output=True, text=True).stdout.strip()[:30] def last_step(p): try: txt = subprocess.run(['tail','-200',p], capture_output=True, text=True, timeout=15).stdout m = re.findall(r'step +(\d+)', txt); ls = re.findall(r'loss ([0-9.]+)', txt) return (m[-1] if m else None, ls[-1] if ls else None) except Exception: return (None, None) while True: st = {'host': host, 'ts': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())} logs = sorted(set(glob.glob('/tmp/phd01/runs/*/train.log') + glob.glob('/tmp/phd01/runs/*.log'))) for p in logs: name = p.replace('/tmp/phd01/runs/','').replace('/train.log','').replace('.log','') step, loss = last_step(p) if step: st[name] = f'step {step} loss {loss}' try: gpu = subprocess.run(['nvidia-smi','--query-gpu=utilization.gpu,memory.used','--format=csv,noheader'], capture_output=True, text=True, timeout=15).stdout.strip() st['gpu'] = gpu.replace('\n',' | ') except Exception: pass try: api.upload_file(path_or_fileobj=json.dumps(st, indent=1).encode(), path_in_repo=f'status/{host}.json', repo_id='owl-grey/pot210-woftsam', repo_type='dataset') except Exception as e: print('beacon fail', type(e).__name__) time.sleep(600)