Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Trainer without argparse #105

Merged
merged 5 commits into from Sep 1, 2020

Conversation

ymd-h
Copy link
Contributor

@ymd-h ymd-h commented Aug 30, 2020

This PR is related with #104

This PR enables Trainer to accept dict-type args at constructor.

User can pass parameters like followings;

trainer = Trainer(policy,env,{"max_steps": 1000},test_env=test_env)

This PR preserves backward compatibility, so that user still can pass argparse.Namespace (result of parse_args()).

args = policy.__class__.get_argument(Trainer.get_argument())
args = args.parse_args([])
for k, v in _args.items():
setattr(args, k, v)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this part overrides the arguments by specified dictionary.
Would it be possible to reject elements that are not defined in the args = policy.__class__.get_argument(Trainer.get_argument())?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as argparse guarantees that there exist all the possible parameters including parameters not specified by command line, we can check with hasattr(args, k).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keiohta

I added a commit (a343fff) which makes Trainer raise ValueError against unsupported arguments.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

batch_size=32,
n_warmup=10)
trainer = Trainer(policy, env, {}, test_env=test_env)
print(trainer)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you printing trainer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid linter error

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you tell me why this avoids linter error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/ymd-h/tf2rl/runs/1047622916?check_suite_focus=true

F841 local variable 'trainer' is assigned to but never used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there are more better solutions, but checking whether parameters are default is also problematic.
These parameters can change their default values in future, which will break unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I found a solution.

I simply do not assign to local value. (12cfa48)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@keiohta keiohta merged commit 453ef59 into keiohta:master Sep 1, 2020
@ymd-h ymd-h deleted the Feature_Train_without_argparse branch September 1, 2020 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants