mosaicml-mpt-7b-bnb-4bit-smashed / custom_embedding.py
sharpenb's picture
642669c10af619d213b9209de15227101a5692a7f43569f9574eef6396839498
27ec240 verified
raw
history blame
No virus
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)