feat: use uv sources for CPU-only PyTorch#11833
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis change adds explicit PyTorch 2.0+ dependencies and configures a platform-aware wheel resolution mechanism via a custom CPU index in the uv package manager. It extends the configuration with required environments for Linux x86_64, Linux aarch64, and Darwin platforms while preserving existing workspace and override settings. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 7✅ Passed checks (7 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (42.03%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #11833 +/- ##
=======================================
Coverage 35.40% 35.40%
=======================================
Files 1527 1527
Lines 73418 73418
Branches 11025 11025
=======================================
Hits 25996 25996
+ Misses 46009 46008 -1
- Partials 1413 1414 +1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pyproject.toml`:
- Around line 150-154: The required-environments block currently restricts lock
resolution to Linux and macOS only; update pyproject.toml's
required-environments to also include Windows entries (e.g., add conditions like
"sys_platform == 'win32' and platform_machine == 'AMD64'" and "sys_platform ==
'win32' and platform_machine == 'ARM64'") so the lockfile contains
Windows-compatible wheels, or remove the required-environments section entirely
if you want resolution for all platforms, or alternatively add a note in the
repo docs instructing Windows developers to regenerate the lockfile locally.
- Around line 21-23: The top-level dependencies currently include "torch" and
"torchvision" with loose ranges ("torch>=2.0.0", "torchvision>=0.15.0") which
forces a huge unconditional install and risks incompatible pairings; either
tighten them to a tested compatible pair (e.g., change "torch>=2.0.0" and
"torchvision>=0.15.0" to pinned/tight ranges like "torch~=2.10.0" and
"torchvision~=0.25.0" in the project dependencies), or remove these two entries
from the main dependencies and add them under [project.optional-dependencies]
(example group name: ml) as "torch~=2.10.0" and "torchvision~=0.25.0" so users
opt-in; update any docs/install instructions to reference the new optional group
if you choose the latter.
pyproject.toml
Outdated
| # Explicit torch/torchvision to trigger [tool.uv.sources] index override | ||
| "torch>=2.0.0", | ||
| "torchvision>=0.15.0", |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# First, verify the file exists and check lines 21-23
echo "=== Lines 21-23 of pyproject.toml ==="
head -30 pyproject.toml | tail -10
echo ""
echo "=== Full dependencies section (lines around 15-30) ==="
head -35 pyproject.toml | tail -25
echo ""
echo "=== Check if langflow-base exists and contains torch ==="
fd "pyproject.toml" | xargs grep -l "langflow-base\|langflow_base" 2>/dev/null || echo "No langflow-base found"
echo ""
echo "=== Search for torch in all pyproject.toml files ==="
fd "pyproject.toml" | xargs grep -n "torch" 2>/dev/null || echo "No torch found"
echo ""
echo "=== Check uv.lock for torch package ==="
if [ -f "uv.lock" ]; then
echo "Found uv.lock, checking for torch entries..."
grep -n "name = \"torch\"" uv.lock | head -5
echo ""
echo "=== Context around torch entry ==="
grep -A 10 "name = \"torch\"" uv.lock | head -20
else
echo "uv.lock not found"
fiRepository: langflow-ai/langflow
Length of output: 4647
🏁 Script executed:
#!/bin/bash
echo "=== Checking src/backend/base/pyproject.toml for torch ==="
cat src/backend/base/pyproject.toml | grep -i "torch" | head -20
echo ""
echo "=== Full dependencies section in langflow-base ==="
sed -n '/^dependencies/,/^]/p' src/backend/base/pyproject.toml | head -50
echo ""
echo "=== Checking uv.lock for torchvision versions and compatibility ==="
grep -A 5 'name = "torchvision"' uv.lock | head -30
echo ""
echo "=== Checking marker consistency between torch and torchvision in uv.lock ==="
echo "Torch entries:"
grep 'name = "torch"' uv.lock | grep -v "^#"
echo ""
echo "Torchvision entries:"
grep 'name = "torchvision"' uv.lock | grep -v "^#"Repository: langflow-ai/langflow
Length of output: 9974
torch and torchvision should be optional dependencies or have tighter version constraints.
torch is now a new unconditional top-level dependency (not previously a transitive dependency of langflow-base), meaning all installations will pull ~700 MB+ even if torch/LLM features aren't used. While the current lockfile correctly resolves to compatible versions (torch 2.2.2 + torchvision 0.17.2 on macOS x86_64, torch 2.10.0 + torchvision 0.25.0 elsewhere), the loose constraint ranges (>=2.0.0 / >=0.15.0) are fragile — they could resolve to incompatible combinations in future updates. Consider either:
- Tightening to specific compatible pairs (e.g.,
torch~=2.10.0, torchvision~=0.25.0), or - Moving torch/torchvision to an optional dependency group (e.g.,
[project.optional-dependencies] ml = [...]) so users opt-in to the extra size, while keeping the default install lean.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pyproject.toml` around lines 21 - 23, The top-level dependencies currently
include "torch" and "torchvision" with loose ranges ("torch>=2.0.0",
"torchvision>=0.15.0") which forces a huge unconditional install and risks
incompatible pairings; either tighten them to a tested compatible pair (e.g.,
change "torch>=2.0.0" and "torchvision>=0.15.0" to pinned/tight ranges like
"torch~=2.10.0" and "torchvision~=0.25.0" in the project dependencies), or
remove these two entries from the main dependencies and add them under
[project.optional-dependencies] (example group name: ml) as "torch~=2.10.0" and
"torchvision~=0.25.0" so users opt-in; update any docs/install instructions to
reference the new optional group if you choose the latter.
pyproject.toml
Outdated
| "langflow-base[complete]~=0.8.0", | ||
| # Explicit torch/torchvision to trigger [tool.uv.sources] index override | ||
| "torch>=2.0.0", | ||
| "torchvision>=0.15.0", |
There was a problem hiding this comment.
Can we also just put these in the docling optional dependencies?
- Add Windows AMD64 platform support to required-environments - Add inline comments explaining architecture naming differences across OSes - Document why loose version ranges are used (avoid conflicts with transitive deps like altk) - Exclude Windows ARM64 due to missing wheels for dependencies like faiss-cpu - Update comments to reflect multi-platform support (Linux, macOS, Windows) Resolves CodeRabbit issues: 1. Windows platform missing from required-environments 2. Clarifies rationale for loose torch/torchvision version ranges The loose version ranges (>=2.0.0) are intentional to avoid conflicts with transitive dependencies (e.g., agent-lifecycle-toolkit requires torch==2.2.2). The uv sources configuration ensures CPU-only PyTorch wheels are used for all platforms (verified in lockfile: torch 2.10.0+cpu for Linux/Windows).
Configure [tool.uv.sources] with pytorch-cpu index to avoid ~6GB CUDA dependencies in Docker images. This replaces hardcoded wheel URLs with a cleaner index-based approach. - Add pytorch-cpu index with explicit = true - Add torch/torchvision to [tool.uv.sources] - Add explicit torch/torchvision deps to trigger source override - Regenerate lockfile without nvidia/cuda/triton packages
- Add Windows AMD64 platform support to required-environments - Add inline comments explaining architecture naming differences across OSes - Document why loose version ranges are used (avoid conflicts with transitive deps like altk) - Exclude Windows ARM64 due to missing wheels for dependencies like faiss-cpu - Update comments to reflect multi-platform support (Linux, macOS, Windows) Resolves CodeRabbit issues: 1. Windows platform missing from required-environments 2. Clarifies rationale for loose torch/torchvision version ranges The loose version ranges (>=2.0.0) are intentional to avoid conflicts with transitive dependencies (e.g., agent-lifecycle-toolkit requires torch==2.2.2). The uv sources configuration ensures CPU-only PyTorch wheels are used for all platforms (verified in lockfile: torch 2.10.0+cpu for Linux/Windows).
1a4485b to
f85fea4
Compare
Adam-Aghili
left a comment
There was a problem hiding this comment.
Tested locally and it seems fine.
The image size seemed to still be ~4gb but that might be due some local issues I had with QEMU emulation. So i trust your local testing more than mine.
I am confortable getting this merged, then we see how it works in our pipelines
The Vite frontend build was configured with --max-old-space-size=12288 (12GB), which exceeds available RAM on ARM64 CI runners, causing the build process to be OOM-killed during the transform phase. Reduced to 4GB (4096MB) which is sufficient for the Vite build and prevents OOM kills in memory-constrained Docker BuildKit environments.
The recursive chown -R on /app was re-owning the entire .venv (~2.6GB, 40k+ files) which was already correctly owned via COPY --chown=1000:0. This was causing the build to be killed on ARM64 runners. Changed to non-recursive chown on /app since only the directory itself needs ownership set. /app/data still gets recursive chown (it's empty).
The 40GB ARM64 runner runs out of disk when building 3 Docker images sequentially. Each image (main ~8GB layers, backend ~5GB, frontend) accumulates build cache and layers that exhaust the disk. Added cleanup steps between builds that: - Remove the tested image (no longer needed) - Prune all unused Docker data and buildx cache - Log disk usage before/after for debugging
…cpu-torch-uv-sources
* feat: use uv sources for CPU-only PyTorch Configure [tool.uv.sources] with pytorch-cpu index to avoid ~6GB CUDA dependencies in Docker images. This replaces hardcoded wheel URLs with a cleaner index-based approach. - Add pytorch-cpu index with explicit = true - Add torch/torchvision to [tool.uv.sources] - Add explicit torch/torchvision deps to trigger source override - Regenerate lockfile without nvidia/cuda/triton packages * fix: address CodeRabbit review issues for PR #11833 - Add Windows AMD64 platform support to required-environments - Add inline comments explaining architecture naming differences across OSes - Document why loose version ranges are used (avoid conflicts with transitive deps like altk) - Exclude Windows ARM64 due to missing wheels for dependencies like faiss-cpu - Update comments to reflect multi-platform support (Linux, macOS, Windows) Resolves CodeRabbit issues: 1. Windows platform missing from required-environments 2. Clarifies rationale for loose torch/torchvision version ranges The loose version ranges (>=2.0.0) are intentional to avoid conflicts with transitive dependencies (e.g., agent-lifecycle-toolkit requires torch==2.2.2). The uv sources configuration ensures CPU-only PyTorch wheels are used for all platforms (verified in lockfile: torch 2.10.0+cpu for Linux/Windows). * fixed * fix: reduce Node.js heap size to 4GB in Docker builds to prevent OOM The Vite frontend build was configured with --max-old-space-size=12288 (12GB), which exceeds available RAM on ARM64 CI runners, causing the build process to be OOM-killed during the transform phase. Reduced to 4GB (4096MB) which is sufficient for the Vite build and prevents OOM kills in memory-constrained Docker BuildKit environments. * fix: avoid redundant recursive chown on /app in backend Dockerfile The recursive chown -R on /app was re-owning the entire .venv (~2.6GB, 40k+ files) which was already correctly owned via COPY --chown=1000:0. This was causing the build to be killed on ARM64 runners. Changed to non-recursive chown on /app since only the directory itself needs ownership set. /app/data still gets recursive chown (it's empty). * fix: add Docker cleanup between image builds to prevent disk full The 40GB ARM64 runner runs out of disk when building 3 Docker images sequentially. Each image (main ~8GB layers, backend ~5GB, frontend) accumulates build cache and layers that exhaust the disk. Added cleanup steps between builds that: - Remove the tested image (no longer needed) - Prune all unused Docker data and buildx cache - Log disk usage before/after for debugging --------- Co-authored-by: vijay kumar katuri <vijay.katuri@ibm.com>
This reverts commit 355a4aa.
* feat: use uv sources for CPU-only PyTorch Configure [tool.uv.sources] with pytorch-cpu index to avoid ~6GB CUDA dependencies in Docker images. This replaces hardcoded wheel URLs with a cleaner index-based approach. - Add pytorch-cpu index with explicit = true - Add torch/torchvision to [tool.uv.sources] - Add explicit torch/torchvision deps to trigger source override - Regenerate lockfile without nvidia/cuda/triton packages * fix: address CodeRabbit review issues for PR #11833 - Add Windows AMD64 platform support to required-environments - Add inline comments explaining architecture naming differences across OSes - Document why loose version ranges are used (avoid conflicts with transitive deps like altk) - Exclude Windows ARM64 due to missing wheels for dependencies like faiss-cpu - Update comments to reflect multi-platform support (Linux, macOS, Windows) Resolves CodeRabbit issues: 1. Windows platform missing from required-environments 2. Clarifies rationale for loose torch/torchvision version ranges The loose version ranges (>=2.0.0) are intentional to avoid conflicts with transitive dependencies (e.g., agent-lifecycle-toolkit requires torch==2.2.2). The uv sources configuration ensures CPU-only PyTorch wheels are used for all platforms (verified in lockfile: torch 2.10.0+cpu for Linux/Windows). * fixed * fix: reduce Node.js heap size to 4GB in Docker builds to prevent OOM The Vite frontend build was configured with --max-old-space-size=12288 (12GB), which exceeds available RAM on ARM64 CI runners, causing the build process to be OOM-killed during the transform phase. Reduced to 4GB (4096MB) which is sufficient for the Vite build and prevents OOM kills in memory-constrained Docker BuildKit environments. * fix: avoid redundant recursive chown on /app in backend Dockerfile The recursive chown -R on /app was re-owning the entire .venv (~2.6GB, 40k+ files) which was already correctly owned via COPY --chown=1000:0. This was causing the build to be killed on ARM64 runners. Changed to non-recursive chown on /app since only the directory itself needs ownership set. /app/data still gets recursive chown (it's empty). * fix: add Docker cleanup between image builds to prevent disk full The 40GB ARM64 runner runs out of disk when building 3 Docker images sequentially. Each image (main ~8GB layers, backend ~5GB, frontend) accumulates build cache and layers that exhaust the disk. Added cleanup steps between builds that: - Remove the tested image (no longer needed) - Prune all unused Docker data and buildx cache - Log disk usage before/after for debugging --------- Co-authored-by: vijay kumar katuri <vijay.katuri@ibm.com>
Configure [tool.uv.sources] with pytorch-cpu index to avoid ~6GB CUDA dependencies in Docker images. This replaces hardcoded wheel URLs with a cleaner index-based approach.
Summary by CodeRabbit