# ValueError：在缓存的序列中遇到未知的 token ID 100000。分词器词汇表不匹配。

- **ID:** `llm/tokenizer-mismatch-cache-miss`
- **领域:** llm
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

缓存的 token 化序列是由不同版本或模型的分词器生成的，当前分词器无法识别缓存中的 token ID。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| transformers 4.35.0 | active | — | — |
| tokenizers 0.14.0 | active | — | — |
| vLLM 0.3.0 | active | — | — |
| Llama 2 70B | active | — | — |
| Mistral 7B | active | — | — |

## 解决方案

1. ```
   使缓存失效并使用当前分词器重新生成。对于 Hugging Face 数据集，运行：`dataset.cleanup_cache_files()` 并使用 `load_from_disk(new_path)` 重新加载。
   ```
2. ```
   如果使用 vLLM 或类似推理引擎，设置环境变量 `VLLM_USE_PREEMPTIVE_MODE=1` 以禁用 token 缓存，代价是推理速度稍慢。
   ```
3. ```
   在 requirements.txt 中固定分词器版本（例如 `tokenizers==0.14.0`），并使用一致的模型快照（例如 `model_name_or_path='meta-llama/Llama-2-7b-hf'`）。
   ```

## 无效尝试

- **** — The cache will be regenerated using the same mismatched tokenizer, and the error will reappear when the tokenizer or model is updated again. (60% 失败率)
- **** — Mapping unknown IDs to [UNK] discards semantic meaning and degrades model output quality, and the tokenizer may still reject the IDs during decoding. (80% 失败率)
- **** — The error is not related to fast vs slow tokenizer mode; it is a vocabulary mismatch that persists across both modes. (90% 失败率)
