Skip to content

Instantly share code, notes, and snippets.

View fredmonroe's full-sized avatar

fred monroe fredmonroe

View GitHub Profile
@jeremiecoullon
jeremiecoullon / Jax_progress_bar_tqdm.py
Last active October 12, 2022 14:51
Add a tqdm progress bar to a JAX scan or fori_loop. Code from this blog post: This code is from this blog post: https://www.jeremiecoullon.com/2021/01/29/jax_progress_bar/
from tqdm.auto import tqdm
from jax import jit, vmap, grad, random, lax, partial
import jax.numpy as jnp
from jax.experimental import host_callback
def progress_bar_scan(num_samples, message=None):
"Progress bar for a JAX scan"
if message is None:
message = f"Running for {num_samples:,} iterations"
@Flunzmas
Flunzmas / calc_2_wasserstein_dist.py
Last active December 21, 2025 12:24
Differentiable 2-Wasserstein Distance in PyTorch
import math
import torch
import torch.linalg as linalg
def calculate_2_wasserstein_dist(X, Y):
'''
Calulates the two components of the 2-Wasserstein metric:
The general formula is given by: d(P_X, P_Y) = min_{X, Y} E[|X-Y|^2]
For multivariate gaussian distributed inputs z_X ~ MN(mu_X, cov_X) and z_Y ~ MN(mu_Y, cov_Y),
@DannyQuah
DannyQuah / 2022.01-D.Quah-Obsidian-iPad-syncing-via-iSH-git.md
Last active November 20, 2025 22:06
Obsidian on iPad syncing via iSH, git, and GitHub

Obsidian iPad syncing via iSH git

by Danny Quah, Jan 2022

This gist describes using Obsidian on iPad while syncing to other Obsidian platforms. The procedure uses git in iSH on iOS, and thus differs from using either Obsidian Sync or Working Copy as described in Obsidian/iOS+app.

(To be clear, Obsidian is one of my favourite Apps, and I'm all for supporting the team financially. Moreover, everything I've heard suggests the paid Obsidian Sync is excellent. However, I don't want my syncing processes to proliferate --- each service using a different client sync flow --- so I keep my systems minimal: just syncthing and git. After writing this I found an Obsidian Forum writeup which uses the same tools I do to achieve the same goal, but you'll want to read that with its accumulated contributions dispersed across the comments. So at least I was thinking

@trygvebw
trygvebw / find_noise.py
Last active December 13, 2025 14:53
A "reverse" version of the k_euler sampler for Stable Diffusion, which finds the noise that will reconstruct the supplied image
import torch
import numpy as np
import k_diffusion as K
from PIL import Image
from torch import autocast
from einops import rearrange, repeat
def pil_img_to_torch(pil_img, half=False):
image = np.array(pil_img).astype(np.float32) / 255.0
@z-ai-lab
z-ai-lab / ws_streaming.py
Created August 3, 2024 20:14
Chatbot built with fasthtml and ollama (websocket streaming)
from fasthtml.common import *
import ollama
import asyncio
# Set up the app, including daisyui and tailwind for the chat component
tlink = (Script(src="https://unpkg.com/[email protected]/tailwindcss.js"),)
dlink = Link(
rel="stylesheet",
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/full.min.css",
)