huggingface / huggingface/diffusers
Fix skipped `test_model_xattn_padding` test by updating mask padding logic
- Lenguaje dominante
- Python
- Estrellas
- 34.5k
- Forks
- 7.3k
- Merge medio
- 3 d 3 h
- PR fusionados (30 d)
- 91
Descripción
### **Title:**
Fix skipped `test_model_xattn_padding` test by updating mask padding logic
### **Description:**
Currently, there is a skipped test in `tests/models/unets/test_models_unet_2d_condition.py` regarding cross-attention mask padding (`test_model_xattn_padding`).
The test is currently skipped with the following reason:
> *"we currently pad mask by target_length tokens (what unclip needs), whereas stable-diffusion's cross-attn needs to instead pad by remaining_length."*
This is reflected by a dangling `TODO` in `src/diffusers/models/attention_processor.py` inside `prepare_attention_mask` (around line 740):
```python
# TODO: for pipelines such as stable-diffusion, padding cross-attn mask:
# we want to instead pad by (0, remaining_length), where remaining_length is:
# remaining_length: int = target_length - current_length
# TODO: re-enable tests/models/test_models_unet_2d_condition.py#test_model_xattn_padding
attention_mask = F.pad(attention_mask, (0, target_length), value=0.0)
```
### **Expected Behavior / Proposed Solution:**
1. Update `prepare_attention_mask` in `attention_processor.py` (and any other relevant `attention.py` files) to pad the mask by `remaining_length = target_length - current_length`.
2. Ensure the MPS `torch.zeros()` hack is also updated to pad by `remaining_length` rather than `target_length`.
3. Verify that these changes do not break existing `unclip` tests/pipelines.
4. Remove `@pytest.mark.skip` from `test_model_xattn_padding` in `tests/models/unets/test_models_unet_2d_condition.py` to re-enable it.
### **Relevant Files:**
- `src/diffusers/models/attention_processor.py`
- `tests/models/unets/test_models_unet_2d_condition.py`
@sayakpaul If this is indeed technical debt that needs fixing, I would be happy to put together a PR to update the logic and re-enable the test myself!
Guía de contribución
Línea de trabajo
Lee primero prepare_attention_mask en src/diffusers/models/attention_processor.py y la prueba omitida en tests/models/unets/test_models_unet_2d_condition.py; sigue las rutas de current_length, target_length y el padding de MPS. Ejecuta test_model_xattn_padding y las pruebas o pipelines relevantes de unclip; la tarea estará terminada cuando la prueba vuelva a estar habilitada y pase sin regresiones.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python, pytorch
- Área
- machine-learning, testing
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Activo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 55/100