Skip to content

Commit

Permalink
Release 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzmeister committed Apr 25, 2019
2 parents 501473a + 3648a6c commit 8144753
Show file tree
Hide file tree
Showing 38 changed files with 2,541 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# IDE
.vscode
.idea
scripts/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

93 changes: 93 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
maggy
=====

Maggy is a framework for efficient asynchronous optimization of expensive
black-box functions. Compared to existing frameworks, maggy is not bound to
stage based optimization algorithms and therefore it is able to make extensive
use of early stopping in order to achieve efficient resource utilization.

Right now, maggy supports asynchronous hyperparameter tuning of machine
learning and deep learning models, but other use cases include ablation studies
and asynchronous distributed training.

Moreover, it provides a developer API that allows advanced usage by
implementing custom optimization algorithms and early stopping criteria.

In order to make decisions on early stopping, the Spark executors are sending
heart beats with the current performance of the model they are training to the
maggy experiment driver which is running on the Spark driver. We call the
process of training a model with a certain hyperparameter combination a
*trial*. The experiment driver then uses all information of finished trials and
the currently running ones to check in a specified interval, which of the
trials should be stopped early.
Subsequently, the experiment driver provides a new trial to the Spark
executor.

Quick Start
-----------

To Install:

>>> pip install maggy

The programming model is that you wrap the code containing the model training
inside a wrapper function. Inside that wrapper function provide all imports and
parts that make up your experiment.

There are three requirements for this wrapper function:

1. The function should take the hyperparameters as arguments, plus one
additional parameter reporter which is needed for reporting the current
metric to the experiment driver.
2. The function should return the metric that you want to optimize for. This
should coincide with the metric being reported in the Keras callback (see
next point).
3. In order to leverage on the early stopping capabilities of maggy, you need
to make use of the maggy reporter API. By including the reporter in your
training loop, you are telling maggy which metric to report back to the
experiment driver for optimization and to check for global stopping. It is
as easy as adding reporter.broadcast(metric=YOUR_METRIC) for example at the
end of your epoch or batch training step and adding a reporter argument to
your function signature. If you are not writing your own training loop you
can use the pre-written Keras callbacks in the `maggy.callbacks` module.

Sample usage:

>>> # Define Searchspace
>>> from maggy import Searchspace
>>> # The searchspace can be instantiated with parameters
>>> sp = Searchspace(kernel=('INTEGER', [2, 8]), pool=('INTEGER', [2, 8]))
>>> # Or additional parameters can be added one by one
>>> sp.add('dropout', ('DOUBLE', [0.01, 0.99]))

>>> # Define training wrapper function:
>>> def mnist(kernel, pool, dropout, reporter):
>>> # This is your training iteration loop
>>> for i in range(number_iterations):
>>> ...
>>> # add the maggy reporter to report the metric to be optimized
>>> reporter.broadcast(metric=accuracy)
>>> ...
>>> # Return the same final metric
>>> return accuracy

>>> # Launch maggy experiment
>>> from maggy import experiment
>>> result = experiment.launch(map_fun=mnist,
>>> searchspace=sp,
>>> optimizer='randomsearch',
>>> direction='max',
>>> num_trials=15,
>>> name='MNIST'
>>> )

MNIST Example
-------------

For a full MNIST example with random search using Keras,
see the Jupyter Notebook in `examples/`.

Documentation
-------------

API documentation is available here.
2 changes: 2 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Release 0.1
===========
19 changes: 19 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
180 changes: 180 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../'))
from maggy import version as maggy_version


# -- Project information -----------------------------------------------------

project = 'maggy'
copyright = '2019, Logical Clocks AB'
author = 'Logical Clocks AB'

# The short X.Y version
version = str(maggy_version.__version__)
# The full version, including alpha/beta/rc tags
release = str(maggy_version.__version__)


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'recommonmark'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ['.rst', '.md']

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'alabaster'
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'maggydoc'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'maggy.tex', 'maggy Documentation',
'Logical Clocks AB', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'maggy', 'maggy Documentation',
[author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'maggy', 'maggy Documentation',
author, 'maggy', 'One line description of project.',
'Miscellaneous'),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']


# -- Extension configuration -------------------------------------------------
2 changes: 2 additions & 0 deletions docs/developer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Maggy Developer API
===================
23 changes: 23 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. maggy documentation master file, created by
sphinx-quickstart on Tue Apr 16 12:13:32 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
.. include:: ../README.rst

.. toctree::
:maxdepth: 2
:caption: Contents:

User API <user>
Developer API <developer>
Release notes <release>
LICENSE <license>


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
6 changes: 6 additions & 0 deletions docs/license.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
License
-------

GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007.
See `LICENSE <https://github.com/logicalclocks/maggy/blob/master/LICENSE>`_.
1 change: 1 addition & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../RELEASE.rst
25 changes: 25 additions & 0 deletions docs/user.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Maggy User API
==============

maggy.experiment module
-----------------------

.. automodule:: maggy.experiment
:members:
:undoc-members:
:show-inheritance:

maggy.searchspace module
------------------------

.. autoclass:: maggy.Searchspace
:members:

maggy.callbacks module
------------------------

.. autoclass:: maggy.callbacks.KerasBatchEnd
:members:

.. autoclass:: maggy.callbacks.KerasEpochEnd
:members:

0 comments on commit 8144753

Please sign in to comment.