Skip to content

Comments

Update ComfyUI to v0.7.0 with PyTorch optimizations#16

Merged
jamesbrink merged 12 commits intomainfrom
update-comfyui-v0.7.0
Jan 3, 2026
Merged

Update ComfyUI to v0.7.0 with PyTorch optimizations#16
jamesbrink merged 12 commits intomainfrom
update-comfyui-v0.7.0

Conversation

@jamesbrink
Copy link
Member

@jamesbrink jamesbrink commented Jan 2, 2026

Summary

This PR updates ComfyUI to v0.7.0 and includes significant improvements to the build system, particularly for PyTorch handling on both CUDA (Linux) and MPS (macOS) platforms.

Key Changes

  • ComfyUI v0.7.0: Updated to the latest release with all new features and dependencies
  • Pre-built PyTorch CUDA wheels: Switched from compiling PyTorch from source to using pre-built wheels from pytorch.org, dramatically reducing build time and memory requirements
  • macOS MPS fix: Pinned PyTorch to 2.5.1 on macOS to fix MPS crashes on macOS 26 (Tahoe)
  • nixpkgs update: Updated from April 2025 to December 2025 with compatibility fixes

Detailed Changes

🚀 Pre-built PyTorch CUDA Wheels (Linux)

  • Before: Compiling PyTorch from source required 30-60GB RAM and hours of build time
  • After: Download ~2GB pre-built wheel in minutes
  • All GPU architectures supported (Pascal through Hopper) in a single build
  • CUDA 12.4 runtime bundled in wheels (no separate toolkit needed)
  • Removed architecture-specific packages (cuda-sm61, cuda-sm86, etc.) - no longer needed

🍎 macOS MPS Fix

  • PyTorch 2.9.x in nixpkgs has known MPS bugs on macOS 26
  • Causes trace trap crashes during SDXL inference
  • Pinned to PyTorch 2.5.1 using pre-built wheels from pytorch.org
  • Excluded kornia on macOS (Cargo build issues unrelated to torch)

🔧 Build System Fixes

  • File descriptor limit: Increased to 10240 for aiohttp/grpc DNS resolver compatibility
  • CUDA build fixes: Disabled cuda_compat on x86_64-linux, added badPlatforms workarounds
  • Cachix push: Filter Rust build artifacts (Cargo.lock, etc.) that cause upload issues
  • SDK migration: Updated from legacy darwin.apple_sdk.frameworks.Metal to apple-sdk_14

Test Plan

  • Build succeeds on macOS Apple Silicon (aarch64-darwin)
  • PyTorch 2.5.1 correctly installed on macOS
  • MPS available and functional
  • SDXL inference works without crashes on macOS 26
  • nix flake check passes
  • Build succeeds on Linux x86_64 (CPU)
  • Build succeeds on Linux x86_64 (CUDA)
  • Docker images build correctly

Breaking Changes

  • Removed architecture-specific CUDA packages (cuda-sm61, cuda-sm86, etc.)
    • Migration: Use nix run .#cuda instead - it now supports all architectures
  • kornia excluded on macOS (build issues with kornia-rs)

Files Changed

File Changes
nix/versions.nix Added PyTorch wheel URLs for CUDA and macOS
nix/python-overrides.nix Pre-built wheel overrides for CUDA and macOS
nix/packages.nix Simplified launcher, excluded kornia on macOS
flake.nix Removed arch-specific CUDA packages, simplified config
scripts/push-to-cachix.sh Filter Rust build artifacts

Related Issues

jamesbrink and others added 9 commits December 31, 2025 20:44
- ComfyUI: 0.6.0 → 0.7.0 (released 2025-12-31)
- Frontend package: 1.34.9 → 1.37.1
- Manager: 4.0.2 → 4.0.4
- Workflow templates: 0.7.59 → 0.7.65
- Workflow templates core: 0.3.43 → 0.3.65
- Workflow templates media API: 0.3.22 → 0.3.34
- Workflow templates media video: 0.3.19 → 0.3.22
- Workflow templates media image: 0.3.36 → 0.3.47
- Workflow templates media other: 0.3.47 → 0.3.63
- KJNodes: 2025-12-21 → 2025-12-28
- WanVideoWrapper: 2025-12-24 → 2025-12-31
- Add ultralytics for Impact Subpack's UltralyticsDetectorProvider node
- Create PEP 405 compliant venv structure for mutable package installs
- Add version constraints to prevent Manager from overriding vendored packages
- Set UV_CONSTRAINT alongside PIP_CONSTRAINT for uv compatibility
- Update nixpkgs from April 2025 to December 2025
- Migrate from legacy darwin.apple_sdk.frameworks.Metal to apple-sdk_14
- Disable failing imageio test_process_termination (exit code 6 vs 2)
The nixpkgs update brought aiohttp 3.13.2 which uses grpc/c-ares for
async DNS resolution. This consumes significantly more file descriptors
per connection. Combined with ComfyUI-Manager's concurrent HTTP requests
during startup, this exhausts the default macOS limit of 256 FDs.

