Skip to content

Instantly share code, notes, and snippets.

Gavin Gray gngdb

Block or report user

Report or block gngdb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gngdb
gngdb / ssh.py
Last active Jan 18, 2019
Use boto3 to generate an ssh config file entry for all your running instances (checks to see if you've already added them as well).
View ssh.py
import os
import boto3
if __name__ == '__main__':
session = boto3.Session()
ec2 = session.resource('ec2')
ec2c = session.client('ec2')
# add active instances to the user's ssh config file
instances = ec2.instances.filter(
Filters=[{'Name': 'instance-state-name', 'Values': ['running']}])
@gngdb
gngdb / listregions.py
Last active Jan 5, 2019
Where in the world is Carmen Sandiego? If "Carmen Sandiego" is the cheapest spot price on AWS EC2:
View listregions.py
import boto3
class Session(boto3.Session):
def __enter__(self):
return self
def __exit__(self, *args):
del self
with Session() as sess:
# get names of regions
View imagenet-validation.py
# dependencies
import re
import os
import argparse
import torch
from tqdm import tqdm
#import cv2
import numpy as np
import torch.utils.data
import torchnet as tnt
@gngdb
gngdb / index_select_example.py
Last active Nov 20, 2018
index_select and then reshaping is faster than just indexing?
View index_select_example.py
import torch
if __name__ == '__main__':
X = torch.randn(100)
out_shape = (100,100)
idxs = torch.randint(high=100, size=out_shape).long()
assert torch.abs(X[idxs] - X.index_select(0, idxs.view(-1)).view(*out_shape)).max() < 1e-3
from timeit import timeit
setup = 'import torch; X = torch.randn(100); out_shape=(100,100); idxs = torch.randint(high=100, size=out_shape).long()'
print("X[idxs]: ", timeit("_ = X[idxs]", setup=setup, number=100))
@gngdb
gngdb / hashing.py
Last active Nov 20, 2018
Inefficient HashedNet implementation: https://arxiv.org/abs/1504.04788
View hashing.py
# implementation of https://arxiv.org/abs/1504.04788
import torch
import torch.nn as nn
import torch.nn.functional as F
import xxhash
class HashFunction(object):
"""Hash function as described in the paper, maps a key (i,j) to a natural number
in {1,...,K_L}"""
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 / Efficient Top 1 Error Scatter Plot.ipynb
Last active Feb 19, 2019
Graphing performance for a report.
View Efficient Top 1 Error Scatter Plot.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / reduce.py
Last active Oct 13, 2018
Trying to matmul reduce in PyTorch faster.
View reduce.py
import torch
from functools import reduce
import math
def is_power(n):
# https://stackoverflow.com/a/29480710/6937913
n = n/2
if n == 2:
return True
elif n > 2:
@gngdb
gngdb / Interpolation with ReLUs in PyTorch.ipynb
Last active Sep 17, 2018
Interpolation with ReLUs in PyTorch
View Interpolation with ReLUs in PyTorch.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / Least Squares in PyTorch.ipynb
Last active Jun 3, 2019
Least Squares in PyTorch
View Least Squares in PyTorch.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.