Commit Graph
1 Commits
Author SHA1 Message Date
google-labs-jules[bot] f49f65a196 ⚡ Bolt: Optimize tensor-to-numpy image conversion
💡 What:
- Created `discordsend_utils/image_processing.py` with `tensor_to_numpy_uint8` helper function.
- Replaced naive `np.clip(255 * tensor.numpy(), ...)` conversions with PyTorch-optimized operations in `discord_image_node.py` and `discord_video_node.py`.

🎯 Why:
- The previous naive implementation converted float tensors to large float64 numpy arrays on CPU before clipping and casting to uint8. This was memory inefficient and slower.
- Moving scaling, clamping, and casting to PyTorch (potentially GPU) before moving to CPU reduces memory transfer and CPU load.

📊 Impact:
- ~70% faster image conversion from tensor to numpy array.
- Significantly reduced memory usage during video processing loops.

🔬 Measurement:
- Verified via `python -m unittest discover tests`.
- Verified tensor output correctness manually.
2026-01-16 01:17:02 +00:00