sharpenb's picture
ffc187469f3beb4fe4138599a9c9241d401e693fbec54875f96d056bca4a0d2c
713d972 verified
raw
history blame
296 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)