-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(detectors): skip HF detectors when models are unreachable #2138
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
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.
In this case failure to load the model requested should continue to fail the run early before spending token budgets on inference that will not match what the user requested via explicit configuration parameters. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from garak.langproviders.local import LocalHFTranslator | ||
|
|
||
|
|
||
| def test_local_hf_translator_falls_back_to_passthru_when_model_unavailable(monkeypatch): | ||
| def _raise_network_error(*args, **kwargs): | ||
| raise OSError("Network is unreachable") | ||
|
|
||
| monkeypatch.setattr( | ||
| "transformers.MarianMTModel.from_pretrained", | ||
| _raise_network_error, | ||
| ) | ||
|
|
||
| translator = LocalHFTranslator( | ||
| config_root={ | ||
| "langproviders": { | ||
| "local": { | ||
| "language": "de,en", | ||
| "model_type": "local", | ||
| "model_name": "Helsinki-NLP/opus-mt-{}", | ||
| } | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| assert translator._offline_passthru is True | ||
| assert translator._translate("hallo welt") == "hallo welt" |
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.
This seems reasonable, since detectors are often lazy loaded terminating the run is not the preferred action, however I question if this is actually needed,
probewise.pyguards for detectors that fail to init as doespxd.pywhich loads all explicitly called detectors before starting inference.