Download tests/test_pim_core.py from ZenoNing/ConsDrive: direct link, hf CLI and curl.
- Browser
- Download file 970 Bytes
-
https://huggingface.co/ZenoNing/ConsDrive/resolve/main/tests/test_pim_core.py
- Command line
-
hf download hf://ZenoNing/ConsDrive/tests/test_pim_core.py
-
curl -L -o test_pim_core.py https://huggingface.co/ZenoNing/ConsDrive/resolve/main/tests/test_pim_core.py
970 Bytes
| import torch | |
| from models.pim import PersistentInteractionMemory | |
| def test_identity_and_persistence(): | |
| torch.manual_seed(1) | |
| m = PersistentInteractionMemory(16, slots=2, memory_dim=8, heads=2) | |
| z, a = torch.randn(1, 2, 16), torch.randn(1, 3, 16) | |
| with torch.no_grad(): | |
| m.visibility.weight.zero_() | |
| m.visibility.bias.fill_(10) | |
| m.release[-1].weight.zero_() | |
| m.release[-1].bias.fill_(-10) | |
| out, state, _ = m(z, a, torch.tensor([0.])) | |
| assert torch.equal(out, a) | |
| old = state.features.clone() | |
| with torch.no_grad(): | |
| m.visibility.bias.fill_(-10) | |
| _, state, info = m(z, a, torch.tensor([5.]), state) | |
| assert state.valid.all() | |
| assert torch.equal(state.features, old) | |
| assert torch.equal(info['age'], torch.full((1, 2), 5.)) | |
| assert torch.equal(state.last_observed, torch.zeros(1, 2)) | |
| _, state, _ = m(z, a, torch.tensor([0.]), state, reset=torch.tensor([True])) | |
| assert not state.valid.any() | |