Code Monkey home page Code Monkey logo

argload's Introduction

Argload, easy reloading of command line arguments

Argload is a python package facilitating the reloading of command line arguments.

As an example is worth a thousand words, let's explain the use cases of argload with an example bit of code.

Say you have a bunch of experiments to run depending on two hyperparameters, a and b. You define your parser with argparse as follow:

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--a', type=float, default=1e-3)
parser.add_argument('--b', type=float, default=2.)
args = parser.parse_args()

Now say you have 2 very long experiments to run, one with a=1e-3, b=3, and the other one with a=1e-4, b=1. If both experiments were very short, everything would be fine, you would launch each of them independantly, and even if they crash, simply restarting them using your bash history is both simple and fast.

But if they are very long, there is a non negligible chance for your command line not to be in your bash history anymore, or for you to have forgotten your exact hyperparameters (OK, two is easy, 32 less so, 32 hyperparameters on 54 experiments even less so...).

That's where argload can come in handy. Now simply wrap your parser in an ArgumentLoader instance in the following way:

import argparse
import argload

parser = argparse.ArgumentParser()
parser.add_argument('--a', type=float, default=1e-3)
parser.add_argument('--b', type=float, default=2.)
parser = argload.ArgumentLoader(parser, to_reload=['a', 'b'])
args = parser.parse_args()

Your script takes one additional required argument logdir, the directory where your current argument will be stored (and typically the directory where all your results will be stored), and two optional flags overwrite and dump. Say you want to store the results of your first experiment in the exp1. After creating this directory, the first time you run your script, with the logdir argument properly set,

python script.py --logdir exp1 --a 1e-3 --b 3

argload stores your arguments in the exp1 directory. Now, the next time you run your script in exp1,

python script.py --logdir exp1

your hyperparameters will be automatically loaded.

I you specify the overwrite flag, you can overwrite previous values of your hyperparameters. For instance, running

python script.py --logdir exp1 --overwrite --a 1e-2

will relaunch script.py with arguments a=1e-2, b=3. However, the new value for a will not be stored in your directory, if you relaunch

python script.py --logdir exp1

the values you will be using are still a=1e-3, b=3.

If you want to store your new setting inside of your experiment directory, issue the command

python script.py --logdir exp1 --overwrite --dump --a 1e-2

The next time you will launch your script in exp1, the values used will be a=1e-2, b=3.

argload's People

Contributors

ctallec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cjsg afcarl

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.