Skip to content

Ensure PT model is in evaluation mode and lightweight forward pass done#17970

Merged
amyeroberts merged 1 commit intohuggingface:mainfrom
amyeroberts:ensure-in-eval-mode
Jul 1, 2022
Merged

Ensure PT model is in evaluation mode and lightweight forward pass done#17970
amyeroberts merged 1 commit intohuggingface:mainfrom
amyeroberts:ensure-in-eval-mode

Conversation

@amyeroberts
Copy link
Contributor

Small update to the pt-to-tf CLI. Sets the pytorch model into evaluate model and uses no_grad context to make the memory requirements lighter.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

@amyeroberts amyeroberts requested review from gante and sgugger June 30, 2022 18:38
Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks!


# Load models and acquire a basic input compatible with the model.
pt_model = pt_class.from_pretrained(self._local_dir)
pt_model.eval()
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you don't get a model in eval mode with from_pretrained, then it's a bug.
(Not saying we shouldn't be safe, but this line shouldn't be necessary.)

Copy link
Contributor

@gante gante left a comment

Choose a reason for hiding this comment

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

TIL :D

(LGTM 👍 )

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 30, 2022

The documentation is not available anymore as the PR was closed or merged.

@amyeroberts amyeroberts merged commit 009171d into huggingface:main Jul 1, 2022
@amyeroberts amyeroberts deleted the ensure-in-eval-mode branch July 1, 2022 18:33
viclzhu pushed a commit to viclzhu/transformers that referenced this pull request Jul 18, 2022
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