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

Method forward

linear_moe/sequence_modeling/based/based.py:57–76  ·  view source on GitHub ↗
(
        self,
        q: torch.Tensor,
        k: torch.Tensor,
        v: torch.Tensor,
    )

Source from the content-addressed store, hash-verified

55
56
57 def forward(
58 self,
59 q: torch.Tensor,
60 k: torch.Tensor,
61 v: torch.Tensor,
62 ) -> torch.Tensor:
63 # torch.Size([128, 4, 16, 32])
64 q, k, v = (rearrange(x, 'n b h d -> b h n d') for x in (q, k, v))
65
66 # expects q: B, H, T, K
67 if self.la_mode in ['chunk', 'fused_chunk']:
68 q, k = map(self.la_feature_map_fn, (q, k))
69 output, _ = self._la_impl(q, k, v, normalize=True, scale=1)
70 elif self.la_mode == 'parallel':
71 assert q.shape[-1] <= 128
72 output, _ = self._la_impl(q, k, v, True, True)
73
74 output = rearrange(output, 'b h n d -> n b (h d)')
75
76 return output

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected