distilbert: fix creation of sinusoidal embeddings when using PyTorch 1.8+ (#9917)
This commit is contained in:
@@ -73,10 +73,10 @@ DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST = [
|
|||||||
|
|
||||||
def create_sinusoidal_embeddings(n_pos, dim, out):
|
def create_sinusoidal_embeddings(n_pos, dim, out):
|
||||||
position_enc = np.array([[pos / np.power(10000, 2 * (j // 2) / dim) for j in range(dim)] for pos in range(n_pos)])
|
position_enc = np.array([[pos / np.power(10000, 2 * (j // 2) / dim) for j in range(dim)] for pos in range(n_pos)])
|
||||||
|
out.requires_grad = False
|
||||||
out[:, 0::2] = torch.FloatTensor(np.sin(position_enc[:, 0::2]))
|
out[:, 0::2] = torch.FloatTensor(np.sin(position_enc[:, 0::2]))
|
||||||
out[:, 1::2] = torch.FloatTensor(np.cos(position_enc[:, 1::2]))
|
out[:, 1::2] = torch.FloatTensor(np.cos(position_enc[:, 1::2]))
|
||||||
out.detach_()
|
out.detach_()
|
||||||
out.requires_grad = False
|
|
||||||
|
|
||||||
|
|
||||||
class Embeddings(nn.Module):
|
class Embeddings(nn.Module):
|
||||||
|
|||||||
Reference in New Issue
Block a user