moondream-2b-2025-04-14-4bit / fourier_features.py
EthanReid
Initial import of code and 4-bit weights
1c87faa
raw
history blame contribute delete
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)