-
Notifications
You must be signed in to change notification settings - Fork 25.9k
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
Fixing image segmentation with inference mode. #14204
Fixing image segmentation with inference mode. #14204
Conversation
Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
Fine with this solution, but a better one might actually to disable all those: if torch.isinf(hidden_states.clone()).any() or torch.isnan(hidden_states.clone()).any():
clamp_value = torch.finfo(hidden_states.dtype).max - 1000
hidden_states = torch.clamp(hidden_states, min=-clamp_value, max=clamp_value) for inference to make inference mode possible. Those "value" clamping checks are IMO only really useful to allow fp16 training (not so much for fp16 inference) and thus we could disable them with an @patil-suraj and I have somewhat unsuccesfully added lots of those statements to T5 in the hope of enabling fp16 training, which turned out to not work very well...with bfloat16 being available more for PyTorch those statements might not serve a good purpose anymore anyways. => So I would be fine with hiding them behind a Pinging @stas00 here as well to hear his opinion :-) |
Agreed with @patrickvonplaten it would be better if we could keep |
This fix is fine for a quick patch (patch release is going to be made in the next couple of hours), and we can make a better one afterward. So I would merge this now :-) |
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.
Thank you @Narsil!
* Fixing image segmentation for inference mode. * Update src/transformers/pipelines/base.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
* Fixing image segmentation for inference mode. * Update src/transformers/pipelines/base.py Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
What does this PR do?
It seems
detr
models are modifying tensors inplace, which is not allowedby
inference_mode
context manager, effectively breakingimage-segmentation
fortorch > 1.9
users.This PR proposes to override the context manager only in
image-segmentation
tono_grad
so the pipeline works again, without checking underlying model. Using a method to do the
switch.
Fixes # (issue)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@mishig25 @LysandreJik