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

feat(tuner): allow adjustment of optimizer #128

Merged
merged 12 commits into from
Oct 15, 2021
Merged

Conversation

tadejsv
Copy link
Contributor

@tadejsv tadejsv commented Oct 14, 2021

Adds 3 different optimizers

  • Adam (new default)
  • SGD (with momentum)
  • RMSprop (as before)

they are customizable (I had to find intersection of options allowed under all 3 frameworks).

Missing docstrings/documentation, but let's add that once we have everything (currently there are no docstrings in place, this PR does not feel like the right place to add them)


Also, you can now adjust learning rate. The new deafult is now 1e-3, a magintude lowe, as @maximilianwerk observed problems with high learning rate (and in general in applications the lr is low, even lower than new default)

@tadejsv tadejsv linked an issue Oct 14, 2021 that may be closed by this pull request
Copy link
Member

@bwanglzu bwanglzu left a comment

Choose a reason for hiding this comment

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

i personally think stopping at optimizer level is sufficiently enough, how do you think? I mean even when I'm using pytorch training model by myself, i almost never change parameters such as beta1, beta2, nesterov etc., let alone using finetuner

@tadejsv
Copy link
Contributor Author

tadejsv commented Oct 14, 2021

i personally think stopping at optimizer level is sufficiently enough, how do you think? I mean even when I'm using pytorch training model by myself, i almost never change parameters such as beta1, beta2, nesterov etc., let alone using finetuner

Yes I agree. However, as you can see, the 3 frameworks sometimes actually have different default values. And I guess it is in our interest to ensure that training is the same for all 3 frameworks. As this already involves creating some default params, we might as well make them available to the users, if they wants to use them.

Copy link
Member

@bwanglzu bwanglzu left a comment

Choose a reason for hiding this comment

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

understand, if we decided to keep the optimizer_kwargs then let's keep it.

)
elif optimizer == 'sgd':
return keras.optimizers.SGD(learning_rate=learning_rate, **optimizer_kwargs)

Copy link
Member

Choose a reason for hiding this comment

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

raise an value error when optimizer name is not recognised

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already done in _get_optimizer_kwargs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason for this is that I try to factor out as much code as possible to the base class, so that it is not repeated in each framework

@@ -39,6 +44,32 @@ def _get_data_loader(self, inputs, batch_size: int, shuffle: bool):
shuffle=shuffle,
)

def _get_optimizer(
Copy link
Member

Choose a reason for hiding this comment

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

personally i'm not a big fan of get_something, in Java or other OOP world, it feels like a getter or setter, if it is a getter, then in Python I would turn it into a property, otherwise I'll rename it how do you think?

Copy link
Contributor Author

@tadejsv tadejsv Oct 15, 2021

Choose a reason for hiding this comment

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

It's a factory function, not a getter or setter. And we already have this in the current base class (see _get_data_loader), so I would stick with this convention for now. You can raise a separate PR to change this if you want

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tests/unit/tuner/keras/test_optimizer.py Show resolved Hide resolved
@tadejsv tadejsv changed the title feat: allow adjustment of optimizer feat(tuner): allow adjustment of optimizer Oct 15, 2021
Copy link
Member

@bwanglzu bwanglzu left a comment

Choose a reason for hiding this comment

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

LGTM!

@tadejsv tadejsv merged commit b624a62 into main Oct 15, 2021
@tadejsv tadejsv deleted the feat-configure-optimizer branch October 15, 2021 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow modifying optimizer parameters
3 participants