# UserWarning: You are using a decoder-only model with padding_side='right'. This may produce incorrect results. Consider setting padding_side='left'.

- **ID:** `huggingface/tokenizer-padding-side-mismatch`
- **Domain:** huggingface
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

Decoder-only models (like GPT, LLaMA) expect padding on the left side to maintain causal attention masking; right padding causes the model to attend to padding tokens at the end of sequences.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| transformers>=4.30.0 | active | — | — |
| tokenizers>=0.14.0 | active | — | — |

## Workarounds

1. **Set padding_side to 'left' before tokenization: `tokenizer.padding_side = 'left'; tokenizer.pad_token = tokenizer.eos_token; inputs = tokenizer(texts, padding=True, truncation=True, return_tensors='pt')`** (95% success)
   ```
   Set padding_side to 'left' before tokenization: `tokenizer.padding_side = 'left'; tokenizer.pad_token = tokenizer.eos_token; inputs = tokenizer(texts, padding=True, truncation=True, return_tensors='pt')`
   ```
2. **Use the tokenizer's `__call__` with the `padding_side` parameter: `tokenizer(texts, padding=True, truncation=True, padding_side='left', return_tensors='pt')`** (90% success)
   ```
   Use the tokenizer's `__call__` with the `padding_side` parameter: `tokenizer(texts, padding=True, truncation=True, padding_side='left', return_tensors='pt')`
   ```
3. **If using a pipeline, set padding_side via the tokenizer: `from transformers import pipeline; pipe = pipeline('text-generation', model='gpt2', tokenizer=tokenizer); pipe.tokenizer.padding_side = 'left'`** (85% success)
   ```
   If using a pipeline, set padding_side via the tokenizer: `from transformers import pipeline; pipe = pipeline('text-generation', model='gpt2', tokenizer=tokenizer); pipe.tokenizer.padding_side = 'left'`
   ```

## Dead Ends

- **Setting `padding_side='right'` explicitly to suppress the warning** — This does not fix the underlying issue; the model still produces incorrect outputs due to attention mask misalignment. (90% fail)
- **Using a different tokenizer without changing padding_side** — All decoder-only tokenizers have the same requirement; the warning will persist or outputs will be wrong. (70% fail)
- **Adding `attention_mask` manually without changing padding_side** — Even with an attention mask, right padding causes the model to attend to padding tokens in the causal mask, leading to degraded generation. (80% fail)
