Skip to content

Instantly share code, notes, and snippets.

View yberreby's full-sized avatar

Yohaï-Eliel Berreby yberreby

View GitHub Profile
@yberreby
yberreby / bench_jax.py
Last active April 20, 2025 01:16
Quick JAX vs Triton comparison on a toy kernel. Outputs from runs on a RTX 4060 Mobile.
import functools, time, jax, jax.numpy as jnp
jax.config.update("jax_default_matmul_precision", "tensorfloat32")
SQRT2_OVER_PI = 0.7978845608028654
# ----------------------------------------------------------------------
def gelu_fast(x):
u = SQRT2_OVER_PI * (x + 0.044715 * x * x * x)
return 0.5 * x * (1. + jnp.tanh(u))
@yberreby
yberreby / 0_geom_opt_cmp.py
Last active April 20, 2025 01:16
Quick comparison of a few optimizers on the 2-simplex: GD, Adam, Mirror Descent, Adam in mirror space, LBFGS in mirror space
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "jax==0.5.0",
# "jaxopt>=0.8.5",
# "optax>=0.2.4",
# "matplotlib>=3.10.1",
# "pyqt6>=6.9.0", # for matplotlib gui
# ]
@yberreby
yberreby / cahn_hilliard_literate.py
Last active April 19, 2025 00:06
Cahn-Hilliard - Run this for visually-interesting non-linear ODE behavior, in an animated plot.
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "jax==0.5.0",
# "matplotlib>=3.10.1",
# "pyqt6>=6.9.0", # for matplotlib gui
# ]
# ///
@yberreby
yberreby / eccentricity_dependent_perlin_noise_jax.py
Last active April 17, 2025 23:19
Fast Perlin noise in JAX with eccentricity-dependent feature scaling. GPU-ready.
#!/usr/bin/env -S uv run --script --quiet
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "pyqt6", # For matplotlib backend
# "numpy",
# "matplotlib",
# "jax[cuda12]==0.5.2", # Change for CPU.
# ]
# ///
#include <stdint.h>
#include <immintrin.h>
#include <intrin.h>
#include <stdio.h>
// Count of set bits in `plus` minus count of set bits in `minus`
// The result is in [ -32 .. +32 ] interval
inline int popCntDiff( uint32_t plus, uint32_t minus )
{
plus = __popcnt( plus );
@nateraw
nateraw / stable_diffusion_walk.py
Created August 18, 2022 05:59
Walk between stable diffusion text prompts
"""
Built on top of this gist by @karpathy:
https://gist.github.com/karpathy/00103b0037c5aaea32fe1da1af553355
stable diffusion dreaming over text prompts
creates hypnotic moving videos by smoothly walking randomly through the sample space
example way to run this script:
$ python stable_diffusion_walk.py --prompts "['blueberry spaghetti', 'strawberry spaghetti']" --seeds 243,523 --name berry_good_spaghetti
@codelynx
codelynx / UnsafePointer Converter.swift
Created September 13, 2020 14:57
[swift] Unsafe Pointer conversion
//
// Swift UnsafePointer converter
// Kaz Yoshikawa
//
// These code demonstrates how to convert swift pointers to the other forms of pointers.
//
// Source:
// Swift の Array やら ArraySlice やらポインタの変換まとめ
// https://qiita.com/Satachito/items/4c39c9b06304e4d86660
//
@ChrisRackauckas
ChrisRackauckas / a_stiff_ode_performance_python_julia.md
Last active February 21, 2025 04:52
SciPy+Numba odeint vs Julia ODE vs NumbaLSODA: 50x performance difference on stiff ODE

SciPy+Numba odeint vs Julia DifferentialEquations.jl vs NumbaLSODA Summary

All are solved at reltol=1e-3, abstol=1e-6 using the fastest ODE solver of the respective package for the given problem.

Absolute Performance Numbers:

  • SciPy LSODA through odeint takes ~489μs
  • SciPy LSODA through odeint with Numba takes ~257μs
  • NumbaLSODA takes ~25μs
  • DifferentialEquations.jl Rosenbrock23 takes ~9.2μs
@chicobentojr
chicobentojr / _a-recipe-for-training-neural-networks.md
Created May 10, 2019 12:00
"A Recipe for Training Neural Networks" - Andrej Karpathy

A Recipe for Training Neural Networks - Andrej Karpathy

@DevonMorris
DevonMorris / i3URxvtCurrentDirectory.md
Last active October 7, 2022 12:32
i3 open URxvt in current directory, zsh

Add the following to a script in .config/i3/i3_shell.sh

#!/usr/bin/env bash
WHEREAMI=$(cat /tmp/whereami)
i3-sensible-terminal -cd $WHEREAMI

To call store the environment variable WHEREAMI put