# ValueError: repetition_penalty and no_repeat_ngram_size cannot be set simultaneously as they may conflict.

- **ID:** `huggingface/transformers-generation-config-repeat-penalty-conflict`
- **Domain:** huggingface
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Both repetition_penalty and no_repeat_ngram_size are set in generation config or passed to model.generate(), but they can produce contradictory effects on token selection.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| transformers>=4.25.0 | active | — | — |

## Workarounds

1. **Remove one of the parameters: use only `repetition_penalty=1.2` (typical range 1.0-2.0) to discourage repetition, or `no_repeat_ngram_size=3` to block n-gram repeats. Example: `model.generate(inputs, repetition_penalty=1.2)` or `model.generate(inputs, no_repeat_ngram_size=3)`** (95% success)
   ```
   Remove one of the parameters: use only `repetition_penalty=1.2` (typical range 1.0-2.0) to discourage repetition, or `no_repeat_ngram_size=3` to block n-gram repeats. Example: `model.generate(inputs, repetition_penalty=1.2)` or `model.generate(inputs, no_repeat_ngram_size=3)`
   ```
2. **If you need both effects, implement a custom repetition penalty that combines both strategies manually in a logits processor, then pass it via `model.generate(logits_processor=[...])`.** (80% success)
   ```
   If you need both effects, implement a custom repetition penalty that combines both strategies manually in a logits processor, then pass it via `model.generate(logits_processor=[...])`.
   ```
3. **Check the generation config before calling: `if hasattr(model.generation_config, 'repetition_penalty') and model.generation_config.repetition_penalty is not None: model.generation_config.no_repeat_ngram_size = None`** (85% success)
   ```
   Check the generation config before calling: `if hasattr(model.generation_config, 'repetition_penalty') and model.generation_config.repetition_penalty is not None: model.generation_config.no_repeat_ngram_size = None`
   ```

## Dead Ends

- **** — Setting no_repeat_ngram_size=0 is valid but still triggers the conflict check; setting repetition_penalty=0.0 is invalid (must be >=1.0) and raises a different error. (60% fail)
- **** — The error is raised before generation; silent catch will cause the generation to proceed with default values, potentially producing unwanted repetition. (50% fail)
- **** — The GenerationConfig itself raises this error during validation, so it will fail before any generation occurs. (70% fail)
