• Stars
    star
    736
  • Rank 61,564 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python library to easily log experiments and parallelize hyperparameter search for neural networks

react-router

Test Tube

Log, organize and parallelize hyperparameter search for Deep Learning experiments

PyPI version

Docs

View the docs here


Test tube is a python library to track and parallelize hyperparameter search for Deep Learning and ML experiments. It's framework agnostic and built on top of the python argparse API for ease of use.

pip install test_tube

Main test-tube uses

Compatible with Python any Python ML library like Tensorflow, Keras, Pytorch, Caffe, Caffe2, Chainer, MXNet, Theano, Scikit-learn


Examples

The Experiment object is a subclass of Pytorch.SummaryWriter.

Log and visualize with Tensorboard

from test-tube import Experiment
import torch

exp = Experiment('/some/path')
exp.tag({'learning_rate': 0.02, 'layers': 4})    

# exp is superclass of SummaryWriter
features = torch.Tensor(100, 784)
writer.add_embedding(features, metadata=label, label_img=images.unsqueeze(1))

# simulate training
for n_iter in range(2000):
    e.log({'testtt': n_iter * np.sin(n_iter)})

# save and close
exp.save()
exp.close()
pip install tensorflow   

tensorboard --logdir /some/path

Run grid search on SLURM GPU cluster

from test_tube.hpc import SlurmCluster

# hyperparameters is a test-tube hyper params object
hyperparams = args.parse()

# init cluster
cluster = SlurmCluster(
    hyperparam_optimizer=hyperparams,
    log_path='/path/to/log/results/to',
    python_cmd='python3'
)

# let the cluster know where to email for a change in job status (ie: complete, fail, etc...)
cluster.notify_job_status(email='[email protected]', on_done=True, on_fail=True)

# set the job options. In this instance, we'll run 20 different models
# each with its own set of hyperparameters giving each one 1 GPU (ie: taking up 20 GPUs)
cluster.per_experiment_nb_gpus = 1
cluster.per_experiment_nb_nodes = 1

# run the models on the cluster
cluster.optimize_parallel_cluster_gpu(train, nb_trials=20, job_name='first_tt_batch', job_display_name='my_batch')   

# we just ran 20 different hyperparameters on 20 GPUs in the HPC cluster!!    

Optimize hyperparameters across GPUs

from test_tube import HyperOptArgumentParser

# subclass of argparse
parser = HyperOptArgumentParser(strategy='random_search')
parser.add_argument('--learning_rate', default=0.002, type=float, help='the learning rate')

# let's enable optimizing over the number of layers in the network
parser.opt_list('--nb_layers', default=2, type=int, tunable=True, options=[2, 4, 8])

# and tune the number of units in each layer
parser.opt_range('--neurons', default=50, type=int, tunable=True, low=100, high=800, nb_samples=10)

# compile (because it's argparse underneath)
hparams = parser.parse_args()

# optimize across 4 gpus
# use 2 gpus together and the other two separately
hparams.optimize_parallel_gpu(MyModel.fit, gpu_ids=['1', '2,3', '0'], nb_trials=192, nb_workers=4)

Or... across CPUs

hparams.optimize_parallel_cpu(MyModel.fit, nb_trials=192, nb_workers=12)

You can also optimize on a log scale to allow better search over magnitudes of hyperparameter values, with a chosen base (disabled by default). Keep in mind that the range you search over must be strictly positive.

from test_tube import HyperOptArgumentParser

# subclass of argparse
parser = HyperOptArgumentParser(strategy='random_search')

# Randomly searches over the (log-transformed) range [100,800).

parser.opt_range('--neurons', default=50, type=int, tunable=True, low=100, high=800, nb_samples=10, log_base=10)


# compile (because it's argparse underneath)
hparams = parser.parse_args()

# run 20 trials of random search over the hyperparams
for hparam_trial in hparams.trials(20):
    train_network(hparam_trial)

Convert your argparse params into searchable params by changing 1 line

import argparse
from test_tube import HyperOptArgumentParser

# these lines are equivalent
parser = argparse.ArgumentParser(description='Process some integers.')
parser = HyperOptArgumentParser(description='Process some integers.', strategy='grid_search')

# do normal argparse stuff
...

Log images inline with metrics

