-
Notifications
You must be signed in to change notification settings - Fork 31.3k
Avoid some pipeline tasks to use use_cache=True
#24893
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import inspect | ||
| from typing import List, Union | ||
|
|
||
| import numpy as np | ||
|
|
@@ -221,6 +222,10 @@ def _forward(self, inputs): | |
| candidate_label = inputs["candidate_label"] | ||
| sequence = inputs["sequence"] | ||
| model_inputs = {k: inputs[k] for k in self.tokenizer.model_input_names} | ||
| # `XXXForSequenceClassification` models should not use `use_cache=True` even if it's supported | ||
| model_forward = self.model.forward if self.framework == "pt" else self.model.call | ||
| if "use_cache" in inspect.signature(model_forward).parameters.keys(): | ||
| model_inputs["use_cache"] = False | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far only in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, there is no backward compatibility issue here:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never a fan of inspecting the signature, but 16% perf improvement is worth it ! |
||
| outputs = self.model(**model_inputs) | ||
|
|
||
| model_outputs = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
self.frameworkhere instead of checking for attributes? Something likeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure!