-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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 offline mode for pipeline (when inferring task). #21113
Conversation
The documentation is not available anymore as the PR was closed or merged. |
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.
Thanks for the fix!
Since I'm looking at the test as a result, I have comments not directly linked to your changes but that should be addressed (in another PR if you prefer).
The weird things is that:
- mocking
socket
tests an internet connection failing, this is independent from TRANFORMERS_OFFLINE and will work if the model is cached (see comment intest_offline_mode
). - adding TRANSFORMERS_OFFLINE tells the library to not connect online. This can be used even if there is internet. This should never call any request so there is no need to mock anything (of mock to check that there was indeed no call).
So the current test_offline_mode
should be split in two, with one test just doing TRANSFORMERS_OFFLINE=1 and somehow testing there are no calls to the Hub, and a second test test_cached_is_used_when_offline
where we do the mock but don't touch TRANSFORMERS_OFFLINE. The test you're adding should be like test_offline_mode
and not mock anything (unless it's to check there are no calls to the internet).
Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
For the added test this is indeed the only thing proving it fails when the code doesn't check the offline mode. For the other tests if I understand correctly it's If internet is not available, regardless of That's ok for the If that's correct, then I'm ok with splitting the tests, but the mock should still probably be in both tests, 1 to fake a buggy internet, the other to make sure we trigger an failure when we actually use internet even after been explicitly asked not to do it, no ? (We could change the mock errors strings to reflect that difference) |
Agreed! And yes the pipeline task for those tests needs to be passed, it can't be retrieved in offline mode/internet fails. |
Made the changes is that what you had in mind ? |
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.
Yes, that's perfect. Thanks a lot!
tests/utils/test_offline.py
Outdated
# this test is a bit tricky since TRANSFORMERS_OFFLINE can only be changed before | ||
# `transformers` is loaded, and it's too late for inside pytest - so we are changing it | ||
# while running an external program |
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.
Note that we don't need this comment anymore since we are not touching the env variable.
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.
Done.
…21113) * Fixing offline mode for pipeline (when inferring task). * Update src/transformers/pipelines/__init__.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Updating test to reflect change in exception. * Fixing offline mode. * Clean. Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
…21113) * Fixing offline mode for pipeline (when inferring task). * Update src/transformers/pipelines/__init__.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Updating test to reflect change in exception. * Fixing offline mode. * Clean. Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com>
What does this PR do?
Was actually using network even when
TRANSFORMERS_OFFLINE=1
was used.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.