39 Commits
Author SHA1 Message Date
FearL0rd 9aba0997ac fix: multi-GPU device mismatch, OOM, and LoRA on split batches
Keep replica blocks out of the nn.Module tree so model.to(cuda:0) cannot steal cuda:1 weights. Reuse the live home GPU model, skip wrapping it so ComfyUI can apply LoRA, and bake adapters only onto independent clones. Preserve operations in clone config for the fast incremental path.
2026-08-13 13:44:06 -05:00
FearL0rd 9337a4560d Clarify RuntimeError handling in README
Updated instructions for handling RuntimeError related to tensors and GPU usage.
2026-02-23 19:05:17 -06:00
FearL0rd eec4db2bf7 Merge branch 'main' of https://github.com/FearL0rd/ComfyUI-ParallelAnything 1.0.11 2026-02-23 07:44:40 -06:00
FearL0rd 12b65a0154 Fix Data Parallelism to work with LoRA
BREAKING CHANGE: Replaces model.forward with parallel_forward; stores original in
_original_forward. Requires model patch_model() to be called before setup if using LoRA.
2026-02-23 07:44:04 -06:00
FearL0rd ec05cbb2cd Merge pull request #4 from FearL0rd/test
Fixed Lora Support
2026-02-23 07:30:17 -06:00
FearL0rd a66cadb917 Implement ParallelAnything - True Multi-GPU Pipeline/Data Parallelism fix LoRA
Adds comprehensive multi-device inference support for ComfyUI diffusion models:

Core Features:
- **Dual-mode execution**: Pipeline Parallelism (Batch=1) distributes layers across devices;
  Data Parallelism (Batch>1) splits batches across device replicas with ThreadPoolExecutor
- **Heterogeneous device support**: CUDA, MPS, XPU, DirectML, and CPU in any combination
- **Automatic LoRA/Hook preservation**: Detects ComfyUI patches (model.patches/model_patcher.patches),
  applies them before cloning to ensure LoRA weights propagate to all replicas
- **Intelligent model cloning**: Three-tier fallback (config reconstruction → incremental state_dict 
  → manual recursive) with automatic FP8→FP16 conversion for pre-SM90 GPUs

Memory & Performance:
- **Aggressive VRAM management**: Automatic cache clearing, stream-based async execution,
  and optional model purging on cleanup
- **Flash Attention safety**: Auto-disables xFormers/Flash Attention for GPUs < SM80
- **Flux optimization**: Clears rope/freqs_cis/img_ids caches before cloning to prevent device mismatches

Technical Implementation:
- Thread-local pipeline mode state for safe nested execution
- ParallelBlock wrapper handles cross-device tensor movement (including dataclasses/lists/dicts)
- Weakref finalization ensures cleanup even if node is deleted
- ComfyUI integration: Preserves load_device tracking and handles diffusion_model wrappers

Nodes Added:
- ParallelAnything: Main processing node
- ParallelDevice: Chainable device configuration
- ParallelDeviceList: Quick 1-4 device preset configuration

BREAKING CHANGE: Replaces model.forward with parallel_forward; stores original in 
_original_forward. Requires model patch_model() to be called before setup if using LoRA.
2026-02-21 21:37:18 -06:00
FearL0rd 85b20bcd0c Update print statement from 'Hello' to 'Goodbye' 2026-02-21 18:49:38 -06:00
FearL0rd 36f1d67c4d Merge pull request #3 from FearL0rd/test
Implement Model Parallelism (Pipeline) for batch_size=1 & Fix Multi-GPU Device Mismatches
1.0.10
2026-02-16 08:13:34 -06:00
FearL0rd b0938a4543 Bump version to 1.0.10 and add Icon URL
Updated version number from 1.0.9 to 1.0.10 and added Icon URL.
2026-02-16 07:51:02 -06:00
FearL0rd 04907c683f Implement Model Parallelism (Pipeline) for batch_size=1 & Fix Multi-GPU Device Mismatches
Feature (Pipeline Parallelism): implemented logic to handle batch_size=1 by splitting transformer blocks across GPUs.

Introduced ParallelBlock wrapper to manage execution across devices.

