Skip to content

Instantly share code, notes, and snippets.

View Interpause's full-sized avatar

John-Henry Lim Interpause

View GitHub Profile
@Interpause
Interpause / pyproject.toml
Created May 25, 2023 01:39
Bug Report Poetry 1
[tool.poetry]
name = "til-23-cv"
version = "0.1.0"
description = ""
authors = ["Author <author@example.com>"]
readme = "README.md"
packages = [{include = "til_23_cv"}]
[tool.poetry.dependencies]
python = "^3.9"
@Interpause
Interpause / hash_torch.py
Created April 1, 2023 07:25
PyTorch Tensor and Model Weights Deterministic Hexdigest
"""Utilities to hash `torch.Tensor` and `nn.Module.state_dict()`."""
import numpy as np
import torch
import torch.nn as nn
from xxhash import xxh3_64_hexdigest as hexdigest
__all__ = ["hash_tensor", "hash_model"]
@Interpause
Interpause / slot_attention.py
Last active April 1, 2023 06:35
PyTorch Slot Attention: Use efficient attention impl, dynamic number of slots, & can pass forward past slots.
"""Slot Attention implementation in PyTorch based on official TensorFlow implementation.
Some modifications were made, namely:
- Can pass forward previous slots to the next time step.
- Dynamic number of slots between calls.
- Uses `F.scaled_dot_product_attention` for more performance.
"""
from typing import Tuple
@Interpause
Interpause / IsogridBackground.js
Created July 17, 2021 14:28
Pure JS version of my SVG background
/**
* @file Generates a colorful animated SVG of equilateral triangles on an isogrid. Pure JS version.
* @author John-Henry Lim <hyphen@interpause.dev>
*/
/** Very simple RNG used for randomizing the animated triangles. */
const detRNG = (s) => () => ((2 ** 31 - 1) & (s = Math.imul(48271, s))) / 2 ** 31
/** The seeded RNG function. */
let rand = () => 0.5
@Interpause
Interpause / LayeredConfig.ts
Created January 15, 2021 14:34
The most ridiculous piece of Typescript I ever wrote just to merge nested objects and invert them while being type-strict.
/**
* @file Suffering with typescript and breaking the tslinter a few times.
* @author John-Henry Lim <hyphen@interpause.dev>
*/
/** K2 are the keys for the inner config. */
export type InnerConfig<K2 extends keyof any,V extends keyof any> = Partial<Record<K2,V>>|V;
/** K1 are the keys for the outer config, K2 are the keys for the inner config. */
export type LayeredConfig<K1 extends keyof any,K2 extends keyof any,V extends keyof any> = Partial<Record<K1,InnerConfig<K2,V>>>;
/** K1 and K2 are reversed on purpose. This is to invert the config structure. */
export type DefaultLayeredConfig<K1 extends keyof any,K2 extends keyof any,V> = Readonly<Record<K2,Record<K1,V>>>;