Add ulimit -n 10240 to the launcher to prevent "Too many open files"
errors on both macOS and Linux.
Skip Cargo.lock, Cargo.toml, and .cargo-checksum.json files when
pushing build dependencies. These intermediate files cause upload
retries and aren't useful for cache consumers who pull pre-built
packages.
Work around nixpkgs-unstable issues where certain packages are marked
in meta.badPlatforms even though they work:
- cudnn 9.13.0 for CUDA 12.8 on x86_64-linux
- kornia-rs on aarch64-linux

Added allowUnsupportedSystem = true to:
- mkCudaPkgs helper (CUDA builds)
- pkgsLinuxX86 (x86_64 Docker images)
- pkgsLinuxArm64 (aarch64 Docker images)

See: NixOS/nixpkgs#458799

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
cuda_compat is only available for aarch64-linux (Jetson devices) but was
incorrectly being pulled into the dependency tree on x86_64-linux builds.

This adds an overlay to set cuda_compat = null on x86_64-linux systems,
preventing the build failure "variable $src or $srcs should point to source".

Combined with allowUnsupportedSystem for the cudnn badPlatforms workaround,
CUDA builds now work correctly on x86_64-linux.

See: NixOS/nixpkgs#458799

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Switch from compiling PyTorch from source to using pre-built wheels
from pytorch.org for CUDA builds. This provides:

- Fast builds (~2GB download vs hours of compilation)
- Low memory usage (no 30-60GB RAM requirement)
- All GPU architectures (Pascal through Hopper) in one package
- CUDA 12.4 runtime bundled in wheels

Also removes architecture-specific packages (cuda-sm61, etc.) since
the wheel-based approach supports all architectures universally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PyTorch 2.9.x in nixpkgs has MPS bugs on macOS 26 (Tahoe) that cause
trace trap crashes during SDXL inference. Pin to 2.5.1 pre-built
wheels from pytorch.org for macOS Apple Silicon.

- Add darwinArm64 wheel pins in nix/versions.nix
- Add macOS-specific torch/torchvision/torchaudio overrides
- Exclude kornia on macOS (Cargo build issues unrelated to torch)

Fixes: pytorch/pytorch#167679
@claude
Copy link

claude bot commented Jan 2, 2026

Code Review: ComfyUI v0.7.0 Update with PyTorch Optimizations

Summary

This is a well-executed major update that significantly improves the build system by switching from source compilation to pre-built PyTorch wheels. The changes are well-documented and the approach is sound.

✅ Strengths

Architecture & Design

  1. Excellent wheel-based approach - Switching to pre-built PyTorch wheels is the right choice:

    • Eliminates 30-60GB RAM compilation requirements
    • Dramatically reduces build time (hours → minutes)
    • Universal GPU architecture support in a single package
    • Well-implemented with proper autoPatchelf handling
  2. Clean simplification - Removing architecture-specific CUDA packages (sm61, sm86, etc.) reduces complexity while maintaining full functionality via the universal wheel approach.

  3. Platform-specific fixes - The macOS PyTorch 2.5.1 pinning is properly justified with issue links and addresses real MPS bugs on macOS 26.

Code Quality

  1. Good documentation - Comments explain rationale (e.g., why PyTorch 2.5.1 on macOS, why filtering Cargo files)
  2. Proper error handling - File descriptor limit increase with fallback, smart symlink handling
  3. Consistent formatting - Nix code follows project style guidelines

🔍 Issues & Concerns

Critical Issues

1. Missing allowUnsupportedSystem workaround in key places (nix/flake.nix:56-61, 63-71)

The allowUnsupportedSystem = true is added for pkgsLinuxArm64 (line 69) but missing for pkgsLinuxX86. According to the commit message and nixpkgs issue #458799, both x86_64 and aarch64 need this workaround for cudnn/kornia-rs badPlatforms issues.

# Should be added to pkgsLinuxX86 config (around line 60):
pkgsLinuxX86 = import nixpkgs {
  system = "x86_64-linux";
  config = {
    allowUnfree = true;
    allowBrokenPredicate = pkg: (pkg.pname or "") == "open-clip-torch";
    allowUnsupportedSystem = true;  # ← Missing! Needed for cudnn workaround
  };
};

2. Potential metadata corruption issue (nix/python-overrides.nix:71-78)

The sed commands that strip nvidia-* and triton dependencies could be fragile:

sed -i '/^Requires-Dist: nvidia-/d' "$metadata"
sed -i '/^Requires-Dist: triton/d' "$metadata"

Concerns:

  • What if there are legitimate packages starting with "nvidia-" that should be kept?
  • The triton pattern is too broad - could match "python-triton" or other packages
  • No validation that metadata file integrity is maintained

Recommendation: Use more specific patterns:

sed -i '/^Requires-Dist: nvidia-c[ua]/d' "$metadata"  # nvidia-cuda-*, nvidia-cublas-*, etc.
sed -i '/^Requires-Dist: triton[^-]/d' "$metadata"    # Match "triton" but not "python-triton"

3. kornia exclusion on macOS lacks explanation (nix/packages.nix:158)

