Add CPU inference support with automatic CUDA fallback #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds comprehensive CPU support for inference operations while maintaining full backward compatibility with CUDA workflows. The changes enable ChronoEdit to run on systems without GPU access by providing graceful fallback mechanisms.
Key Changes
1. New Central Device Management Module (chronoedit/utils/device_utils.py)
2. Prompt Enhancer Updates (scripts/prompt_enhancer.py)
3. Inference Script Enhancements (scripts/run_inference_diffusers.py)
4. Pipeline CPU Compatibility (chronoedit_diffusers/pipeline_chronoedit.py)
5. Device Utility Hardening (chronoedit/_ext/imaginaire/utils/device.py)
6. Test Infrastructure
Design Principles
Usage Examples
Auto-detect (CUDA if available, else CPU with warning) python scripts/run_inference_diffusers.py --input image.png --prompt "..." --output out.mp4
Explicit CPU
python scripts/run_inference_diffusers.py --device cpu --input image.png --prompt "..." --output out.mp4
Explicit CUDA (with auto-fallback to CPU if unavailable) python scripts/run_inference_diffusers.py --device cuda --input image.png --prompt "..." --output out.mp4
Testing
Run the test script to verify CPU inference:
bash test_cpu_inference.sh cpu
Notes
Files Modified
Tested on: PyTorch 2.7.1+cu126 with CUDA unavailable
Environment: chronoedit_mini conda environment