transformer process

This commit is contained in:
wassname
2020-10-23 08:30:02 +08:00
parent 152b0c4afd
commit 7f91ce5aab
2 changed files with 178 additions and 0 deletions
+4
View File
@@ -8,3 +8,7 @@ def to_numpy(x):
if isinstance(x, torch.Tensor):
x = x.cpu().detach().numpy()
return x
def mask_upper_triangular(N, device):
"""Causal attention."""
return torch.triu(torch.ones(N, N), diagonal=1).to(device).bool()