Giter Site home page Giter Site logo

banditsflow's Introduction

BanditsFlow: 🎰 A building workflow and tracking its information framework for bandits.

Lint and Test

BanditsFlow is a framework that supports the construction of a typical evaluation workflow for comparing bandit algorithms. Your experimental modules on this framework are automatically executed in the Metaflow workflow. In addition, the workflow incorporates experiment management with MLflow Tracking and hyperparameter optimization with Optuna. Combined with code management using Git, you will be able to manage your experiments with high reproducibility.

Usage

1. Generate scaffold and first run your experiment

$ YOUR_BANDIT_FLOW_NAME='sample'
$ python -m banditsflow scaffold $YOUR_BANDIT_FLOW_NAME
$ git add .
$ git commit -m 'Initial commit'
$ git tag first-experiment
$ make run
$ mlflow ui

And access to http://127.0.0.1:5000

2. Customize experiment

  1. Implement our scenario.
  2. Implement an actor who acts the scenario.
  3. Implement a reporter who reports result of actions of the actor.
  4. Prepare a parameter suggestion for each actor. (optional)

The scenario, actor and reporter must follow each protocol. See each protocol (scenario.Scenario, actor.Actor and reporter.Reporter).

Note that each module has a loader.Loader class which returns its instance by name.

β”œβ”€β”€ actor
β”‚Β Β  └── loader.py
β”œβ”€β”€ reporter
β”‚Β Β  └── loader.py
β”œβ”€β”€ scenario
β”‚Β Β  └── loader.py
└── suggestion
    β”œβ”€β”€ ACTOR_NAME.yml
    └── loader.py

3. Update experiment and run

$ git add .
$ git commit -m 'Customize modules'
$ git tag second-experiment
$ make run
$ mlflow ui

Repeat 2 and 3.

Workflow

BanditsFlow provides the following workflow. The workflow has optimize and evaluate and report steps. The each step result are saved by Metaflow and MLflow Tracking.

                                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                   β”‚  start  β”‚
                                   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                     (actor-1)      (actor-2)      (actor-3)
 {suggestion}       β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
 {scenario  } ─────►│optimize β”‚    β”‚optimize β”‚    β”‚optimize β”œβ”€β”€β”€β–Ί <best_params>
 {actor     }       β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                    best_params    best_params    best_params
                    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
 {scenario  } ─────►│evaluate β”‚    β”‚evaluate β”‚    β”‚evaluate β”œβ”€β”¬β”€β–Ί <result>
 {actor     }       β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β”‚
                         β”‚              β”‚              β”‚      β”œβ”€β–Ί [Parameter]
                      result         result         result    └─► [Metric]
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
                                   β”‚  join   β”‚
                                   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                                     results
                                   β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
 {reporter  } ────────────────────►│ report  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί [Artifact]
                                   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
                                   β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
                                   β”‚   end   β”‚
                                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

{}: Module
[]: MLflow Tracking
<>: Metaflow

Data location and relation

                              Metaflow                     MLflow Tracking

                     β”Œβ”€Flow(BanditsFlow)───────┐     β”Œβ”€Experiments─────────────┐
                     β”‚                         β”‚     β”‚                         β”‚
    RAW DATA         β”‚                         β”‚     β”‚ β”Œβ”€exp-1───────────────┐ β”‚       REPORT DATA
                     β”‚   β”Œβ”€Run─────────────┐   β”‚     β”‚ β”‚ β”Œβ”€Run (actor-1)───┐ β”‚ β”‚
