- Add explicit .to(device) after extracting ID embeddings in _register_character
- Add device check and migration in _generate_with_consistency before inference
- Fixes RuntimeError: Expected all tensors to be on the same device
fix: Change torch.compile mode to default for thread-safety
- Changed mode from reduce-overhead to default in _apply_torch_compile()
- This fixes AssertionError in CUDA Graph TLS when handling concurrent requests
- HuggingFace Inference Endpoints use multi-threaded request handling
- CUDA Graphs (used by reduce-overhead) have thread-local storage issues
- mode=default still provides graph optimization, operator fusion, and Triton kernels
- See: https://github.com/pytorch/pytorch/issues/123177
feat: Add H200 batch processing support (batch_size=4, torch.compile)
fix: offload FLUX model and AE to CPU after initialization
kkytai
b43773a
ROOT CAUSE: PuLID's load_flow_model() and load_ae() have a bug where they
ignore the device parameter. Even when device='cpu' is passed, models are
created on CUDA because there's no explicit .to(device) call.
Previous fix only offloaded T5 and CLIP, but the main FLUX transformer (~24GB)
and AutoEncoder (~1GB) remained on GPU, causing OOM.
Now all models are explicitly moved to CPU after FluxGenerator initialization:
- FLUX transformer model (~24GB)
- AutoEncoder (~1GB)
- T5 encoder (~10GB)
- CLIP encoder (~2GB)
- PuLID components (~10GB)
Expected post-init GPU memory: < 1GB (was 77GB+)
fix: enable aggressive_offload for A100 80GB to prevent OOM
kkytai
e3fd6ed
Root cause: With aggressive_offload=False, the full FLUX transformer model
was being loaded to GPU via model.to(device) (~24GB), causing OOM on A100 80GB.
Changes:
1. Changed aggressive_offload threshold from < 50GB to < 90GB
- Now A100 80GB uses components_to_gpu() instead of model.to(device)
- This loads only necessary components per step, minimizing memory
2. Added T5/CLIP offload immediately after FluxGenerator initialization
- get_models() always loads T5/CLIP to GPU regardless of offload mode
- Now immediately moved to CPU to free ~12GB
3. Strengthened _offload_all_models() with proper setattr and error handling
- Ensures model references are properly updated after .cpu()
- Individual error handling prevents one failure from blocking others
Expected post-init GPU memory: < 5GB (was 35GB+)
fix: add explicit model offloading to prevent OOM errors
kkytai
1628dbf
Added _offload_all_models() method that explicitly moves all models to CPU:
- Main transformer model
- Text encoders (T5, CLIP)
- Autoencoder (encoder/decoder)
- PuLID face analysis components
Now called before:
- Character registration (before moving PuLID to GPU)
- Image generation with consistency
- Normal image generation
This ensures GPU memory is freed before each major operation,
preventing OOM when models accumulate on GPU after previous operations.
fix: move PuLID components to GPU before ID embedding extraction
kkytai
11d85c0
When offload mode is enabled, PuLID face analysis components stay on CPU.
The _register_character method was calling get_id_embedding without first
moving these components to GPU, causing a device mismatch error:
'Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor)'
Now properly calls components_to_device(cuda) before ID extraction and
moves back to CPU afterwards to maintain memory efficiency.
fix: increase offload threshold to 90GB for A100-SXM4-80GB
kkytai
d820660
A100-SXM4-80GB reports 85.1GB via torch.cuda.get_device_properties(),
so the previous threshold of < 85 didn't trigger offload mode.
Increased to < 90 to ensure offload is enabled for 80GB class GPUs.
fix: Enable CPU offload for A100 80GB to prevent OOM
kkytai
da45f94
- Change offload threshold from 70GB to 85GB (includes A100 80GB)
- Add memory cleanup after model initialization
- Issue: Models consumed ~77GB leaving no room for inference
fix: Add memory cleanup to prevent CUDA OOM errors
kkytai
65a4b73
- Add _cleanup_memory() method with gc.collect() and torch.cuda.empty_cache()
- Call cleanup before/after batch processing
- Call cleanup after each image generation
- Force cleanup on errors
- Clean up when GPU memory usage exceeds 85%
fix: Patch app_flux.py to remove gradio dependency