Data now flows in a pipeline sequence (e.g., GPU0 → GPU1 → ...) and automatically returns to the Lead Device for final processing.

Maintains original Data Parallel (batch splitting) behavior for batch_size > 1.

Fix (Device Mismatch): Resolved RuntimeError: Expected all tensors to be on the same device.

Updated ParallelBlock to recursively identify and move all input arguments (tensors, nested lists/tuples, dicts, and dataclasses) to the target device, rather than just the first argument.

Ensured auxiliary inputs (like timesteps and context) are correctly transferred alongside the main hidden states.

Fix (Syntax): Fixed a SyntaxError in clone_dataclass_or_object where a try block was missing its corresponding except.

Refactor: Improved tensor movement logic to be "deep" and recursive, preventing crashes when models use complex input structures.
2026-02-13 14:00:26 -06:00
FearL0rd 50b6fd1f74 Version Increase 1.0.9 2026-02-12 14:14:20 -06:00
FearL0rd 9d56104932 Bug Fixes 2026-02-12 12:19:38 -06:00
FearL0rd 309db10504 Merge branch 'main' of https://github.com/FearL0rd/ComfyUI-ParallelAnything 1.0.7 2026-02-07 11:54:18 -06:00
FearL0rd 0644b55d4b Adds is_float8_dtype() helper to detect any FP8 format (e4m3fn, e5m2, e4m3fnuz, e5m2fnuz) and automatically convert to FP16 when targeting devices without native FP8 support (< SM90).
This fixes compatibility with models like LTX-Video, Wan, and others that may use different FP8 encoding schemes (particularly e5m2) on mixed GPU setups.

Changes:
- Add is_float8_dtype() to detect all PyTorch FP8 variants
- Update clone_module_simple() to handle FP8 in layer reconstruction and generic fallback
- Update safe_model_clone() to post-process all FP8 variants during incremental loading
- Update move_to_device() to convert FP8 inputs at runtime during parallel inference
- Ensure consistent FP8→FP16 conversion across weights, buffers, and activation tensors

Preserves FP8 performance on Hopper/Ada (SM90+) while ensuring compatibility with Ampere and older architectures that only support FP16/FP32 computation.

Fixes: Support for LTX-Video, Wan, and other FP8 models using e5m2 or alternative FP8 formats on mixed-GPU setups
2026-02-07 11:54:14 -06:00
FearL0rd 3058b658d5 Update README to include WAN2.2 in tested models 2026-02-06 15:11:51 -06:00
FearL0rd f74eae7e64 Multiple Fixes and WAN Support
Fixed infinite recursion: Added check if hasattr(replica, '_original_forward') and replica is target_model in the worker to use the original forward method when the replica is the original model, preventing parallel_forward from calling itself recursively.

Device reference safety: Converted devices_ref and weights_ref to tuples to prevent accidental modification after assignment.

Explicit device comparison: Used replica is target_model to detect when we're using the original model vs a clone.

Consistent fallback handling: Both the single-device fallback and the OOM fallback now check for _original_forward to use the correct method.

Better logging: Added explicit print at the end showing which devices are actually being used.

This ensures that when CUDA:0 is the original device and CUDA:1 is a clone, both are used correctly without the original device causing a recursive loop.
1.0.6
2026-02-06 15:09:08 -06:00
FearL0rd 5fca7fa289 Critical memory optimization for Parallel Anything node to prevent CUDA out-of-memory errors on first execution and improve stability across multi-GPU setups.
Critical memory optimization for Parallel Anything node to prevent CUDA out-of-memory
errors on first execution and improve stability across multi-GPU setups.

Problem:
- First-run OOM errors occurred due to CUDA memory fragmentation and holding
  duplicate model copies (CPU + GPU) simultaneously during cloning
- No handling for devices that failed during cloning due to insufficient VRAM
- Original model restoration caused temporary 2x VRAM usage spikes

Solution:
- Skip cloning when target device matches source device (use reference)
- Incremental state_dict loading to minimize peak memory usage
- Aggressive ComfyUI model cache unloading before cloning operations
- Progressive cleanup between device clones with synchronized CUDA operations
- Graceful degradation: skip OOM devices and redistribute workload

