Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
imenelydiaker wants to merge 2 commits into ServiceNow:main
base: main
Choose a base branch
Loading
from imenelydiaker:torch-lazy-import

Conversation

@imenelydiaker
Copy link
Collaborator

@imenelydiaker imenelydiaker commented Aug 13, 2025
edited by korbit-ai bot
Loading

torch is only used with VisualWebArena in the setup function. But it gets installed with browsergym when pip install browsergym.

Since the module is heavy and is only needed when using VisualWebArena, this PR makes torch an optional package to be installed when using VisualWebArena only.

Description by Korbit AI

What change is being made?

Implement lazy import for the torch library in the browsergym/visualwebarena component to prevent unnecessary installations and speed up initial loading.

Why are these changes being made?

The torch library is large and might not always be necessary for immediate execution of visualwebarena tasks unless specific functionalities are used, which makes lazy loading an optimal strategy to improve efficiency. This ensures that torch is only imported when explicitly required, reducing overhead for users who do not need torch in their current workflows. Additionally, the Makefile and requirements.txt were updated to accommodate this change.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Copy link

@korbit-ai korbit-ai bot left a comment
edited
Loading

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
Documentation Incomplete dependency error message ▹ view
Error Handling 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.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment on lines +15 to +18
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'."
)
Copy link

@korbit-ai korbit-ai bot Aug 13, 2025

Choose a reason for hiding this comment

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

Incomplete dependency error message category Documentation

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

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@recursix recursix Awaiting requested review from recursix

@amanjaiswal73892 amanjaiswal73892 Awaiting requested review from amanjaiswal73892

1 more reviewer

@korbit-ai korbit-ai[bot] korbit-ai[bot] left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /