Download fourier_features.py from Aryan215gupta/moondream: direct link, hf CLI and curl.
- Browser
- Download file 558 Bytes
-
https://huggingface.co/Aryan215gupta/moondream/resolve/main/fourier_features.py
- Command line
-
hf download hf://Aryan215gupta/moondream/fourier_features.py
-
curl -L -o fourier_features.py https://huggingface.co/Aryan215gupta/moondream/resolve/main/fourier_features.py
558 Bytes
| # Adopted from https://github.com/crowsonkb/k-diffusion/blob/transformer-model-v2/k_diffusion/layers.py | |
| import torch | |
| import torch.nn as nn | |
| import math | |
| class FourierFeatures(nn.Module): | |
| def __init__(self, in_features, out_features, std=1.0): | |
| super().__init__() | |
| assert out_features % 2 == 0 | |
| self.register_buffer( | |
| "weight", torch.randn([out_features // 2, in_features]) * std | |
| ) | |
| def forward(self, input): | |
| f = 2 * math.pi * input @ self.weight.T | |
| return torch.cat([f.cos(), f.sin()], dim=-1) | |