# name must have either jpg, png or jpeg in it
img = np.imread('a.jpg')
exp.log('test_jpg': img, 'val_err': 0.2)

# saves image to ../exp/version/media/test_0.jpg
# csv has file path to that image in that cell

Demos

How to contribute

Feel free to fix bugs and make improvements! 1. Check out the current bugs here or feature requests. 2. To work on a bug or feature, head over to our project page and assign yourself the bug. 3. We'll add contributor names periodically as people improve the library!

Bibtex

To cite the framework use:

@misc{Falcon2017,
  author = {Falcon, W.A.},
  title = {Test Tube},
  year = {2017},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/williamfalcon/test-tube}}
}    

License

In addition to the terms outlined in the license, this software is U.S. Patent Pending.

More Repositories

1

DeepRLHacks

Hacks for training RL systems from John Schulman's lecture at Deep RL Bootcamp (Aug 2017)
1,079
star
2

tensorflow-gpu-install-ubuntu-16.04

Tensorflow GPU install instructions for ubuntu 16.04 - Deep learning
288
star
3

pytorch-lightning-vae

VAE for color images
Python
170
star
4

pix2pix-keras

Image-to-Image Translation with Conditional Adversarial Networks (Pix2pix) implementation in keras
Python
141
star
5

SwiftTryCatch

Adds try-catch support for Swift
Objective-C
139
star
6

keras-deep-learning-paper-implementations

Keras implementation of Deep Learning papers
93
star
7

pytorch-complex-tensor

Unofficial complex tensor and scalar support for Pytorch
Python
78
star
8

SwiftArmyKnife

Collection of low level Swift extensions
Swift
66
star
9

pytorch-gpu-install

Instructions for installing pytorch to run on GPU
36
star
10

Matrix-Factorization-Recommender-Systems-Netflix-Paper-Implementation

Implementation of the Matrix Factorization Recommender System from the Netflix Paper
Python
28
star
11

deep-learning-gpu-box-build-instructions

Instructions and parts for building a deep learning GPU box
22
star
12

pytorch-imagenet-dataset

Imagenet dataset for pytorch
Python
20
star
13

Predicting-floor-level-for-911-Calls-with-Neural-Networks-and-Smartphone-Sensor-Data

Code + data for predicting floor location from smartphone sensor data
Jupyter Notebook
11
star
14

vae_demo

Python
8
star
15

NoNetworkViewController

View controller that takes over screen when there is no internet connection. Critical for networked apps.
Objective-C
7
star
16

WFLocationService

Simplest Location Service for iOS. In Swift
Swift
5
star
17

cifar5

Python
5
star
18

WF-iOS-Categories

Adds JS-like methods to simplify manipulation of some objects
Objective-C
4
star
19

NLP-Viterbi-POS-Tagger-HMM

POS Tagger, N-Grams
Python
4
star
20

docker-flask-nginx-uwsgi-miniconda-3.4

Docker image for flask app running on nginx uwsgi and miniconda with python 3.4 installed
Python
3
star
21

fun_with_git

Python
3
star
22

demo_model

Python
2
star
23

WHARF

Wifi at Hotels, Airports, Restaurants for Free
Shell
2
star
24

sensory

iOS Sensors app
C++
2
star
25

hello

Python
2
star
26

theano-deep-neural-net

Deep neural network implementation using theano and lasagne
Python
1
star
27

debug_023423

Python
1
star
28

deep-learning-blog

My ML/Deep learning blog
HTML
1
star
29

demo_3

Python
1
star
30

NLP_HW3

hw3
Python
1
star
31

PySQLManager

A simple class to abstract MYSQL interactions with python programs
Python
1
star
32

hh

1
star
33

new_system

my vim folder
Vim Script
1
star
34

NLP_HW2

hw2
Python
1
star
35

ghostKey

Ephemeral open source password manager for iOS. Like OnePassword without hidden tricks or network syncing.
Objective-C
1
star
36

6998GoogleMapsFramework

Framework needed for 699807 HW 1 assignment
Objective-C
1
star
37

ml-indoor-outdoor-classifier

Determines whether someone is indoors or outdoors.
OpenEdge ABL
1
star
38

asdfasdf

1
star
39

docker-data-science-flask-ebs

Fully deployable AWS EBS ML App with flask, scipy, pandas, and more inside Docker Container
Python
1
star