sharpenb's picture
2328f3216c115fc82ab32763645b2bed34c882a1fc288a6a7939efbe5a94ade0
663114b verified
raw
history blame
No virus
292 Bytes
import torch.nn as nn
import torch.nn.functional as F
from torch import Tensor
class SharedEmbedding(nn.Embedding):
def forward(self, input: Tensor, unembed: bool=False) -> Tensor:
if unembed:
return F.linear(input, self.weight)
return super().forward(input)