This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = tf.constant([[1,2],[3,4]]) | |
row_to_add = tf.constant([1, 1]) | |
original_row = a[0] | |
updated_row = original_row + row_to_add | |
unchanged_indices = tf.range(tf.size(a)) | |
changed_indices = tf.range(a.get_shape()[0]) | |
a_flat = tf.reshape(a, [-1]) | |
updated_a_flat = tf.dynamic_stitch([unchanged_indices, changed_indices], [a_flat, updated_row]) | |
updated_a = tf.reshape(updated_a_flat, a.get_shape()) | |
print sess.run(updated_a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of profiling session.run overhead | |
# for python profiling | |
# python -m cProfile -o session-run-benchmark-feed.prof session-run-benchmark.py feed_dict | |
# python -m cProfile -o session-run-benchmark-variable.prof session-run-benchmark.py variable | |
# pip install snakeviz | |
# snakeviz session-run-benchmark-feed.prof | |
# snakeviz session-run-benchmark.prof | |
# | |
# | |
# Feed_dict: 147 usec, no feed dict, 71 usec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make things wide | |
from IPython.core.display import display, HTML | |
display(HTML("<style>.container { width:100% !important; }</style>")) | |
from IPython.display import clear_output, Image, display, HTML | |
def strip_consts(graph_def, max_const_size=32): | |
"""Strip large constant values from graph_def.""" | |
strip_def = tf.GraphDef() | |
for n0 in graph_def.node: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.protobuf import text_format | |
from tensorflow.core.framework import op_def_pb2 | |
ops = op_def_pb2.OpList() | |
ops_text = open("/local_home/yaroslav/tensorflow.git/tensorflow/tensorflow/core/ops/ops.pbtxt").read() | |
text_format.Merge(ops_text, ops) | |
print(len(ops.op)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Benchmark transferring data from TF into Python runtime | |
# | |
## Dependencies: | |
# portpicker (pip install portpicker) | |
# tcmalloc4 (sudo apt-get install google-perftools) | |
# TF 0.12 (for var.read_value(), ones_initializer()) | |
# | |
# On Linux default malloc is slow | |
# sudo apt-get install google-perftools | |
# export LD_PRELOAD="/usr/lib/libtcmalloc.so.4" |