okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ba8745e13
main
1# Copyright (c) 2026 Peasant Smith and the Project Maya contributors (MIT; https://github.com/mw00/project-maya, v1.1.17). 2# Ported into Strata (third_party/project-maya/NOTICE.md, LICENSE); changes are in the git history of this file. 3"""dumpscan.py DUMP_L [--pos P] [--dim 5120] [--hc 4] - one run's DS4_DUMP_L records: each layer's residual stream at 4position P against the other positions (its norm over the median norm, its largest |value| and where, non-finite 5values) - where a position's stream blows up or goes non-finite.""" 6import argparse 7import sys 8 9import numpy as np 10 11 12def main (): 13ap = argparse .ArgumentParser () 14ap .add_argument ("dump" ) 15ap .add_argument ("--pos" ,type = int ,default = 0 ) 16ap .add_argument ("--dim" ,type = int ,default = 5120 ) 17ap .add_argument ("--hc" ,type = int ,default = 4 ) 18a = ap .parse_args () 19n = a .dim * a .hc 20"%-10s %10s %10s %12s %10s %10s %s" % ("record" ,"|h| pos" ,"median" ,"pos / med" ,"max|v| pos" ,"max|v| all" , 21"non-finite (pos / all)" )) 22with open (a .dump ,"rb" )as f : 23while True : 24h = f .read (24 ) 25if len (h )< 24 : 26break 27il ,p0 ,t = (int (v )for v in np .frombuffer (h ,dtype = np .int64 )) 28v = np .frombuffer (f .read (t * n * 4 ),dtype = np .float32 ).reshape (t ,n ) 29p = a .pos - p0 30if not 0 <= p < t : 31continue 32fin = np .isfinite (v ) 33vv = np .where (fin ,v ,0 ).astype (np .float64 ) 34nr = np .linalg .norm (vv ,axis = 1 ) 35med = float (np .median (nr )) 36mx = np .abs (vv [p ]) 37j = int (np .argmax (mx )) 38"L%-4d@%-3d %10.3e %10.3e %12.2f %10.3e %10.3e %d / %d (max at stream %d dim %d)" % ( 39il ,p0 ,nr [p ],med ,nr [p ]/ max (med ,1e-30 ),mx [j ],float (np .abs (vv ).max ()), 40int ((~ fin [p ]).sum ()),int ((~ fin ).sum ()),j // a .dim ,j % a .dim )) 41 42 43if __name__ == "__main__" : 44sys .exit (main ())