Download fixture.py from factlogic/weight-space-editor: direct link, hf CLI and curl.
- Browser
- Download file 859 Bytes
-
https://huggingface.co/factlogic/weight-space-editor/resolve/main/fixture.py
- Command line
-
hf download hf://factlogic/weight-space-editor/fixture.py
-
curl -L -o fixture.py https://huggingface.co/factlogic/weight-space-editor/resolve/main/fixture.py
859 Bytes
| """Deterministic synthetic tensors for testing the public API without downloading a classifier or dataset.""" | |
| import torch | |
| from target import init,sl | |
| def example(): | |
| gen=torch.Generator().manual_seed(26101) | |
| rand=lambda *s:torch.randn(*s,generator=gen) | |
| d,r,m,c=32,8,16,6 | |
| st=dict(basis=torch.linalg.qr(rand(d,r)).Q,proj=rand(m,d)*.08,norm_w=torch.ones(d),norm_b=torch.zeros(d),eps=1.e-5) | |
| y=torch.arange(c).repeat(12);protos=rand(c,d);s=protos[y]+.68*rand(len(y),d) | |
| X=(s@st['basis'],s@(rand(d,m)/d**.5),s) | |
| o=init(st,c);u=init(st,c);g=torch.arange(c)>=3 | |
| o['head']=.30*protos+rand(c,d)*.08;o['head'][g]*=.19 | |
| u['head']=.30*protos+rand(c,d)*.08;u['head'][~g]*=.19 | |
| for k in ('inc','inbias','out','outbias'):u[k]=rand(*u[k].shape)*.07 | |
| return o,u,st,sl(X,slice(0,24)),y[:24],sl(X,slice(24,36)),y[24:36],g,sl(X,slice(36,None)) | |