Skip to content

Instantly share code, notes, and snippets.

Yaroslav Bulatov yaroslavvb

View GitHub Profile
@yaroslavvb
yaroslavvb / pytorch_lbfgs.py
Created Dec 3, 2017
PyTorch tied autoencoder with l-BFGS
View pytorch_lbfgs.py
import util as u
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.autograd import Variable
import numpy as np
# todo: make images global
@yaroslavvb
yaroslavvb / memory_parsing_test.py
Created Oct 31, 2017
Example of getting memory allocation stats out of timeline
View memory_parsing_test.py
import tensorflow as tf
import memory_util
import numpy as np
def memory_timeline_from_nodestats(nodestats):
lines = []
for node in nodestats:
mem = node.memory
assert(len(mem) == 1), str(node)
View benchmark_add_pytorch.py
import torch
import numpy as np
import time
def benchmark():
SIZE_GB = 1
num_iters = 100
def compute():
a = torch.ones(int(SIZE_GB*1000*250000)).cuda()
@yaroslavvb
yaroslavvb / resnet_test.py
Created Oct 28, 2017
Resnet minimize in Eager mode
View resnet_test.py
import tensorflow as tf
from tensorflow.contrib.eager.python import tfe
tfe.enable_eager_execution()
context = tf.device('/gpu:0')
context.__enter__()
# download resnet_model
import sys, os, urllib.request
resnet_model_url="https://raw.githubusercontent.com/tensorflow/models/master/official/resnet/resnet_model.py"
response = urllib.request.urlopen(resnet_model_url)
@yaroslavvb
yaroslavvb / train2.py
Last active Feb 6, 2018
example of using TMUX
View train2.py
import argparse
import os
import sys
from six.moves import shlex_quote
parser = argparse.ArgumentParser(description="Run commands")
parser.add_argument('-w', '--num-workers', default=1, type=int,
help="Number of workers")
parser.add_argument('-r', '--remotes', default=None,
help='The address of pre-existing VNC servers and '
@yaroslavvb
yaroslavvb / kfac_nano_eager_test.py
Last active May 31, 2018
Small example of KFAC in Eager mode
View kfac_nano_eager_test.py
import numpy as np
import tensorflow as tf
import scipy
from tensorflow.contrib.eager.python import tfe
tfe.enable_eager_execution()
# manual numpy example
# X = np.array(([[0., 1], [2, 3]]))
# W0 = X
# W1 = np.array(([[0., 1], [2, 3]]))/10
@yaroslavvb
yaroslavvb / kfac_small_pytorch_test.py
Created Oct 19, 2017
toy example of KFAC in pytorch
View kfac_small_pytorch_test.py
# Times: min: 440.60, median: 452.39, mean: 453.87
import util as u
u.check_mkl()
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
View Example of conditional initialization
import tensorflow as tf
from tensorflow.python.ops import control_flow_ops
from tensorflow.contrib import graph_editor as ge
def make_conditional_initializer(v):
"""Makes initializer of variable var lazy, returns new conditional init
op."""
cond = tf.is_variable_initialized(v)
@yaroslavvb
yaroslavvb / copy_initializer
Created Mar 7, 2017
utility to copy initializer for one variable to another
View copy_initializer
def copy_initializer(from_var, to_var):
from tensorflow.contrib import graph_editor as ge
assert ge.reroute_a2b_ts(from_var.initial_value, to_var.initial_value), "No copy took place"
@yaroslavvb
yaroslavvb / github-recipes.txt
Last active Apr 6, 2017
TensorFlow github recipes
View github-recipes.txt
1. Making Pull Request
First, click "Fork" on github tensorflow page
Then in Terminal:
export user=yaroslavvb
export branch_name
git clone https://github.com/$user/tensorflow.git
cd tensorflow
You can’t perform that action at this time.