Skip to content

Instantly share code, notes, and snippets.

View lfrati's full-sized avatar

Lapo Frati lfrati

  • University of Vermont
View GitHub Profile
@lfrati
lfrati / rwkv.py
Created April 5, 2023 16:05 — forked from mattiasarro/rwkv.py
RWKV MVP
# Taken from https://johanwind.github.io/2023/03/23/rwkv_details.html.
# I've added additional comments restructured it a tiny bit, which makes it clearer for me.
import numpy as np
from torch import load as torch_load # Only for loading the model weights
from tokenizers import Tokenizer
exp = np.exp
layer_norm = lambda x, w, b : (x - np.mean(x)) / np.std(x) * w + b
sigmoid = lambda x : 1/(1 + exp(-x))
@lfrati
lfrati / grad.py
Last active October 20, 2018 18:53
"""Toy examples for torch.autograd.grad."""
import torch
from torch.autograd import Variable
# Input
x = torch.tensor([1., 2., 3.], requires_grad=True)
# Weights
w1 = torch.tensor([2., 3., 4.]), requires_grad=True)