Skip to content

Instantly share code, notes, and snippets.

View harpone's full-sized avatar

Heikki Arponen harpone

View GitHub Profile
@harpone
harpone / serial.py
Created September 8, 2022 19:54
Serial 1 layer NN
# SERIAL:
W = parameter(M, N)
def forward(x_: float32[N]) -> float32:
# matrix-vector multiplication:
zs = float32[M] # let's imagine we have a float32 dtype in Vyper
for i, W_row in enumerate(W):
zs[i] = dot(W_row, x_) # 'dot' is an external smart contract
# summation:
@harpone
harpone / parallel.py
Created September 8, 2022 19:58
Parallel NN layer
# PARALLEL:
from contractpool import ContractPool # imaginary 'contractpool' library, similar to python's `multiprocessing`
W = parameter(M, N)
def forward(x_: float32[N]) -> float32:
# matrix-vector multiplication:
zs = float32[M] # let's imagine we have a float32 dtype in Vyper
with ContractPool(dot, M) as p:
p.map(W, x_, out=zs) # launches M subcontracts asynchronously, each subcontract writes values to zs
@harpone
harpone / lru.py
Created March 23, 2023 20:11
LRU with self-attention
def forward_sequential(h, xs, U, W, nu, theta):
"""Forward pass through the network sequentially over input `xs` of any length.
NOTE: has no batch dimension. To be batched with `vmap`.
Args:
h (torch.tensor): shape [D_h, ]; previous state
xs (torch.tensor): shape [T, D_x]; input sequence
U (torch.tensor): Parameter matrix of shape [D_h, D_x]
W (torch.tensor): Parameter matrix of shape [D_h, D_x]
xi (torch.tensor): Parameter vector of shape [D_h, ]
@harpone
harpone / keybase.md
Created March 25, 2023 09:26
keybase.md

Keybase proof

I hereby claim:

  • I am harpone on github.
  • I am harpone (https://keybase.io/harpone) on keybase.
  • I have a public key ASDFQqiM9-Yg0wVF3nsnOaVSan8jKCAgtTLccHHts8RhaQo

To claim this, I am signing this object: