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 November 11, 2025 08:56 — 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)