vinai-PhoGPT-4B-bnb-4bit-smashed / custom_embedding.py
sharpenb's picture
58f6a980e0b3deb26fe37954ebdbdff6d1306bbd78a9b16f983f8814fcd29a8f
4a1e990 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)