++ lib.optionals (pkgs.stdenv.isLinux && ps ? kornia && available ps.kornia) [ ps.kornia ]

The code excludes kornia on macOS, mentioned briefly in PR description as "Cargo build issues unrelated to torch", but:

  • No code comment explaining why
  • No issue reference
  • Could this break ComfyUI functionality on macOS?
  • Is this temporary or permanent?

Security Concerns

1. File descriptor limit increase (nix/packages.nix:232-235)

ulimit -n 10240 2>/dev/null || true

While the justification is sound (aiohttp/grpc DNS resolver), this is a significant increase from default limits. The silent failure (|| true) means users won't know if it failed.

Recommendations:

  • Document this prominently in release notes
  • Consider warning users if ulimit fails
  • Could this mask other issues with resource leaks?

2. Cachix filtering (scripts/push-to-cachix.sh:153-155)

ALL_PATHS=$(echo "$ALL_PATHS" | grep -vE '(Cargo\.lock|Cargo\.toml|\.cargo-checksum\.json)$')

Good approach, but the regex could be more defensive:

ALL_PATHS=$(echo "$ALL_PATHS" | grep -vE '/(Cargo\.lock|Cargo\.toml|\.cargo-checksum\.json)$')

Add leading / to ensure we're matching files, not just any path containing these strings.

Code Quality Issues

1. Inconsistent version constraint format (nix/packages.nix:55-61)

comfyui-frontend-package>=${versions.vendored.frontendPackage.version}
comfyui-workflow-templates>=${versions.vendored.workflowTemplates.version}
# ...

Using >= for vendored packages could allow pip to upgrade them if newer versions exist. Should use == for exact pinning:

comfyui-frontend-package==${versions.vendored.frontendPackage.version}

2. Duplicate library path handling (nix/python-overrides.nix:23-28, 31-45)

The wheelBuildInputs and cudaLibs are defined but the relationship between them could be clearer. Some organization:

# Common libs for all wheels
commonWheelBuildInputs = [ stdenv.cc.cc.lib zlib libGL glib ];

# CUDA-specific libs
cudaRuntimeLibs = lib.optionals useCuda [ ... ];

# Combined
wheelBuildInputs = commonWheelBuildInputs ++ cudaRuntimeLibs;

3. Silent test disabling (nix/python-overrides.nix:89, 147, 203)

pythonImportsCheck = [ ];
doCheck = false;

Disabling all import checks for wheel packages means we won't catch packaging issues. At minimum, we should check that torch imports successfully:

pythonImportsCheck = [ "torch" ];  # Basic smoke test

🎯 Recommendations

High Priority

  1. Add missing allowUnsupportedSystem to pkgsLinuxX86 config
  2. Improve metadata sed patterns to be more specific and safer
  3. Document kornia exclusion with comment and consider filing an issue
  4. Use exact version pinning (==) instead of >= for vendored packages

Medium Priority

  1. Enable basic import checks for PyTorch wheels (at least pythonImportsCheck = [ "torch" ])
  2. Improve ulimit failure visibility - at least log a warning if it fails
  3. Add defensive / to Cachix filter regex
  4. Add test plan results - PR shows unchecked Linux x86_64 CPU/CUDA and Docker builds

Low Priority

  1. Consider refactoring library path handling for better clarity
  2. Add smoke test for CUDA functionality (even if just checking .cuda is available)

📊 Test Coverage

The test plan shows:

  • ✅ macOS Apple Silicon builds and works
  • ❌ Linux x86_64 CPU - not tested
  • ❌ Linux x86_64 CUDA - not tested
  • ❌ Docker images - not tested

Recommendation: Before merging, verify at minimum that Linux CUDA builds successfully, as this is the major change in this PR.

🔒 Security Assessment

Overall: Low Risk

No critical security issues, but:

  • Watch for supply chain risks from PyPI wheels (mitigated by hash pinning)
  • File descriptor limit increase is justified but should be monitored
  • Metadata manipulation could theoretically be exploited but risk is low

📝 Documentation

Excellent - The PR description, commit messages, and code comments are thorough and well-written. The CLAUDE.md and README.md updates accurately reflect the changes.

Final Verdict

Conditional Approval ⚠️

This is excellent work that significantly improves the project. However, please address:

  1. Must fix before merge:

    • Add allowUnsupportedSystem to pkgsLinuxX86 config
    • Test Linux CUDA builds to verify the wheel approach works
  2. Should fix before merge:

    • Make metadata sed patterns more specific
    • Document kornia exclusion with code comment
    • Use == instead of >= for vendored package constraints
  3. Can fix in follow-up:

    • Enable import checks for wheels
    • Improve ulimit error visibility
    • Complete remaining test plan items

Great work on this modernization effort! The wheel-based approach is a massive improvement for users.


Review generated with guidance from project CLAUDE.md conventions

- Use exact version pinning (==) for vendored packages instead of >=
- Add comment explaining kornia exclusion on macOS with issue reference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@claude
Copy link

claude bot commented Jan 2, 2026

Code Review: ComfyUI v0.7.0 Update with PyTorch Optimizations

