sharpenb's picture
68a40a2e1a63d87c397c2ee4f5be9fc954c358ff607013d6c1ec326ccc4bcc6c
9ce5335 verified
raw
history blame
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)