Reduce temporary CPU allocations when converting PIL conditioning batches
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Refactorización
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- numpy, python
- Área
- performance
Línea de trabajo
The target is VaeImageProcessor.pil_to_numpy in the image processor module, which converts each PIL image to a normalized float32 array before stacking. Read that method and its callers in the ControlNet and video preprocessing paths, then benchmark a small batch before and after. Done means a single float32 batch is built and normalized in place, with existing tests for the image processor still passing and no change to public signatures or outputs. The author already has a local patch, but the issue is unassigned and the maintainers have not yet approved the approach.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is your feature request related to a problem? Please describe.
VaeImageProcessor.pil_to_numpy currently converts each PIL image into a separate normalized float32 array before stacking them into another float32 batch. This creates unnecessary intermediate allocations when processing multiple images. The method is shared by preprocessing paths used in ControlNet and video pipelines.
Describe the solution you'd like.
Construct a single float32 batch from the input pixel arrays and normalize it in place, avoiding per-image normalized float32 arrays and an additional full-batch copy. The change would preserve existing model computations, public signatures, and supported input/output behavior.
I've already implemented and validated a minimal local patch.
Describe alternatives you've considered.
Keeping the current per-image conversion and stacking preserves existing behavior but retains the unnecessary allocations. The proposed optimization avoids them without changing the API.
Additional context.
I benchmarked the optimization on Diffusers main (c215605a189169236544c1c9828789bfca0891d1) using an Intel Xeon Gold 6248R CPU, one thread, PyTorch 2.7.1+cpu, NumPy 2.2.6, and Pillow 11.3.0.
| Workload | Original | Optimized | Improvement |
|---|---|---|---|
| 8 × 1024×1024 RGB ControlNet conditioning images | 119.35 ms | 71.09 ms | 40.4% lower latency |
| 49-frame 512×512 normalized video preprocessing | 369.81 ms | 315.87 ms | 14.6% lower latency |
| Peak sampled process RSS, 8-image workload | 584.4 MiB | 494.8 MiB | 15.3% lower |
Measurements included warmups and multiple timed samples. I used codex to help investigate and implement this optimization.
Would the maintainers consider this CPU preprocessing optimization appropriate for Diffusers? I'd be happy to contribute the patch I've already prepared if the approach is approved and the issue is assigned to me.
- Lenguaje dominante
- Python
- Estrellas
- 35k
- Forks
- 7.5k
- Merge medio
- 2 d 22 h
- PR fusionados (30 d)
- 58
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de huggingface/diffusers
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
huggingface/diffusers#15436 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
InpaintProcessor crashes when padding_mask_crop is set and a dimension is omittedPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
huggingface/diffusers#15433 ·
Los mantenedores suelen responder en 1 día
-
LTXEulerAncestralRFScheduler skips signal scaling with s_noise=0Posiblemente ocupada @hparik11 la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
huggingface/diffusers#15423 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Docs: 13 docstrings document parameters their functions don't havePosiblemente ocupada @M-Colley la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
huggingface/diffusers#15363 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
`ZImageImg2ImgPipeline` / `ZImageInpaintPipeline`: explicit height/width different from the input image raises RuntimeErrorPosiblemente ocupada @chessing234 la tomó hace 11 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
huggingface/diffusers#15337 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de huggingface/diffusers
Issues similares
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount duePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 79/100
developmentseed/titiler-covjson#164 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
awslabs/visual-asset-management-system#2164 ·
Los mantenedores suelen responder en 1 día
-
needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
MakazhanAlpamys/Soup#3589 ·
Los mantenedores suelen responder en 1 día
-
channels status reports the wrong Enabled value for Feishu instances and default-enabled WebSocketAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
Los mantenedores suelen responder en 1 día