Skip to content

feat: better build_wheel.py venv handling #4525

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

Conversation

tongyuantongyu
Copy link
Member

Some user experience improvements for build_wheel.py related to virtual environment handling

  • Recognize manually created environments and skip creating another virtual environment.
  • Detect common PyTorch environment issue and warn user.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the virtual environment handling in build_wheel.py by recognizing pre‐existing environments and warning users about potential PyTorch conflicts.

  • Introduces a new function create_venv for creating venvs.
  • Adds a no-venv option to use the current Python environment as is.
  • Updates venv path resolution and incorporates a check/warning for NVIDIA PyTorch issues.
Comments suppressed due to low confidence (1)

scripts/build_wheel.py:76

  • [nitpick] The change from using a variable name like venv_dir to venv_prefix could reduce clarity. Consider using a consistent and self-explanatory name (e.g., venv_dir) throughout the code.
venv_prefix = project_dir / f".venv-{py_major}.{py_minor}"

@tongyuantongyu
Copy link
Member Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #5980 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #5980 [ run ] completed with state FAILURE
/LLM/main/L0_MergeRequest_PR pipeline #4372 completed with status: 'FAILURE'

@tongyuantongyu tongyuantongyu force-pushed the ytong/build_wheel_venv branch from 8da545e to 976417b Compare May 21, 2025 08:28
@tongyuantongyu
Copy link
Member Author

/bot run

@tongyuantongyu tongyuantongyu force-pushed the ytong/build_wheel_venv branch from 976417b to 46f99cb Compare May 21, 2025 08:33
@tensorrt-cicd
Copy link
Collaborator

PR_Github #5987 [ run ] triggered by Bot

Signed-off-by: Yuan Tong <13075180+tongyuantongyu@users.noreply.github.com>
@tongyuantongyu tongyuantongyu force-pushed the ytong/build_wheel_venv branch from 46f99cb to b1ad203 Compare May 21, 2025 08:33
@tongyuantongyu
Copy link
Member Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #5989 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #5987 [ run ] completed with state ABORTED

@tensorrt-cicd
Copy link
Collaborator

PR_Github #5989 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #4377 completed with status: 'FAILURE'

if os.environ.get(
"NVIDIA_PYTORCH_VERSION") is not None and has_non_system_pytorch:
warnings.warn(
"You are using the NVIDIA PyTorch container, but not using the provided PyTorch installation. "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Refined by Owen:

Using the NVIDIA PyTorch container without leveraging the included PyTorch installation may lead to compatibility issues.

If you encounter any problems, please delete the environment at `{venv_prefix}` so that `build_wheel.py` can recreate the virtual environment.

parser.add_argument(
"--no-venv",
action="store_true",
help="Use current Python interpreter as is, don't create venv.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use the current Python interpreter without creating a virtual environment

f"If anything goes wrong, please remove the environment at {venv_prefix} "
"to let build_wheel.py rebuild virtual environment.")
print("^^^^^^^^^^ IMPORTANT WARNING ^^^^^^^^^^", file=sys.stderr)
time.sleep(15)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we use some more elegant behaviour instead of time.sleep(15)?

Copy link
Collaborator

@tburt-nv tburt-nv May 21, 2025

Choose a reason for hiding this comment

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

Instead of prompting the user to consider taking action, can we just run pip remove torch inside the venv in this case (before running pip install -r "{requirements_file}")?

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.

4 participants