# ValueError: Truncation side 'left' is not compatible with padding side 'right' for this model. Set truncation_side='right' or padding_side='left'.

- **ID:** `huggingface/truncation-side-mismatch-with-padding`
- **Domain:** huggingface
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 93%

## Root Cause

The tokenizer's truncation_side and padding_side are set to opposite sides, causing inconsistent token alignment for decoder-only models.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| huggingface/transformers 4.40.0 | active | — | — |
| huggingface/tokenizers 0.17.0 | active | — | — |
| huggingface/transformers 4.41.0 | active | — | — |

## Workarounds

1. **Set tokenizer padding_side to 'left' and truncation_side to 'left' for decoder-only models: `tokenizer.padding_side = 'left'; tokenizer.truncation_side = 'left'` before encoding.** (95% success)
   ```
   Set tokenizer padding_side to 'left' and truncation_side to 'left' for decoder-only models: `tokenizer.padding_side = 'left'; tokenizer.truncation_side = 'left'` before encoding.
   ```
2. **Use `tokenizer(text, padding='max_length', truncation=True, return_tensors='pt')` and let the tokenizer auto-resolve by setting `truncation_side='right'` and `padding_side='left'` via `tokenizer.init_kwargs`.** (85% success)
   ```
   Use `tokenizer(text, padding='max_length', truncation=True, return_tensors='pt')` and let the tokenizer auto-resolve by setting `truncation_side='right'` and `padding_side='left'` via `tokenizer.init_kwargs`.
   ```

## Dead Ends

- **Set both truncation_side and padding_side to 'right'** — For decoder-only models, padding on the right can cause incorrect attention masking; the model expects left padding for generation. (70% fail)
- **Ignore the warning and proceed with training** — This is a ValueError, not a warning; it raises an exception and stops execution. (100% fail)
