-
Notifications
You must be signed in to change notification settings - Fork 139
Lazy import for torch #364
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?
Conversation
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.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Incomplete dependency error message ▹ view | ||
| Unhandled lazy import error ▹ view | ✅ Fix detected |
Files scanned
| File Path | Reviewed |
|---|---|
| browsergym/visualwebarena/src/browsergym/visualwebarena/init.py | ✅ |
| browsergym/visualwebarena/src/browsergym/visualwebarena/task.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
| if importlib.util.find_spec("torch") is None: | ||
| raise ImportError( | ||
| "The 'torch' package is required for VisualWebArena tasks evaluation. Please install it with 'pip install torch'." | ||
| ) |
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.
Incomplete dependency error message 
Tell me more
What is the issue?
The error message states that torch is required but doesn't explain why it's needed for evaluation.
Why this matters
Users encountering this error won't understand which functionality depends on torch, making it harder to decide if they really need it.
Suggested change ∙ Feature Preview
if importlib.util.find_spec("torch") is None:
raise ImportError(
"The 'torch' package is required for VisualWebArena tasks evaluation (used for neural embedding comparisons). Please install it with 'pip install torch'."
)
Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| # Lazy import | ||
| import importlib | ||
|
|
||
| torch = importlib.import_module("torch") |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
torchis only used with VisualWebArena in the setup function. But it gets installed with browsergym whenpip install browsergym.Since the module is heavy and is only needed when using VisualWebArena, this PR makes
torchan optional package to be installed when using VisualWebArena only.Description by Korbit AI
What change is being made?
Implement lazy import for the
torchlibrary in thebrowsergym/visualwebarenacomponent to prevent unnecessary installations and speed up initial loading.Why are these changes being made?
The
torchlibrary is large and might not always be necessary for immediate execution ofvisualwebarenatasks unless specific functionalities are used, which makes lazy loading an optimal strategy to improve efficiency. This ensures thattorchis only imported when explicitly required, reducing overhead for users who do not needtorchin their current workflows. Additionally, the Makefile and requirements.txt were updated to accommodate this change.