Skip to content

Instantly share code, notes, and snippets.

View harpone's full-sized avatar

Heikki Arponen harpone

View GitHub Profile
@harpone
harpone / lamb.py
Created September 24, 2020 12:25
Lamb optimizer that doesn't work on TPUs
class Lamb(Optimizer):
r"""Implements Lamb algorithm.
It has been proposed in `Large Batch Optimization for Deep Learning: Training BERT in 76 minutes`_.
Arguments:
params (iterable): iterable of parameters to optimize or dicts defining
parameter groups
lr (float, optional): learning rate (default: 1e-3)
betas (Tuple[float, float], optional): coefficients used for computing
running averages of gradient and its square (default: (0.9, 0.999))
eps (float, optional): term added to the denominator to improve
import numpy as np
cimport cython
cimport numpy as np
from libc.stdint cimport uint32_t, int32_t
from libc.math cimport sqrt
from libc.math cimport fabs
from libc.math cimport pow
@harpone
harpone / gist:401b91d48652d7138844
Last active August 29, 2015 14:07
Pure Python
def simulation(L = 0, N = 100000, dt = 1E-3, init = .1):
"""Simulate a stochastic differential equation.
"""
#Set up some parameters:
f1 = .1
g1 = .01
g2 = .1
dW = np.random.randn(N)*np.sqrt(dt)
@harpone
harpone / Cython
Last active August 29, 2015 14:07
Stochastic differential equations: Python+Numpy vs. Cython. FIGHT!!
# Same with Cython:
import numpy as np
cimport cython
cimport numpy as np
from libc.stdint cimport uint32_t, int32_t
from libc.math cimport sqrt
from libc.math cimport fabs
from libc.math cimport pow