Skip to content

Instantly share code, notes, and snippets.

# function to untar arxiv source files into a folder
untar_arxiv () {
# Check if the file has a .tar.gz suffix
if [[ $1 == *.tar.gz ]]; then
# Extract the base name without the .tar.gz suffix
base_name=$(basename "$1" .tar.gz)
mkdir -p "$base_name"
tar -xvf "$1" -C "$base_name"
else
# Add the .tar.gz suffix to the filename
@gngdb
gngdb / itertools_einsum.py
Created April 10, 2024 22:13
einsum implemented with `itertools.product`
import torch
import itertools
from collections import OrderedDict
def einsum_itertools(equation, *operands, verbose=False):
# Parse the equation
input_labels, output_labels = equation.split('->')
input_labels = input_labels.split(',')
if verbose:
print(f"{input_labels=} {output_labels=}")
@gngdb
gngdb / tpu_configssh.py
Last active October 11, 2022 19:23
Script to do the same thing as https://cloud.google.com/sdk/gcloud/reference/compute/config-ssh but works for TPU VMs
# script to add gcloud instances to ssh config
#
# Usage: tpu_configssh.py <instance_name> <instance_name> ...
#
# A version of this exists in gcloud compute config-ssh but it doesn't work for TPU VMs
#
# Works by parsing the output of dryrun mode of gcloud compute ssh, example:
# $ gcloud alpha compute tpus tpu-vm ssh instance-name --dry-run
# /usr/bin/ssh -t -i /home/user/.ssh/google_compute_engine -o CheckHostIP=no -o HashKnownHosts=no -o HostKeyAlias=<alias> -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/home/user/.ssh/google_compute_known_hosts user@IP
@gngdb
gngdb / .bashrc
Last active September 23, 2022 13:25
Add to bashrc to autocomplete nvim scp commands: `nvim <remote>:/path/to/file.py`
# autocomplete nvim scp commands
nvim () {
local params=();
while [[ ! -z $1 ]]; do
if [[ "$1" =~ ^[a-z0-9-]*:/.*$ ]]; then
params=("scp://${1/:\//\/\//}" "${params[@]}");
else
params+=("$1");
fi;
shift;
@gngdb
gngdb / downloader.py
Last active July 26, 2021 20:48
Download utility for AIST++ edited to use aria2c https://google.github.io/aistplusplus_dataset/download.html
# coding=utf-8
# Copyright 2020 The Google AI Perception Team Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@gngdb
gngdb / Pooling.ipynb
Created June 23, 2021 16:06
Pooling notebook for checking einops channel pooling correctness
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / MLP_Mixer_without_Linear.ipynb
Created May 11, 2021 01:48
Technically an implementation of MLP-Mixer without nn.Linear
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import torch
from einops import rearrange, repeat, reduce
def relation(input, g, embedding=None, max_pairwise=None):
r"""Applies an all-to-all pairwise relation function to a set of objects.
See :class:`~torch.nn.Relation` for details.
"""
# Batch size, number of objects, feature size
b, o, c = input.size()
# Create pairwise matrix
@gngdb
gngdb / Grayscale Quantised Painting Avatar.ipynb
Last active March 31, 2021 17:56
Generating a new profile picture in the most convoluted way possible.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.