Olympus
latest

Getting Started

  • First Steps
  • Observers and Aspects
    • What not to do
    • Observers
    • Aspect

Examples

  • Minimalist Example
  • Simple Hyper Parameter Search
  • Parallel Hyper Parameter Search
  • Simple Dashboard
  • Dynamic Dashboard

Contributing

  • Contributing to Olympus
    • Adding new Basic Blocks
      • Models
      • Model Optimizer
      • Weight Initialization
      • Schedule
      • Tasks
      • Baselines
      • Datasets
      • Dataset Sampling
      • Metrics
      • Observers
      • Hyper-parameter Optimizer
    • Specifying hyper-parameters
    • Examples
      • Custom Model
      • Custom Model with NAS
      • Custom Optimizer
      • Custom Schedule
      • Custom Observer

API

  • Accumulators
    • olympus.accumulators.smoothing module
  • Dashboard
    • Plots
      • Exploration
      • Importance
      • Training Curves
      • Work Distribution
      • Work Status
      • Saliency Map
      • Layer Inspection
  • Baselines
    • Classification
    • Launcher
      • Parallelization
      • Monitoring
    • Module contents
  • Datasets
    • Archive
    • CIFAR 10
    • CIFAR 100
    • All Dataset
    • Extended MNIST
    • FakeDataset
    • Fashion MNIST
    • Gaussian
    • ImageNet
    • MNIST
    • Pennfudan
    • SVHN
    • Tensor HDF5
    • Tiny ImageNet
    • Transformed Dataset
  • Distributed
    • Multi GPU
    • Module contents
  • Hyper parameter Optimization
    • Registered HPO
      • Hyperband
      • Random Search
    • Module contents
  • Metrics
    • Available Metrics
      • Reinforcement Learning
      • Accuracy
      • Adversary
    • Module contents
  • Models
    • Registered Models
      • Efficientnet
      • LeNet
      • Logistic Regression
      • MultiLayer Perceptron
      • Mobilenetv2
      • PreActResnet
      • Resnet
      • VGG
      • Initializations
        • Registered Initializations
        • Module contents
    • Module contents
  • Observers
    • Available Observers
      • Progress
    • Observer Interface
    • Observer List
  • Optimizers
    • Adam
    • AMSGrad
    • Base
    • SGD
    • Module contents
  • Reinforcement Learning
    • Reinforcement Loader
    • Parallel Environments
    • Gym Environment
    • Procedurally Generated Environment
    • Replay Vector
    • Module contents
  • Samplers
    • Group
  • Schedules
    • Cyclic
    • Exponential
    • Module contents
  • Split Methods
    • Balanced Classes
    • Boostrap
    • Constrained Bootstrap
    • CrossValid
    • Original
    • Resample
    • Split
    • SubSample
  • Tasks
    • Classification
    • Object Detection
    • olympus.tasks.gan module
    • olympus.tasks.segmentation module
    • olympus.tasks.task module
    • Reinforcement
      • Actor Critic
      • Proximal Policy Optimization
  • Utilities
    • dtypes
    • Factory
    • Mixed Precision
    • Network
    • Options
    • Signals
    • Statistics
    • Storage
    • Subpackages
      • GPU
        • Submodules
        • Module contents
    • Module contents
Olympus
  • Docs »
  • <no title> »
  • Parallel Hyper Parameter Search
  • Edit on GitHub
Next Previous

Parallel Hyper Parameter SearchΒΆ

import argparse
import itertools
from olympus.hpo import HPOptimizer, Fidelity, ParallelHPO


def train(uid, epoch, a, b, c, lr):
    return a + b + c + lr


def parallel_hpo(**kwargs):
    args = argparse.Namespace(**kwargs)

    # Arguments required for the HPO workers to synchronize
    parser = argparse.ArgumentParser()
    parser.add_argument('--rank', type=int,
                        help='Worker rank, use to initialize the HPO')
    parser.add_argument('--uri', type=str, default='cockroach://192.168.0.1:8123',
                        help='Resource URI pointing to the database')
    parser.add_argument('--experiment', type=str, default='classification',
                        help='Database namespace to use for this experiment')

    parser.parse_args(namespace=args)

    params = {
        'a': 'uniform(0, 1)',
        'b': 'uniform(0, 1)',
        'c': 'uniform(0, 1)',
        'lr': 'uniform(0, 1)'
    }

    hpo = HPOptimizer('hyperband', fidelity=Fidelity(1, 30).to_dict(), space=params)

    # Wrap your HPO into Olympus ParallelHPO
    hpo = ParallelHPO(
        hpo,
        rank=args.rank,
        uri=args.uri,
        experiment=args.experiment)

    # Iterate over your configs distributed across workers
    for config in hpo:
        print('Worker: ', args.rank, config)
        validation_error = train(**config)
        hpo.observe(config, validation_error)

    # get the result of the HPO
    print(f'Worker {args.rank} is done')
    best_trial = hpo.result()
    if best_trial is not None:
        print(best_trial.params, best_trial.objective)


if __name__ == '__main__':
    # The code below is boilerplate to make the example work on your local machine without requiring
    # multiple nodes.

    # The script above assume you have a database running
    from olympus.hpo.worker import HPOWorkGroup

    # First time setup
    #   1. Launch a cockroach server
    #      Create the Namespace for our experiment
    uri = 'mongo://0.0.0.0:8123'
    namespace = 'trial'

    with HPOWorkGroup(uri, 'olympus', 'classification', clean=True, launch_server=True) as group:
        # Anywhere else; start as many clients as you want
        # we will use multiprocessing as an example but we can easily spawn clients on different nodes
        # as long as all the nodes can reach the database it will work
        from multiprocessing import Process

        count = 10
        workers = []
        for w in range(0, count):
            p = Process(
                target=parallel_hpo,
                kwargs=dict(uri=uri, namespace=namespace, rank=w)
            )
            p.start()
            workers.append(p)

        # wait for the client to finish
        for w in workers:
            w.join()
            print(f'closing {w}')
            w.close()

        # save the experiment for analysis
        group.archive('data.zip')
        group.stop()
Next Previous

© Copyright 2017-2019 Pierre Delaunay Revision b5b7a2b1.

Built with Sphinx using a theme provided by Read the Docs.