-
Notifications
You must be signed in to change notification settings - Fork 450
feature: deferred loading and requirement pruning #1199
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
Draft
leondz
wants to merge
39
commits into
NVIDIA:main
Choose a base branch
from
leondz:update/optional_imports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
3000d4c
draft postponed import pattern for cohere generator
leondz 757e0f3
move extra dependency requirements into classdefs, mediate requiremen…
leondz 9310d0a
actually do the plugin dep load
leondz dac569e
migrate generators to 'extra dependencies' pattern
leondz 35e93fc
prune dupe lazyload
leondz bf7f36b
extra_dependency_names in all plugins
leondz 6a39b0c
active must be False for Probes using extra modules
leondz 56c6182
make PIL optional in generators.huggingface.LLaVA
leondz 3657e04
move optional load fail to ModuleNotFoundError
leondz 865d604
add _load/_clear_deps() into base generator and _load/_clear client
leondz d61957d
put the MNFE where it belongs
leondz 8a7051e
backoff exception placeholder must inherit base exception
leondz 60775f6
test for reqs presence in pyproject.toml, requirements.txt
leondz 31e98d4
handle hyphen in pypi pkg names
leondz 75babb7
rm optional plugin deps
leondz 83f551a
skip generator tests if optional deps absent
leondz dd51196
support sub-package deps
leondz b33a46c
scope optimum to nvidia
leondz de5b3f1
move import function to _load_deps
leondz 19c31fe
rm import handling in langchain
leondz 54fabc5
amend optimum to be nvidia flavour
leondz ffac714
dry - use garak._plugins.PLUGIN_TYPES as canonical def of 1st class p…
leondz 97c8160
unify backoff exception pattern mediated via garak GeneratorBackoffEx…
leondz 1d4e69c
skip instantiation when modules not present
leondz 6164bc5
catch straggling backoff exception wrappings
leondz 85fb7c3
Merge branch 'main' into update/optional_imports
leondz 0402116
use isinstance for exception matching
leondz e287fe9
don't backoff on 404
leondz 6339648
merge in our good pal main
leondz 76b1774
switch to pyproject; get tests deps if testing
leondz ca133e4
add [dev] target
leondz 8e8a5b9
add required jsonschema that was previously implicit from now-optiona…
leondz aa7500a
specify versions; move to secure versions cf. #1207
leondz 4f2e5ef
skip internal config mappings for req consistency testing
leondz 69cfef2
skip test option for non-test workflow
leondz a1da5ed
skip ollama tests if no module
leondz 3a8605d
rm spurious dep check
leondz d2d17ad
straggling spurious check
leondz 13974b8
Merge branch 'main' into update/optional_imports
leondz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,8 @@ class Generator(Configurable): | |
supports_multiple_generations = ( | ||
False # can more than one generation be extracted per request? | ||
) | ||
# list of strings naming modules required but not explicitly in garak by default | ||
extra_dependency_names = [] | ||
|
||
def __init__(self, name="", config_root=_config): | ||
self._load_config(config_root) | ||
|
@@ -63,6 +65,29 @@ def __init__(self, name="", config_root=_config): | |
f"🦜 loading {Style.BRIGHT}{Fore.LIGHTMAGENTA_EX}generator{Style.RESET_ALL}: {self.generator_family_name}: {self.name}" | ||
) | ||
logging.info("generator init: %s", self) | ||
self._load_deps() | ||
|
||
def _load_deps(self): | ||
# load external dependencies. should be invoked at construction and | ||
# in _client_load (if used) | ||
for extra_dependency in self.extra_dependency_names: | ||
extra_dep_name = extra_dependency.replace(".", "_").replace("-", "_") | ||
if ( | ||
not hasattr(self, extra_dep_name) | ||
or getattr(self, extra_dep_name) is None | ||
): | ||
setattr( | ||
self, | ||
extra_dep_name, | ||
garak._plugins.load_optional_module(extra_dependency), | ||
) | ||
|
||
def _clear_deps(self): | ||
# unload external dependencies from class. should be invoked before | ||
# serialisation, esp. in _clear_client (if used) | ||
for extra_dependency in self.extra_dependency_names: | ||
extra_dep_name = extra_dependency.replace(".", "_") | ||
setattr(self, extra_dep_name, None) | ||
Comment on lines
+70
to
+90
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. Should this be in |
||
|
||
def _call_model( | ||
self, prompt: str, generations_this_call: int = 1 | ||
|
@@ -101,7 +126,7 @@ def _prune_skip_sequences(self, outputs: List[str | None]) -> List[str | None]: | |
) | ||
rx_missing_final = re.escape(self.skip_seq_start) + ".*?$" | ||
rx_missing_start = ".*?" + re.escape(self.skip_seq_end) | ||
|
||
if self.skip_seq_start == "": | ||
complete_seqs_removed = [ | ||
( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this really the best way to do this? Perhaps we just enforce lazy loading throughout instead? I'm not sure.
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.
Oh, I guess that is what we're doing. This is the hazard of doing code reviews linearly, I suppose.