Technical Changes:
- Added aggressive_cleanup() helper for forced GC and CUDA cache clearing
- Modified safe_model_clone() with incremental parameter loading and
  early-exit if model already on target device
- Updated setup_parallel() to use reference counting for original device
- Implemented successful_devices tracking for OOM fallback handling
- Added periodic torch.cuda.empty_cache() during large model transfers
- Enhanced error handling with device-level try/except blocks
- Fixed state dict parsing for nested modules in incremental loading

Memory optimizations:
- Unload ComfyUI models (unload_all_models) before cloning
- Delete state_dict entries immediately after transfer
- Force CPU transition only when necessary (not when reusing original)
- Synchronize CUDA devices before/after memory operations

Breaking Changes: None
Backwards Compatible: Yes
1.0.5
2026-02-06 11:28:21 -06:00
FearL0rd 6b1dd775f7 Fix V100 + 3090 timing in README
Updated the time for V100 + 3090 from 13.72s/it to 12.91s/it.
2026-02-05 10:28:11 -06:00
FearL0rd 600ad8d4ca Update image in README.md for V100 + 3090 2026-02-05 10:26:50 -06:00
FearL0rd 260468038e Update README with RuntimeError troubleshooting tip
Added troubleshooting tip for RuntimeError related to tensor device mismatch.
2026-02-05 09:36:07 -06:00
FearL0rd 6a8a99fcb4 Added VRAM purge toggles
Added VRAM purge toggles to INPUT_TYPES:

purge_cache: Clears CUDA cache during cleanup (default: True)
purge_models: Aggressively unloads all models from VRAM using comfy.model_management.unload_all_models() (default: False)
Updated setup_parallel method signature to accept purge_cache and purge_models parameters

Store purge preferences on the model: target_model._parallel_purge_cache and target_model._parallel_purge_models

Enhanced cleanup_parallel_model function to:

Read the purge flags from the model attributes
Conditionally run comfy.model_management.unload_all_models() if purge_models is True
Conditionally clear CUDA cache and soft empty cache based on purge_cache setting
Multi-GPU cache clearing (iterates through all CUDA devices)
The purge settings persist with the model and are applied when the parallel processing resources are cleaned up (either when the node is re-run with new settings or when the model is garbage collected).
1.0.4
2026-02-04 16:24:57 -06:00
FearL0rd 838052e0ff Added VRAM purge toggles
Added VRAM purge toggles to INPUT_TYPES:

purge_cache: Clears CUDA cache during cleanup (default: True)
purge_models: Aggressively unloads all models from VRAM using comfy.model_management.unload_all_models() (default: False)
Updated setup_parallel method signature to accept purge_cache and purge_models parameters

Store purge preferences on the model: target_model._parallel_purge_cache and target_model._parallel_purge_models

Enhanced cleanup_parallel_model function to:

