Skip to content

Conversation

imenelydiaker
Copy link
Collaborator

@imenelydiaker imenelydiaker commented Aug 13, 2025

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

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

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant