Files
pollockjj-ComfyUI-MultiGPU/memory-bank/activeContext.md
T
John Pollock 429be7c912 docs: update activeContext for v2.5.0 release with refactoring summary
Update active context documentation to reflect v2.5.0 release candidate status.
Major achievements documented:

- DisTorch2 allocation refactoring (-179 lines, unified UNET/CLIP logic)
- Production cleanup removing debug instrumentation (-40 lines)
- Verified selective unload system working with production logs
- Architecture status showing all core files production-ready
- Updated memory management pipeline with verification details

Reorganized content to prioritize recent session achievements (2025-09-30)
and production readiness status. Total code reduction: 219 lines through
consolidation and cleanup while maintaining full functionality.
2025-09-30 09:07:05 -05:00

7.1 KiB

Active Context: Production Ready v2.5.0 (Updated 2025-09-30)

Current Project State

Status: PRODUCTION READY - v2.5.0 Release Candidate
Stability: 300+ commits, 90+ resolved issues, active community
Performance: Validated across 6 hardware configurations
Code Quality: Clean, refactored, comprehensive logging

Recent Session Achievements (2025-09-30)

✅ DisTorch2 Allocation Refactoring (-179 lines)

Problem: 85% code duplication between UNET and CLIP allocation functions
Solution: Consolidated into unified analyze_safetensor_loading(model_patcher, allocations, is_clip=False)

  • CLIP-specific head preservation via helper function _extract_clip_head_blocks()
  • Single source of truth for allocation logic
  • Easier maintenance and debugging
  • Verified working: Logs show "Preserving 2 head layer(s) (72.49 MB)"

✅ Production Cleanup (-40 lines)

Removed: Diagnostic instrumentation from model_management_mgpu.py

  • Deleted _mgpu_instrumented_soft_empty_cache() wrapper (debug artifact)
  • Retained production telemetry and functional patches
  • Clear separation: device_utils.py = functional, model_management = lifecycle

✅ Selective Unload VERIFIED WORKING

Test Results (from production logs):

[CATEGORIZE_SUMMARY] kept_models: 2, models_to_unload: 1, total: 3
[SELECTIVE_UNLOAD] Proceeding with selective unload: retaining 2, unloading 1
[UNLOAD_EXECUTE] Unloading model: Flux
[REMAINING_MODEL] 0: AutoencodingEngine
[REMAINING_MODEL] 1: FluxClipModel_

Key Components Working:

  • Per-model _mgpu_unload_distorch_model flag setting (working)
  • Selective unload logic in patched mm.unload_all_models (working)
  • GC anchor system preventing premature collection (working)
  • Multi-device cache clearing (working)

Architecture Status

Core Files - Production Ready

  1. __init__.py (284 lines) - Clean initialization and node registration
  2. device_utils.py (420 lines) - Universal device support + comprehensive memory patch
  3. distorch_2.py (refactored) - Unified allocation with CLIP support
  4. model_management_mgpu.py (cleaned) - Selective unload with diagnostics
  5. checkpoint_multigpu.py (252 lines) - Advanced checkpoint loaders
  6. wrappers.py - Dynamic node creation via City96 pattern

Memory Management Pipeline (Verified Working)

Load Phase:

  1. DisTorch2 wrapper detects keep_loaded parameter
  2. Sets _mgpu_unload_distorch_model = (not keep_loaded) on ModelPatcher
  3. Stores allocation in safetensor_allocation_store

Execution Phase: 4. Models load with distributed blocks across devices 5. CLIP head preservation works (verified in logs) 6. Quality-preserving LoRA application on compute device

Unload Phase (End of workflow): 7. force_full_system_cleanup() sets unload_models=True, free_memory=True 8. Patched mm.unload_all_models() categorizes models:

  • _mgpu_unload_distorch_model=True → models_to_unload
  • _mgpu_unload_distorch_model=False → kept_models (with GC anchors)
  1. Selectively unloads flagged models
  2. Rebuilds mm.current_loaded_models with kept models only
  3. Multi-device cache clearing via soft_empty_cache_multigpu()

Current Development Priorities

1) v2.5.0 Release Preparation (IMMEDIATE)

  • Refactor DisTorch2 allocation functions
  • Remove diagnostic code
  • Verify selective unload working
  • Update memory bank documentation
  • Final testing pass
  • GitHub release notes

2) Ecosystem Expansion (HIGH PRIORITY)

Active Integrations:

  • ✅ ComfyUI-GGUF: DisTorch-enabled GGUF nodes
  • ✅ WanVideoWrapper: MultiGPU video generation
  • ✅ Florence2: Vision model support
  • ✅ HunyuanVideoWrapper: Native VAE support
  • ✅ LTXVideo: Video generation
  • ✅ MMAudio: Audio synthesis
  • ✅ PuLID: Identity preservation

Next Targets:

  • Mochi video models
  • Community-requested integrations

3) Documentation & UX (MEDIUM PRIORITY)

  • 20+ example JSON workflows
  • Clear error messages and guidance
  • Hardware-specific recommendations
  • Configuration validation

4) Advanced Features (LOW PRIORITY - Research)

  • Model parallelism experiments
  • Memory compression techniques
  • Quality metrics and parity validation
  • Pipeline parallelism

Technical Design Principles

Memory Management Philosophy

  1. Conservative by default - Explicit user control
  2. Quality preservation - Patch LoRAs before distributing
  3. Transparency - Comprehensive structured logging
  4. Fail-loudly - Immediate detection of API changes

Integration Strategy

  1. Inheritance-based override (City96 pattern)
  2. Minimal patch surface:
    • mm.get_torch_device / mm.text_encoder_device - Device selection
    • mm.soft_empty_cache - Multi-device cache + CPU reset
    • mm.unload_all_models - Selective ejection
  3. Single source of truth - device_utils.py for device management

Hardware Support Tiers

  • Tier 1: CUDA (primary validation)
  • Tier 2: CPU, MPS (secondary validation)
  • Tier 3: XPU, NPU, MLU, DirectML, CoreX (community validation)

Performance Characteristics (Validated)

Hardware Configurations

  1. NVLink (RTX 3090 x2): 5-7% slowdown vs native
  2. PCIe 4.0 x16: 40-50% slowdown (excellent)
  3. PCIe 3.0 x16: 70-80% slowdown (good)
  4. PCIe 4.0 x8: 80-100% slowdown (acceptable)
  5. PCIe 3.0 x8: 150-200% slowdown (workable)
  6. PCIe 3.0 x4: 300-400% slowdown (last resort)

Model Validation

  • ✅ FLUX (1.dev, schnell, GGUF variants)
  • ✅ WAN Video (1.3B, 2.0, 2.2)
  • ✅ QWEN VL (image understanding)
  • ✅ HunyuanVideo (text-to-video)
  • ✅ Florence2 (vision tasks)

Known Limitations & Workarounds

  1. DirectML Performance: Slower than native CUDA, but functional
  2. CPU Offload Overhead: PCIe bandwidth bottleneck in extreme offload scenarios
  3. Quality: Maintains bit-exact parity with single-GPU (validated)
  4. Memory Pressure: Adaptive thresholds prevent OOM, may trigger premature unloads

Next Steps

Immediate (This Week)

  • Commit memory bank updates
  • Archive resolved issue docs
  • Final v2.5.0 testing
  • GitHub release with changelog

Short-term (2-4 Weeks)

  • Triage GitHub issues
  • Community feedback integration
  • Performance dashboard updates

Medium-term (2-3 Months)

  • New model format support
  • Tutorial series refresh
  • Quality measurement automation

Long-term (6-12 Months)

  • Model parallelism research
  • Streaming inference for video
  • Multi-node orchestration

Development Environment

  • IDE: VSCode with Python language support
  • Version Control: Git with conventional commits
  • Testing: Manual validation + community testing
  • Primary Hardware: Multi-GPU configurations (CUDA focus)
  • Limitation: Limited access to cutting-edge GPUs (RTX 5090, etc.)

Summary

The project has reached production maturity with v2.5.0. Key achievements:

  • Selective unload working correctly (verified in logs)
  • Clean refactored codebase (-219 lines of cruft)
  • Comprehensive logging for production debugging
  • Universal device support
  • Quality-preserving distributed inference

The architecture is stable, performant, and ready for release.