Skip to content

Instantly share code, notes, and snippets.

View bobchennan's full-sized avatar

cnx bobchennan

View GitHub Profile
@bobchennan
bobchennan / pytorch_reformer.py
Last active January 23, 2020 00:58 — forked from lucidrains/pytorch_reformer.py
reformer(pytorch)
import torch
import torch.nn as nn
import torch.nn.functional as F
# helpers
def make_unit_length(x, epsilon=1e-6):
norm = x.norm(p=2, dim=-1, keepdim=True)
return x.div(norm + epsilon)