Skip to content

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
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

leondz
Copy link
Collaborator

@leondz leondz commented May 7, 2025

Support construction-time loading of optional modules. Includes

  • many generators now using this pattern
  • pattern for loading modules at run-time and failing if absent
  • optional requirements moved to pyproject.toml options and pruned from requirements.txt
  • _load_deps and _clear_deps pattern, used in generator constructor and _load_client / _clear_client
  • tests to check that optional deps are in the right place and not in the wrong place

Todo / in scope:

  • skipping tests requiring absent optional imports
  • take a stance on whether to skip or stop on missing module, per plugin type (likely skip for probe, stop for main generator, beyond that tba)
  • Consider moving load/clear dep function defs up and out for all classes (where - garak._plugins? How - assign func member? create mixin?)
  • validation: exception throws correctly / doesn't throw if dependency present
    • cohere
    • langchain
    • litellm
    • mistral
    • nemoguardrails
    • nemollm
    • octo
    • ollama
    • optimum (huggingface.OptimumPipeline) - exception fires, pkg install seems borked
    • replicate

Not done:

  • load/clear deps for plugin types other than generators
  • gh actions for testing optional components
  • deeper validation

Out of scope:

  • handling of versioning outside of pyproject.toml

Resolves #101

@leondz leondz requested a review from jmartin-tech May 7, 2025 11:00
@leondz leondz added the architecture Architectural upgrades label May 7, 2025
@leondz leondz requested review from jmartin-tech and removed request for jmartin-tech May 7, 2025 11:04
@leondz leondz added this to the 0.11.0 milestone May 8, 2025
@leondz leondz self-assigned this May 8, 2025
@leondz leondz removed this from the release 0.11.0 milestone May 8, 2025
]
plugin_replicate = [
"replicate>=0.8.3",
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding to allows for pip install garak[plugin_all]:

plugin_all = garak[
    plugin_cohere,
    plugin_langchain,
    plugin_llava,
    plugin_litellm,
    plugin_mistralai,
    plugin_nemoguardrails,
    plugin_nemollm,
    plugin_octoai,
    plugin_ollama,
    plugin_replicate,
]

There might be a better name to use for this group.

@leondz leondz requested a review from erickgalinkin as a code owner May 16, 2025 11:01
@leondz leondz marked this pull request as draft May 16, 2025 12:14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep requirements.txt as a consolidated lists of all possible requirements and require usage of pyproject.toml to get a limited dependencies install?

Another option to me would be simply remove requirements.txt and require all installs be based on using pyproject.toml until we implement a lock file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. After migrating the gh workflows to use pyproject.toml, requirements.txt becomes superfluous - I'm leaning toward the latter.

Removal does mean we lose a cross check in test_reqs, but that's OK. Could do with a test to ensure all packages (including optional) specity a version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture Architectural upgrades
Projects
None yet
Development

Successfully merging this pull request may close these issues.

improved / consistent plugin lazy loading
2 participants