File size: 859 Bytes
1fa5a85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"""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))