sharpenb's picture
6bfa63b591b641dbe9c0d415d1bd3cd52e99a403eadec000fcf8f80c4efd5c7f
85b445c 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)