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

Change functional surgery method return values to None #1543

Merged
merged 33 commits into from
Feb 6, 2023

Conversation

nik-mosaic
Copy link
Contributor

@nik-mosaic nik-mosaic commented Sep 20, 2022

Closes https://mosaicml.atlassian.net/browse/CO-988 and #1441 .
For consistency sake, and to ensure that the user knows the model is being mutated, all applicable functional model surgery methods return None, rather than some returning the model object and some returning None.

@nik-mosaic nik-mosaic marked this pull request as ready for review September 20, 2022 09:14
@nik-mosaic nik-mosaic requested review from dskhudia and a team as code owners September 20, 2022 09:14
@nik-mosaic nik-mosaic changed the title Set all functional surgery method return values to None Set functional surgery methods return values to None Sep 20, 2022
@nik-mosaic nik-mosaic changed the title Set functional surgery methods return values to None Set all functional surgery method return values to None Sep 20, 2022
@mvpatel2000
Copy link
Contributor

Can we instead return how many layers are changed? Would be very useful for agent bc then it can skip surgeries if they are no-ops

@nik-mosaic
Copy link
Contributor Author

nik-mosaic commented Sep 20, 2022

This is an option. However, there are lots of algorithms which aren't surgery based, for which there is no clear number to return. e.g.: compute_ema. One priority should be consistency for users using the functional interface. Returning non-none will reduce this.

We currently raise NoEffectWarnings for no-op model surgery algorithms; the agent could catch those warnings.

@hanlint
Copy link
Contributor

hanlint commented Sep 20, 2022

Agreed with @nik-mosaic , having the methods return an int would lead to odd bugs when users try:

model = apply_x(model)

whereas None would clearly indicate that this is an in-place operation.

@dskhudia
Copy link
Contributor

IMO it's ok to return "something" for apply methods if it makes sense (e.g., number of layers replaced as @mvpatel2000 suggested) but not model if apply method is modifying the model inplace. Any user of apply_* method will look at least look at the API to see what it does and will be able to see return type/value. Therefore, consistency across the board for the apply APIs is, I think, too restrictive.

@mvpatel2000
Copy link
Contributor

Agreed with @nik-mosaic , having the methods return an int would lead to odd bugs when users try:

model = apply_x(model)

whereas None would clearly indicate that this is an in-place operation.

I think returning an int would pretty clearly indicate what's going on here, and the docs can be clear this is in-place. It's a lot cleaner to just measure how many layers are changed vs. trying to catch warnings and interpret them.

Basically +1 to Daya's points

@nik-mosaic
Copy link
Contributor Author

Per offline discussion, functional model surgery methods will return # of modified layers where applicable and None elsewhere.

@nik-mosaic nik-mosaic marked this pull request as draft September 22, 2022 00:01
@nik-mosaic nik-mosaic marked this pull request as ready for review October 4, 2022 17:40
@nik-mosaic nik-mosaic changed the title Set all functional surgery method return values to None Change functional surgery method return values Oct 4, 2022
@nik-mosaic nik-mosaic changed the title Change functional surgery method return values Change functional surgery method return values to Layers Modified Oct 4, 2022
Copy link
Contributor

@dskhudia dskhudia left a comment

Choose a reason for hiding this comment

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

This may break code that uses functional version of algorithms and uses return values. I think that's ok though.

Copy link
Contributor

@hanlint hanlint left a comment

Choose a reason for hiding this comment

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

LGTM, one request:

Add a note here (https://docs.mosaicml.com/en/v0.10.1/trainer/algorithms.html#model-surgery) explaining that all surgery methods return the number of instances replaced.

Also, do we need to add a test to enforce this API?

@nik-mosaic nik-mosaic marked this pull request as draft October 18, 2022 21:17
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@hanlint
Copy link
Contributor

hanlint commented Jan 27, 2023

@nik-mosaic do we close this PR?

@nik-mosaic nik-mosaic changed the title Change functional surgery method return values to Layers Modified Change functional surgery method return values to None Jan 30, 2023
@nik-mosaic nik-mosaic marked this pull request as ready for review January 30, 2023 21:47
@nik-mosaic
Copy link
Contributor Author

@nik-mosaic do we close this PR?

In a December design discussion, we backtracked on our decision to return the number of layers modified. We decided that for user-friendliness, functional algorithms should return None instead. This PR is now ready to merge.

Copy link
Contributor

@mvpatel2000 mvpatel2000 left a comment

Choose a reason for hiding this comment

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

Should go out on 13. Holding off for now since we're going to cut a 12.1 off dev

Copy link
Contributor

@mvpatel2000 mvpatel2000 left a comment

Choose a reason for hiding this comment

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

Good to merge

@nik-mosaic nik-mosaic merged commit c191b37 into mosaicml:dev Feb 6, 2023
@nik-mosaic nik-mosaic deleted the nikhil/consistent-surgery branch February 6, 2023 23:30
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.

4 participants