Filter JAX packages from user requirements to prevent accelerator backend override#80
Filter JAX packages from user requirements to prevent accelerator backend override#80JyotinderSingh merged 4 commits intomainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the container build process by automatically filtering JAX-related packages from user-provided Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a sensible feature to filter JAX-related packages from user requirements, preventing conflicts with the pre-installed accelerator-specific JAX versions. However, a potential security issue exists where sensitive information (like credentials in a URL) could be leaked into the logs when a requirement line is filtered. Additionally, I suggest refactoring a small part of the implementation to avoid reading and processing the requirements file twice, which would improve both efficiency and maintainability. The implementation is otherwise robust and accompanied by a comprehensive set of tests.
|
|
||
| # Copy requirements.txt if it exists | ||
| # Copy requirements.txt (with JAX-related packages filtered out) | ||
| if requirements_path and os.path.exists(requirements_path): | ||
| shutil.copy(requirements_path, os.path.join(tmpdir, "requirements.txt")) | ||
| with open(requirements_path, "r") as f: | ||
| filtered = _filter_jax_requirements(f.read()) |
There was a problem hiding this comment.
The requirements.txt file is being read and filtered here, but it's also read and filtered earlier in _hash_requirements (lines 162-164). This duplicates work and file I/O.
Consider refactoring to read and filter the requirements file only once within the get_or_build_container function. The resulting filtered content could then be passed as an argument to both _hash_requirements and _build_and_push to avoid this duplication.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
| _KEEP_MARKER = "# kr:keep" | ||
|
|
||
|
|
||
| def _filter_jax_requirements(requirements_content: str) -> str: |
There was a problem hiding this comment.
Will we also support requirements specified in pyproject.toml?
There was a problem hiding this comment.
Yes, we should add support for that in subsequent PRs. Created #81 for tracking.
Summary
requirements.txtfiles containingjax,jaxlib,libtpu, orlibtpu-nightlyare now automatically filtered before the container build, preventing them from overriding the accelerator-specific JAX installation (e.g.,jax[tpu],jax[cuda12])# kr:keepto any line in theirrequirements.txtrequirements.txtno longer trigger unnecessary container rebuildsProblem
The Dockerfile template installs the correct JAX backend first (
jax[tpu]>=0.4.6for TPU,jax[cuda12]for GPU), then installs user requirements after. If a user's localrequirements.txtcontainsjaxorjax[cpu](common during local development), pip would silently reinstall JAX without the accelerator extras, causing runtime failures or performance degradation on TPU/GPU.