Ray: [tune] Pass in other arguments to Trainable Function

Created on 21 Mar 2018  Â·  9Comments  Â·  Source: ray-project/ray

Describe the problem

I don't want to modify any of my code to use Tune; I just want to add a reporter parameter (and a tune configuration).

See source code for example.

Source code / logs

This is an example code that I want to change to Tune.

def run_training(args):
    # create model
    model = models.__dict__[args.arch](args.pretrained)
    model = torch.nn.DataParallel(model).cuda()

    best_prec1 = 0

    # optionally resume from a checkpoint
   ...

This has a particular format for setting up a lot of non-hyperparam information. It would take 20 or 30 lines of modifications to fit the current Tune specification. Ideally, I would only want to modify 2 or 3 lines (passing in reporter, calling the reporter, and modifying the hyperparameter)

Part to change here:
https://github.com/ray-project/ray/blob/5c7ef34b054de9ca28328333189ccc788a7d121f/python/ray/tune/function_runner.py#L60-L70

question

Most helpful comment

I guess the args were serializable, so they were captured as part of the
class definition. Passing options through config is probably more robust
though and lets you parametrize args per trial.

On Thu, Aug 16, 2018, 12:31 PM Hershel Mehta notifications@github.com
wrote:

I believe the question is how to pass in arguments to the Trainable class
(i.e., to _setup(self)). The approach I've been using is to add
parameters to config in my train_spec, which is passed to _setup(self)
and that works well. Interesting though, in an older approach, i simply
loaded in args using an argparser, and it seemed that _setup() was also
passed my dictionary of args somehow, and I was able to use that inside of
_setup().

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/ray-project/ray/issues/1762#issuecomment-413659258,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA6SuytQhJAOZSvokRdOr25fO3GIisfks5uRcivgaJpZM4S0w6n
.

All 9 comments

How is it possible to not change the code? You still need to report your results and parse the args right?

Modified above description to clarify. See this:
https://github.com/ucbdrive/skipnet/pull/3

Can't you define a new function

def train(config, reporter): run_training(args, config, reporter)

that wraps the original function call? args can be captured as a closure variable.

I think you could also pass a lambda function to register_trainable().

I guess that's reasonable, although I suspect this isn't the first solution that people would think of...

I guess we can close this for now and if anyone has a complaint later on we can open this again

Do you have a suggestion how I would to get around doing this with a custom Trainable class?
As I don't call the constructor explicitly, I don't see another option for passing parameters to it...

Hey @nadavbh12, sorry this slipped through the cracks. What are you trying to do?

I believe the question is how to pass in arguments to the Trainable class (i.e., to _setup(self)). The approach I've been using is to add parameters to config in my train_spec, which is passed to _setup(self) and that works well. Interesting though, in an older approach, i simply loaded in args using an argparser, and it seemed that _setup() was also passed my dictionary of args somehow, and I was able to use that inside of _setup().

I guess the args were serializable, so they were captured as part of the
class definition. Passing options through config is probably more robust
though and lets you parametrize args per trial.

On Thu, Aug 16, 2018, 12:31 PM Hershel Mehta notifications@github.com
wrote:

I believe the question is how to pass in arguments to the Trainable class
(i.e., to _setup(self)). The approach I've been using is to add
parameters to config in my train_spec, which is passed to _setup(self)
and that works well. Interesting though, in an older approach, i simply
loaded in args using an argparser, and it seemed that _setup() was also
passed my dictionary of args somehow, and I was able to use that inside of
_setup().

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/ray-project/ray/issues/1762#issuecomment-413659258,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAA6SuytQhJAOZSvokRdOr25fO3GIisfks5uRcivgaJpZM4S0w6n
.

Sorry for late response, eventually I realized I could just pass it through config, which was than rather straightforward.

Was this page helpful?
0 / 5 - 0 ratings