<best_params> ◄─┬───────── ID:   mt-run-1  β”œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β–Ίβ”‚ ID:   ml-run-A  β”œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β–Ί [Parameter]
Each <result> ◄──    β”‚   β”‚ Tag:  exp-1     β”‚   β”‚  β”‚  β”‚ β”‚ β”‚ Name: mt-run-1  β”‚ β”‚ β”‚   └─► [Metric]
    <results> β—„β”€β”˜    β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚  β”‚  β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
                     β”‚                         β”‚  β”‚  β”‚ β”‚ β”Œβ”€Run (actor-2)───┐ β”‚ β”‚
                     β”‚                         β”‚  β”œβ”€β”€β”€β”€β”€β–Ίβ”‚ ID:   ml-run-B  β”œβ”€β”€β”€β”€β”€β”€β”€β”¬β”€β–Ί [Parameter]
                     β”‚                         β”‚  β”‚  β”‚ β”‚ β”‚ Name: mt-run-1  β”‚ β”‚ β”‚   └─► [Metric]
                     β”‚                         β”‚  β”‚  β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
                     β”‚                         β”‚  β”‚  β”‚ β”‚ β”Œβ”€Run (reporter)──┐ β”‚ β”‚
                     β”‚                         β”‚  └─────►│ ID:   ml-run-C  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί [Artifact]
                     β”‚                         β”‚     β”‚ β”‚ β”‚ Name: mt-run-1  β”‚ β”‚ β”‚
                     β”‚                         β”‚     β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
                     β”‚                         β”‚     β”‚ β”‚                     β”‚ β”‚
                     β”‚                         β”‚     β”‚ β”‚  -----------------  β”‚ β”‚
                     β”‚                         β”‚     β”‚ β”‚                     β”‚ β”‚
                     β”‚   β”Œβ”€Run─────────────┐   β”‚     β”‚ β”‚ β”Œβ”€Run (actor-1)───┐ β”‚ β”‚
                     β”‚   β”‚ ID:   mt-run-2  β”œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β–Ίβ”‚ ID:   ml-run-D  β”‚ β”‚ β”‚
                     β”‚   β”‚ Tag:  exp-1     β”‚   β”‚  β”‚  β”‚ β”‚ β”‚ Name: mt-run-2  β”‚ β”‚ β”‚
                     β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚  β”‚  β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
                     β”‚                         β”‚  β”‚  β”‚ β”‚ β”Œβ”€Run (actor-2)───┐ β”‚ β”‚
                     β”‚                         β”‚  β”œβ”€β”€β”€β”€β”€β–Ίβ”‚ ID:   ml-run-E  β”‚ β”‚ β”‚
                     β”‚                         β”‚  β”‚  β”‚ β”‚ β”‚ Name: mt-run-2  β”‚ β”‚ β”‚
                     β”‚                         β”‚  β”‚  β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
                     β”‚                         β”‚  β”‚  β”‚ β”‚ β”Œβ”€Run (reporter)──┐ β”‚ β”‚
                     β”‚                         β”‚  └─────►│ ID:   ml-run-F  β”‚ β”‚ β”‚
                     β”‚                         β”‚     β”‚ β”‚ β”‚ Name: mt-run-2  β”‚ β”‚ β”‚
                     β”‚                         β”‚     β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
                     β”‚                         β”‚     β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
                     β”‚                         β”‚     β”‚                         β”‚
                     β”‚                         β”‚     β”‚ β”Œβ”€exp-2───────────────┐ β”‚
                     β”‚   β”Œβ”€Run─────────────┐   β”‚     β”‚ β”‚ ...                 β”‚ β”‚
                     β”‚   β”‚ ID:   mt-run-3  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ί...                 β”‚ β”‚
                     β”‚   β”‚ Tag:  exp-2     β”‚   β”‚     β”‚ β”‚ ...                 β”‚ β”‚
                     β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚     β”‚ β”‚ ...                 β”‚ β”‚
                     β”‚                         β”‚     β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Cache

BanditsFlow stores metrics, results and reports for every run. BanditsFlow assumes that the results are the same for the same experiment, and reduces the time needed to re-run the experiment by using previous results. These caches are searched using the experiment name, scenario name, and actor name as keys. You can re-run the experiment by specifying the --revival_from_optimization_by or --revival_from_evaluation_by option or changing the name of the experiment by setting another git tag.

Optimization

BanditsFlow uses Optuna for optimization. Your suggestion loader class returns parameter suggestions for its actor. If you use the loader made by scaffold, each actor receives its suggestion which is prepared in suggestion module as YAML of its name. The YAML has suggestions dictionary which has list of parameter suggestion dictionary. Each parameter suggestion has name, type and parameter for each type.

An example of categorical parameter is the following:

suggestions:
  - name: epsilon
    type: discrete_uniform
    low: 0.1
    high: 1.0
    q: 0.1

See Optuna document for other type and parameter for each type.

Installation

$ pip install git+https://github.com/monochromegane/banditsflow

License

MIT

Author

monochromegane

banditsflow's People

Contributors

monochromegane avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.