Download linear_attn/utils.py from msj19/newfla4: direct link, hf CLI and curl.
- Browser
- Download file 232 Bytes
-
https://huggingface.co/msj19/newfla4/resolve/main/linear_attn/utils.py
- Command line
-
hf download hf://msj19/newfla4/linear_attn/utils.py
-
curl -L -o utils.py https://huggingface.co/msj19/newfla4/resolve/main/linear_attn/utils.py
232 Bytes
| # -*- coding: utf-8 -*- | |
| import torch | |
| def normalize_output(q: torch.Tensor, k: torch.Tensor, o: torch.Tensor) -> torch.Tensor: | |
| k = k.cumsum(1) | |
| z = (q * k).sum(-1, keepdim=True) | |
| return o / (z + 1e-10) | |