Download tests/test_model.py from kiruluta/rsil-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 624 Bytes
-
https://huggingface.co/kiruluta/rsil-benchmark/resolve/main/tests/test_model.py
- Command line
-
hf download hf://kiruluta/rsil-benchmark/tests/test_model.py
-
curl -L -o test_model.py https://huggingface.co/kiruluta/rsil-benchmark/resolve/main/tests/test_model.py
624 Bytes
| import torch | |
| from rsil import RSILConfig, RSILForMaskedLM, ResonantSpectralMixer | |
| def test_forward_backward(): | |
| c=RSILConfig(vocab_size=101,dim=32,depth=2,n_bands=3,groups=4,max_seq_len=64) | |
| m=RSILForMaskedLM(c); x=torch.randint(0,101,(2,64)); y=x.clone(); o=m(x,y); assert o['logits'].shape==(2,64,101); o['loss'].backward() | |
| def test_translation_equivariance(): | |
| c=RSILConfig(dim=32,n_bands=3,groups=4,max_degree=3); m=ResonantSpectralMixer(c).eval(); x=torch.randn(2,64,32) | |
| with torch.no_grad(): | |
| for p in m.gates.values(): p.normal_(0,.1) | |
| a=torch.roll(m(x),7,1); b=m(torch.roll(x,7,1)) | |
| assert (a-b).abs().max()<2e-4 | |