Skip to content

Instantly share code, notes, and snippets.

View README.md

This gist shows how to use rebase to change the Git history of a repo. Imagine you realise that the first commit to your repo should be different (maybe it's incomplete, includes something it shouldn't or simply could be cleaner). However, since then you and others have made many changes to the repo that you want to preserve. Here we show how to split the first commit into multiple and re-attach the remaining version history to these new commits.

Let's make a dummy git repo rebase-root and add two files to it. We commit them with the commit #1.

@gngdb
gngdb / MLP_Mixer_without_Linear.ipynb
Created May 11, 2021
Technically an implementation of MLP-Mixer without nn.Linear
View MLP_Mixer_without_Linear.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View relational.py
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 / example_usage.py
Last active Apr 12, 2021
Wrap PyTorch functions for scipy's optimize.minimize: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html (I also made a repo to do this https://github.com/gngdb/pytorch-minimize, although I had forgotten about this gist at the time)
View example_usage.py
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import numpy as np
from scipy import optimize
from obj import PyTorchObjective
@gngdb
gngdb / Grayscale Quantised Painting Avatar.ipynb
Last active Mar 31, 2021
Generating a new profile picture in the most convoluted way possible.
View Grayscale Quantised Painting Avatar.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Unpacked minGPT.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / Basin Hopping.ipynb
Last active Feb 18, 2021
An example using scipy.optimize's basin hopping with torch calculating gradients
View Basin Hopping.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View roaming-ssh.md

So, you want to be able to work from anywhere. You want to be on a mountain somewhere, two bars of 3G signal, and you forward that to your laptop with a WiFi hotspot. Open your laptop and your shell on remote is already open and as responsive as possible. Work/life balance? With power like this, who cares?

Problem Scenario

Often, in academic institutions at least, you have the following situation:

@gngdb
gngdb / tf-autograd.py
Last active Jun 19, 2020
How to use autograd inside Tensorflow
View tf-autograd.py
import tensorflow as tf
import autograd.numpy as np
from autograd import grad
from tensorflow.python.framework import function
rng = np.random.RandomState(42)
x_np = rng.randn(4,4).astype(np.float32)
with tf.device('/cpu:0'):
x = tf.Variable(x_np)
@gngdb
gngdb / Soap Bubble Effect.ipynb
Created Jun 4, 2020
Soap bubble effect simulation
View Soap Bubble Effect.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.