This is an excellent PR that significantly improves the build system. The migration from compiling PyTorch from source to using pre-built wheels is a major quality-of-life improvement. Here's my detailed review:


Strengths

1. Architecture Simplification

  • Major win: Removing architecture-specific CUDA packages (cuda-sm61, cuda-sm86, etc.) simplifies the flake dramatically
  • The pre-built PyTorch wheels from pytorch.org support all GPU architectures (Pascal through Hopper) in a single package
  • This reduces cognitive load for users and maintainability burden

Location: flake.nix:32-60

2. Build Performance & Resource Usage

  • Moving from 30-60GB RAM compilation to ~2GB wheel downloads is transformative
  • CUDA 12.4 runtime bundled in wheels eliminates separate toolkit requirement
  • This makes CUDA builds accessible to more users with limited hardware

Location: nix/python-overrides.nix:12-118

3. macOS MPS Fix

  • Pinning PyTorch 2.5.1 on macOS to work around MPS crashes is the right pragmatic approach
  • Good documentation of the issue with GitHub issue link
  • Excluding kornia on macOS is appropriate given the kornia-rs build issues

Locations:

  • nix/python-overrides.nix:213-296
  • nix/packages.nix:159-161

4. Code Quality

  • Excellent inline comments explaining PyTorch wheel metadata patching (nix/python-overrides.nix:69-78)
  • Clear separation of CUDA and Darwin wheel configurations
  • Good use of autoPatchelfIgnoreMissingDeps for runtime-provided libraries

5. Documentation Updates

  • CLAUDE.md and README.md are thoroughly updated
  • Breaking changes clearly documented
  • Migration path provided for users on old packages

🔍 Potential Issues

1. NixOS Module Still References Removed Packages ⚠️ CRITICAL

The NixOS module at nix/modules/comfyui.nix:10-36 still references the removed architecture-specific packages:

archPackages = {
  sm61 = pkgs.comfy-ui-cuda-sm61; # These packages no longer exist\!
  sm75 = pkgs.comfy-ui-cuda-sm75;
  sm86 = pkgs.comfy-ui-cuda-sm86;
  # ... etc
};

Impact: Users with NixOS configurations using cudaArch or cudaCapabilities will get build errors.

Recommendation:

  • Remove the cudaArch and cudaCapabilities options from the module since pre-built wheels support all architectures
  • Simplify to just cuda = true/false
  • Update the module to match the simplified flake architecture
  • Add deprecation warnings in this PR if you want a migration period

Location: nix/modules/comfyui.nix:10-36


2. Missing flake.lock Update Reference

The flake.lock shows nixpkgs was updated from April to December 2025, but there's no mention in the PR description of what compatibility issues were fixed.

Recommendation: Add a note about why the nixpkgs bump was necessary (probably for Python 3.12 compatibility or to pick up newer dependency versions).


3. File Descriptor Limit Increase

The launcher increases ulimit -n to 10240, which is good, but the comment could be clearer:

# Increase file descriptor limit for aiohttp/grpc DNS resolver
# macOS default (256) is too low; Linux (1024) may also be insufficient

Recommendation: Specify why ComfyUI-Manager's concurrent HTTP requests exhaust FDs. This helps future maintainers understand if this can be reduced when the underlying issue is fixed upstream.

Location: nix/packages.nix:235-238


4. Rust/Cargo Artifact Filtering

The cachix push script filters out Cargo artifacts:

ALL_PATHS=$(echo "$ALL_PATHS" | grep -vE '(Cargo\.lock|Cargo\.toml|\.cargo-checksum\.json)$')

Questions:

  • Which packages are causing these Cargo artifacts to appear?
  • Is this a symptom of a deeper build issue (should these files not be in the closure at all)?
  • Should we be fixing the root cause instead of filtering the symptom?

Recommendation: Add a comment explaining which package(s) introduce these artifacts and why filtering is the best approach.

Location: scripts/push-to-cachix.sh:153-155


5. Docker Image Architecture Support

The PR mentions multi-arch CPU builds (amd64 and arm64), but I don't see explicit handling of arm64 CUDA (NVIDIA Jetson, Grace Hopper).

Question: Is arm64 CUDA intentionally excluded? If so, this should be documented.

Location: nix/docker.nix, .github/workflows/build.yml


🚀 Performance Considerations

1. PyTorch Wheel Duplication

Using separate pre-built wheels for CUDA and macOS means each platform has its own ~2GB PyTorch download. This is actually better than the previous approach (huge CUDA compilation), but worth noting for binary cache sizing.

2. autoPatchelfHook Overhead

The CUDA wheels go through autoPatchelfHook with many ignored dependencies. This is correct, but adds a small build-time overhead. Consider if this could be optimized with more specific patchelf commands in the future.


🔒 Security Considerations

1. Pre-built Wheel Trust

The PR shifts from building PyTorch from auditable source to downloading pre-built wheels from pytorch.org.

Analysis: This is standard practice and pytorch.org is trusted, but worth noting the trust model has changed. The hashes in nix/versions.nix provide integrity verification.

Recommendation: Document in CLAUDE.md that PyTorch wheels come from pytorch.org with pinned hashes for reproducibility.

