MCPcopy Create free account
hub / github.com/OpenSparseLLMs/Linear-MoE / TaylorFeatureMap

Class TaylorFeatureMap

linear_moe/model/common_modules/feature_map.py:190–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188
189
190class TaylorFeatureMap(nn.Module):
191 def __init__(
192 self,
193 head_dim: int
194 ) -> TaylorFeatureMap:
195 super().__init__()
196 self.head_dim = head_dim
197 self.r2 = math.sqrt(2)
198 self.rd = math.sqrt(self.head_dim)
199 self.rrd = math.sqrt(self.rd)
200
201 def forward(self, x: torch.Tensor):
202 x2_1, x2_2 = flatten_diag_outer_product_off1(x, x)
203 return torch.cat([torch.ones_like(x[..., 0:1]), x / self.rrd, x2_2 / (self.rd * self.r2), x2_1 / self.rd], dim=-1)
204
205
206class RebasedFeatureMap(nn.Module):

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected