sharpenb's picture
b0a50a3f8cc901f6ecd22e384836a9d411ad00f39ff27c7cc3d0341bf7e70f54
ca8a03f 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)