huggingface / huggingface/diffusers

Fix skipped `test_model_xattn_padding` test by updating mask padding logic

Aperta
#14,699 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug models needs-code-example needs-env-info
Lingua principale
Python
Stelle
34.5k
Fork
7.3k
Merge medio
3g 3h
PR unite (30g)
91

Descrizione

### **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!

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Read prepare_attention_mask in src/diffusers/models/attention_processor.py and the skipped test in tests/models/unets/test_models_unet_2d_condition.py first; trace the current_length, target_length, and MPS padding paths. Run test_model_xattn_padding and the relevant unclip tests or pipelines; done means the test is re-enabled and passes without regressions.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python, pytorch
Ambito
machine-learning, testing
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Specificata chiaramente
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.