2. pip/uv Constraint File

The constraint file prevents package manager conflicts, which is good security hygiene:

comfyui-frontend-package==${versions.vendored.frontendPackage.version}

Recommendation: Consider adding a comment explaining that this prevents ComfyUI-Manager from downgrading security-critical packages.

Location: nix/packages.nix:48-64


📝 Test Coverage

The PR description shows comprehensive testing:

  • ✅ macOS Apple Silicon build
  • ✅ PyTorch 2.5.1 on macOS
  • ✅ MPS functionality
  • ✅ SDXL inference (no crashes)
  • ✅ Linux x86_64 CPU and CUDA
  • ✅ Docker images
  • nix flake check

Excellent coverage! Only missing:

  • Verification that NixOS module still works (probably broken due to issue Fails to start #1 above)
  • arm64 Linux testing (if supported)

🎯 Recommendations

High Priority (Should Fix Before Merge)

  1. Fix NixOS module to remove references to deleted architecture-specific packages
  2. Add deprecation notice in module docs for removed options

Medium Priority (Nice to Have)

  1. Add comment explaining Cargo artifact filtering in cachix script
  2. Document nixpkgs bump rationale in PR description
  3. Clarify ulimit comment with specific ComfyUI-Manager context

Low Priority (Future Work)

  1. Consider removing cudaArch/cudaCapabilities options entirely vs deprecation
  2. Document arm64 CUDA support status (Jetson, Grace Hopper)

📊 Summary

Aspect Rating Notes
Code Quality ⭐⭐⭐⭐⭐ Excellent structure, well-commented
Architecture ⭐⭐⭐⭐⭐ Major simplification, great UX improvement
Testing ⭐⭐⭐⭐½ Comprehensive, missing NixOS module verification
Documentation ⭐⭐⭐⭐⭐ Thorough updates to all user-facing docs
Breaking Changes ⭐⭐⭐⭐ Well-documented, but module needs updating
Security ⭐⭐⭐⭐ Good practices, pre-built wheels are trusted source

Overall Assessment: This is a high-quality PR that makes significant improvements to build ergonomics and performance. The main blocker is fixing the NixOS module to match the flake changes. Once that's addressed, this is ready to merge.


🔧 Action Items

Before merging:

  • Fix nix/modules/comfyui.nix to remove architecture-specific package references
  • Test NixOS module with simplified cuda = true option
  • Update module documentation in README.md

Suggested follow-ups (can be separate PRs):

  • Add Cargo artifact filter explanation
  • Document wheel trust model in security section
  • Test on arm64 Linux if supported

Great work on this modernization! 🎉

- kornia-rs has aarch64-linux in badPlatforms, causing CI failures
- Also improve Cachix filter regex to be more defensive

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@claude
Copy link

claude bot commented Jan 2, 2026

Code Review: ComfyUI v0.7.0 Update with PyTorch Optimizations

This is a substantial and well-executed PR that modernizes the build system with significant architectural improvements. Overall, the code quality is excellent, but I've identified a few areas for consideration.


🎯 Summary Assessment

Strengths:

  • Clean migration from source compilation to pre-built PyTorch wheels (excellent design decision)
  • Comprehensive documentation updates across README, CLAUDE.md
  • Well-structured Python overrides with clear separation of concerns
  • Good error handling for missing dependencies (autoPatchelfIgnoreMissingDeps)
  • Thorough testing checklist in PR description

Risk Level: Medium (significant architectural changes, but well-tested)


📋 Detailed Findings

1. Critical: PyTorch Version Pinning ⚠️

Issue: PyTorch 2.5.1 is pinned for both CUDA and macOS to work around MPS bugs on macOS 26, but this creates a version lock that affects all platforms.

Location: nix/versions.nix:103-137

Concern:

  • CUDA users are getting PyTorch 2.5.1 when 2.6+ might be available and stable
  • The MPS bug workaround for macOS shouldn't constrain Linux CUDA users
  • No automated mechanism to track when upstream fixes the bug

Recommendation:

# Consider different versions per platform:
cu124 = {
  torch = {
    version = "2.6.0";  # or latest stable for CUDA
    # ...
  };
};
darwinArm64 = {
  torch = {
    version = "2.5.1";  # pinned for MPS bug workaround
    # ...
  };
};

Priority: Medium - Current approach works but limits optimization opportunities


2. Security: Wheel URL Integrity

Issue: Pre-built wheels from pytorch.org are downloaded via HTTPS with hash verification, which is good, but there's no signature verification.

Location: nix/python-overrides.nix:54-58, nix/versions.nix:104-137

Current State:

src = pkgs.fetchurl {
  url = cudaWheels.torch.url;
  hash = cudaWheels.torch.hash;  # SHA256 verification only
};

Concern:

  • Relies solely on HTTPS + hash matching (standard for Nix, but worth noting)
  • No verification that wheels came from official PyTorch
  • Compromise of pytorch.org could inject malicious wheels (though hash would need updating)

Recommendation:

  • Document the trust model in comments (currently done implicitly)
  • Consider adding a comment about the verification chain
  • Not a blocker - this is standard Nix practice

Priority: Low - Standard practice, but worth documenting


3. Performance: autoPatchelfIgnoreMissingDeps List Maintenance

Issue: Large lists of ignored libraries in nix/python-overrides.nix could mask real missing dependencies.

Location: nix/python-overrides.nix:133-198

Example:

autoPatchelfIgnoreMissingDeps = [
  "libcuda.so.1"
  "libtorch.so"
  # ... 20+ entries for torchaudio alone
];

Concern:

  • FFmpeg version sprawl (4.x, 5.x, 6.x all listed) suggests potential for stale entries
  • If a library name changes, errors might be silently ignored
  • No comments explaining why each is ignored

Recommendation:

  • Add inline comments explaining each category of ignored libs
  • Consider grouping by reason (e.g., "# Runtime-provided", "# Optional backends")
  • Periodically review if all entries are still needed

Priority: Low - Works correctly, but maintainability concern


4. Code Quality: kornia Exclusion Logic

Issue: kornia is excluded on macOS and aarch64-linux, but the conditional logic is verbose and brittle.

Location: nix/packages.nix:159-163

Current:

++ lib.optionals (
  pkgs.stdenv.isLinux && pkgs.stdenv.isx86_64 && ps ? kornia && available ps.kornia
) [ ps.kornia ]

Concern:

  • Inverted logic (easier to express as "exclude if darwin OR aarch64")
  • Multiple predicates make it harder to understand the intent
  • available check might be redundant after platform checks

Recommendation:

++ lib.optionals (
  # kornia excluded on macOS/aarch64-linux due to kornia-rs Cargo issues
  # See: https://github.com/NixOS/nixpkgs/issues/458799
  (pkgs.stdenv.isLinux && pkgs.stdenv.isx86_64)
  && (ps ? kornia && available ps.kornia)
) [ ps.kornia ]

Priority: Low - Cosmetic improvement for clarity


5. Documentation: Breaking Changes Communication

Issue: Architecture-specific CUDA packages removed, but migration path could be clearer.

Location: README.md:18-24, flake.nix:34-43

Current State:

  • PR body mentions breaking changes
  • README updated to remove architecture-specific docs
  • No deprecation warnings or migration guide in code

Concern:

  • Users with nix run .#cuda-sm86 bookmarked will get errors
  • No runtime message suggesting the new command

Recommendation:

  • Consider adding a flake output that shows a helpful error:
cuda-sm86 = throw "cuda-sm86 removed in v0.7.0. Use 'nix run .#cuda' instead (now supports all GPU architectures)";

Priority: Medium - Better user experience for existing users


6. Testing: Insufficient Platform Coverage in CI

Issue: PR description shows manual testing, but CI only builds, doesn't verify runtime behavior.

Location: .github/workflows/build.yml (not shown in diff, but referenced)

Concern:

  • PyTorch wheel patches (metadata sed) aren't tested
  • MPS functionality on macOS 26 not verified in CI (understandable, requires runner)
  • No smoke test that actually imports torch and checks CUDA/MPS availability

Recommendation:

  • Add basic import tests in nix/checks.nix:
python-import-test = pkgs.runCommand "test-python-imports" {} ''
  ${pythonRuntime}/bin/python -c "import torch; print(torch.__version__)"
  touch $out
'';

Priority: Medium - Would catch regressions in future


7. Best Practice: pip Constraints Versioning

Issue: pip constraints file prevents version drift, but uses loose constraints.

Location: nix/packages.nix:48-64

Current:

pipConstraints = pkgs.writeText "pip-constraints.txt" ''
  huggingface-hub<1.0
  transformers>=4.0.0
  torch>=2.0.0
  # ...

Concern:

  • Loose ranges (>=4.0.0) could still allow unwanted updates
  • No mechanism to verify constraints match Nix-provided versions
  • ComfyUI-Manager could install newer versions within range

Recommendation:

  • Pin exact versions from Nix derivations:
torch==${final.torch.version}
transformers==${final.transformers.version}
  • This ensures pip never tries to "upgrade" Nix-provided packages

Priority: Medium - Could prevent subtle bugs


8. Potential Bug: File Descriptor Limit

Issue: No explicit file descriptor limit increase visible in launcher.

Location: nix/packages.nix:224-400 (launcher script)

From PR Description:

"File descriptor limit: Increased to 10240 for aiohttp/grpc DNS resolver compatibility"

Concern:

  • I don't see ulimit -n 10240 in the diff
  • If this is handled elsewhere, should be documented
  • aiohttp DNS issues are platform-specific (usually Linux)

Recommendation:

  • Verify the fd limit is actually set in the launcher
  • Add inline comment explaining why it's needed
  • Consider platform-specific application (only Linux?)

Priority: High - If missing, could cause runtime issues


9. Code Style: Metadata sed Patterns

Issue: sed patterns in postInstall could be more robust.

Location: nix/python-overrides.nix:72-77

Current:

sed -i '/^Requires-Dist: nvidia-/d' "$metadata"
sed -i '/^Requires-Dist: triton/d' "$metadata"

Concern:

  • Matches triton anywhere in the line (could catch pytriton or similar)
  • No error checking if metadata file is malformed
  • Silent failure if patterns don't match

Recommendation:

sed -i '/^Requires-Dist: nvidia-[^[:space:]]*/d' "$metadata"
sed -i '/^Requires-Dist: triton[[:space:]<>=]/d' "$metadata"

Priority: Low - Unlikely to cause issues, but more precise is better


10. Architecture: Vendored Package Strategy

Issue: Many packages vendored as wheels in nix/versions.nix, but no clear policy on when to vendor vs. use nixpkgs.

Location: nix/versions.nix:9-95

Observation:

  • spandrel, color-matcher, facexlib all vendored
  • Some packages (segment-anything, sam2) built from source
  • No documented criteria for the decision

Concern:

  • Wheel maintenance burden increases with each version
  • Some wheels might have binary dependencies that break on updates
  • No automation for updating vendored wheels

Recommendation:

  • Add comments in versions.nix explaining why each is vendored
  • Consider upstreaming missing packages to nixpkgs
  • Document update process in CLAUDE.md

Priority: Low - Works well, but maintainability concern


🔒 Security Review

  1. Pre-built wheels from pytorch.org: ✅ Standard practice, hash-verified
  2. No arbitrary code execution in patches: ✅ Reviewed patches, all benign
  3. Dependencies pinned with hashes: ✅ Excellent reproducibility
  4. No network access during build: ✅ Pure Nix build
  5. autoPatchelf doesn't introduce vulnerabilities: ✅ Standard library linking

Security Rating: Good - No concerning patterns found


⚡ Performance Considerations

  1. Build time improvement: Massive win (hours → minutes for CUDA)
  2. Runtime performance: Should be identical to upstream PyTorch wheels
  3. Closure size: Slightly larger due to bundled CUDA libs (~2GB), acceptable trade-off
  4. Memory usage: Build now possible on 8GB+ RAM systems (vs. 32GB+ before)

Performance Rating: Excellent improvement


🧪 Test Coverage

Manual testing (from PR): ✅ Comprehensive

  • macOS Apple Silicon build
  • Linux x86_64 CPU build
  • Linux x86_64 CUDA build
  • Docker images
  • MPS functionality
  • SDXL inference

Automated testing: ⚠️ Could be improved

  • nix flake check passes
  • No runtime import tests
  • No GPU functionality tests (challenging in CI)

Recommendation: Add basic import smoke tests to nix/checks.nix


📚 Documentation Quality

  • ✅ README extensively updated with new workflow
  • ✅ CLAUDE.md updated with accurate build info
  • ✅ PR description thorough and well-structured
  • ✅ Inline comments explain complex logic
  • ⚠️ Could benefit from more comments in python-overrides.nix

🎯 Recommendations Summary

Must Address (Before Merge):

  1. Verify file descriptor limit is actually set (mentioned in PR but not visible in diff)
  2. Add deprecation errors for removed cuda-sm packages* for better UX

Should Address (Soon After Merge):

  1. Decouple CUDA and macOS PyTorch versions to allow independent updates
  2. Add basic Python import smoke tests to CI
  3. Pin exact versions in pip constraints to prevent drift

Nice to Have (Future Improvements):

  1. Document vendored package policy in CLAUDE.md
  2. Add inline comments for autoPatchelf ignored libs
  3. Make sed patterns more precise in metadata cleanup
  4. Improve kornia exclusion logic for clarity
  5. Add platform coverage to automated tests

✅ Final Verdict

Recommendation: Approve with minor fixes

This is excellent work that significantly improves the project's build system. The migration to pre-built wheels is architecturally sound and well-executed. The code quality is high, documentation is thorough, and testing is comprehensive.

The identified issues are mostly minor improvements and maintainability concerns. The only potential blocker is #1 (fd limit) - please verify this is handled correctly.

Estimated risk of merge: Low-Medium

  • High confidence in CUDA Linux (well-tested, standard approach)
  • High confidence in macOS (author confirmed testing)
  • Medium confidence in edge cases (arm64 Linux, unusual configurations)

Great work on this substantial improvement! 🚀

The wheel-based CUDA approach supports all GPU architectures in a single
package, so architecture-specific options are no longer needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@claude
Copy link

claude bot commented Jan 2, 2026

Comprehensive Code Review: ComfyUI v0.7.0 Update with PyTorch Optimizations

Summary

This is a well-executed major update that significantly improves the build system by switching from source compilation to pre-built PyTorch wheels. The changes are thoroughly tested, well-documented, and represent a major usability improvement.

✅ Strengths

1. Architecture & Design Excellence

  • Brilliant wheel-based approach: Switching to pre-built PyTorch wheels is the right architectural decision:

    • Eliminates 30-60GB RAM compilation requirements
    • Reduces build time from hours to minutes (~2GB download)
    • Universal GPU architecture support (Pascal through Hopper) in a single package
    • Properly implemented with autoPatchelf for library dependencies
  • Clean simplification: Removing 7 architecture-specific CUDA packages (cuda-sm61, cuda-sm86, etc.) dramatically reduces maintenance burden while maintaining full functionality.

  • Platform-specific fixes: macOS PyTorch 2.5.1 pinning is well-justified with issue link addressing real MPS crashes.

2. Code Quality

  • Excellent documentation: Comments clearly explain rationale (PyTorch version choices, FFmpeg compatibility, Cargo filtering)

  • Proper dependency management:

    • Correct use of autoPatchelfIgnoreMissingDeps for runtime-provided libraries
    • Smart removal of nvidia-* wheel metadata to use nixpkgs cudaPackages
    • Comprehensive FFmpeg version handling for torchaudio (versions 4-6)
  • Good abstractions: python-overrides.nix cleanly separates wheel handling from package definitions

3. Testing & Validation

  • Comprehensive test plan covers all platforms (macOS ARM, Linux CPU/CUDA, Docker)
  • Test items are specific and measurable
  • Version compatibility validated

🔍 Issues Found

Critical Issues

None - No critical bugs or security issues identified.

Medium Priority Issues

  1. nix/python-overrides.nix:155 - Potential platform support gap:
    The cudaLibs list uses pkgs.cudaPackages but doesn't verify CUDA package availability on the platform. While this works on x86_64-linux, consider adding a platform check.

    Recommendation: Add assertion or better document platform requirements in meta.platforms.

  2. nix/python-overrides.nix:370-393 - av wheel fallback may silently fail:
    The fallback to prev.av may still hit FFmpeg 8.x build failures on unsupported platforms. The comment mentions this but doesn't handle the error case.

    Recommendation: Consider marking av as broken on unsupported platforms or adding a more explicit error message.

  3. scripts/push-to-cachix.sh:155 - Cargo filtering may be too aggressive:
    This filters all Cargo files from all packages, not just problematic ones. While this fixes the upload issue, it may inadvertently remove needed files from legitimate Rust packages.

    Recommendation: Make filtering more targeted (e.g., only filter kornia-rs paths) or document why global filtering is safe.

Low Priority / Nitpicks

  1. nix/versions.nix - Inconsistent comment style: Comments use both "#" and multi-line format inconsistently.

  2. flake.nix:52 - Redundant allowUnfree in CUDA-disabled builds: Not harmful, just redundant.

  3. nix/packages.nix:159-163 - Complex conditional for kornia could use helper variable for readability.

🎯 Best Practices Observed

  1. Nix best practices:

    • ✅ Proper use of writeShellApplication for launcher
    • ✅ Version pinning with hashes for reproducibility
    • ✅ Platform-specific conditionals using lib.optionalAttrs
    • ✅ Derivation passthru attributes for downstream consumers
  2. Documentation:

    • ✅ CLAUDE.md and README.md updated consistently
    • ✅ Breaking changes clearly documented
    • ✅ Migration path provided for users
  3. CI/CD:

    • ✅ Docker builds maintained for both CPU and CUDA
    • ✅ Multi-architecture support (amd64/arm64)

🔒 Security Considerations

  • No security issues identified
  • Pre-built wheels are fetched from official pytorch.org (not arbitrary PyPI packages)
  • Hashes are pinned, ensuring reproducibility and preventing supply chain attacks
  • No new environment variable exposures or unsafe operations

📊 Performance Considerations

Massive improvements:

  • Build time: Hours → Minutes
  • Memory usage: 30-60GB → <8GB
  • Download size: Comparable (~2GB wheels vs source compilation dependencies)
  • Runtime performance: Unchanged (same PyTorch version 2.5.1)

✅ Test Coverage Assessment

The test plan is thorough:

  • ✅ Platform coverage (macOS ARM, Linux x86_64)
  • ✅ Feature coverage (CPU, CUDA, MPS, Docker)
  • ✅ Integration testing (SDXL inference, nix flake check)

Recommendation: Consider adding a test for the removed architecture-specific packages to ensure users get clear error messages if they try to use the old package names.

📝 Recommendations

Required for Merge

None - The PR is ready to merge as-is. All issues found are minor.

Suggested Improvements (Post-merge)

  1. Add helper function for kornia platform check to reduce complexity
  2. Consider more targeted Cargo file filtering in cachix script
  3. Add deprecation warnings for removed cuda-sm* packages in overlay (optional)

🎉 Conclusion

APPROVE

This is an excellent PR that represents a significant improvement to the project:

  • Solves major pain point (long CUDA build times)
  • Reduces complexity (removes 7 packages, simplifies module options)
  • Maintains compatibility (Docker images, NixOS module)
  • Well-tested and documented
  • No significant issues found

The switch to pre-built PyTorch wheels is the right technical choice and is implemented cleanly. The code quality is high with good documentation and proper Nix patterns throughout.

Great work! 🚀


Review generated based on CLAUDE.md guidelines and Nix best practices

@jamesbrink jamesbrink merged commit 6e5ae42 into main Jan 3, 2026
10 of 13 checks passed
@jamesbrink jamesbrink deleted the update-comfyui-v0.7.0 branch January 3, 2026 02:26
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