Read the purge flags from the model attributes
Conditionally run comfy.model_management.unload_all_models() if purge_models is True
Conditionally clear CUDA cache and soft empty cache based on purge_cache setting
Multi-GPU cache clearing (iterates through all CUDA devices)
The purge settings persist with the model and are applied when the parallel processing resources are cleaned up (either when the node is re-run with new settings or when the model is garbage collected).
2026-02-04 16:21:57 -06:00
FearL0rd db7f7b98b4 Update README with PC specs for test case
Added PC specifications for test case with batch size 21.
2026-02-04 16:17:13 -06:00
FearL0rd febd49127a Update test case details in README.md 2026-02-04 16:10:35 -06:00
FearL0rd b2c3852cbf Update test case description in README.md 2026-02-04 15:21:49 -06:00
FearL0rd f0485b38b4 Update README with test case results for batch size 21
Added test case results for batch size of 21, including performance metrics for Single 3090 and V100 + 3090 setups.
2026-02-04 15:20:49 -06:00
FearL0rd 6362d3c2aa Multiple Fixes
Fixed Memory Leaks: Added explicit cleanup of partial replicas if cloning fails mid-process
Better Error Handling: Exception handling in worker() now properly returns exceptions rather than raising, allowing cleanup of other threads
Thread Safety: Removed unused imports and ensured proper synchronization points for CUDA/XPU devices
Robust Splitting: Fixed split_batch to handle mixed lists of tensors and non-tensors correctly
Cleanup Safety: cleanup_parallel_model now handles cases where the model was partially initialized
VRAM Management: Added soft_empty_cache calls between cloning operations to prevent OOM when cloning to multiple devices
Management: Added auto balance to improve performance
Attribute Handling: Improved clone_module_simple to better handle missing attributes in layer reconstruction
Config Extraction: Added serialization check to extract_model_config to prevent storing non-serializable objects
1.0.3
2026-02-04 09:39:26 -06:00
FearL0rd 8a3085da78 Critical Bug Fixes / Improvements / Optimizations
Critical Bug Fixes:
Memory Leak: weakref.finalize now uses weakref.ref(target_model) instead of direct reference
Race Condition: Worker threads now return exceptions instead of raising them, allowing proper aggregation and cleanup
Batch Validation: get_batch_size() now validates consistent batch dimensions across tensor lists
Double Device Transfer: Removed .to(device) from split_kwargs(), now only happens in worker()
Attribute Handling: Cleaner separation of in_features vs in_channels in layer cloning
Improvements Added:
CUDA Streams: Each GPU now uses its own CUDA stream for true parallel execution
Auto VRAM Balance: New auto_vram_balance parameter adjusts splits based on available VRAM (70% user preference / 30% availability)
Gradient Checkpointing: Automatically disabled on replicas to save VRAM
Accelerate Hooks: Clears _hf_hook and hooks attributes for compatibility with accelerate offloading
Enhanced Cache Clearing: Added rope_cache and freqs_cis_cache to FLUX cleanup
Thread Safety: Proper executor context management and result validation
Performance Optimizations:
Non-blocking transfers where safe
Synchronization only on CUDA/XPU devices
Batch size auto-adjustment prevents OOM on uneven GPU setups
1.0.2
2026-02-03 15:35:03 -06:00
FearL0rd 1b5b638372 Add LTX-2 Video and multi-output model support 2026-02-03 10:49:47 -06:00
FearL0rd 1941751cba Add LTX-2 Video and multi-output model support
Fixed "'list' object has no attribute 'shape'" error when using 
LTX-2 Video and other diffusion models that return tuples/lists 
instead of single tensors.

Key changes:
- Added tensor container helpers: get_batch_size(), split_batch(), 
  move_to_device(), concatenate_results()
- parallel_forward now handles list/tuple inputs/outputs (common in 
  video models with temporal conditioning)
- Enhanced split_kwargs() to split list-of-tensors kwargs 
  (frame-wise embeddings, temporal IDs)
- Results are now properly concatenated whether model returns 
  Tensor, Tuple[Tensor, ...], or List[Tensor]

Tested working with: FLUX, SD3.5, LTX-2 Video, HunyuanVideo
VRAM: Maintains existing N× model replication strategy
Breaking: None (backward compatible with single-tensor outputs)
2026-02-03 10:48:52 -06:00
FearL0rd 8609d32b4f Add FLUX.1 to tested platforms in README
Updated README to reflect testing on additional platforms.
1.0.1
2026-02-03 08:35:01 -06:00
FearL0rd aebce4f889 Bump version to 1.0.1 in pyproject.toml 2026-02-03 08:34:42 -06:00
FearL0rd c32d55ac02 Flux Compatibility 2026-02-03 08:34:14 -06:00
FearL0rd 6069d2c560 Update README.md 2026-02-02 16:28:16 -06:00
FearL0rd 274c1b7cf3 Add 'copy' to requirements.txt 1.0.0 2026-02-02 11:04:30 -06:00
FearL0rd b2919663cd icon 2026-02-02 11:00:44 -06:00
FearL0rd 616832a180 Remove copyright notice from README
Removed copyright notice from README.
2026-02-02 10:57:45 -06:00
FearL0rd 8bfee3f7df Add README for Parallel Anything multi-GPU support
Add comprehensive documentation for Parallel Anything nodes in ComfyUI, detailing features, installation, usage, performance tips, troubleshooting, architecture, and limitations.
2026-02-02 10:56:22 -06:00
FearL0rd e39e19fc46 initial release 2026-02-02 10:48:52 -06:00