# 运行时错误：梯度检查点要求use_cache=False

- **ID:** `huggingface/gradient-checkpointing-disable-error`
- **领域:** huggingface
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 93%

## 根因

梯度检查点与生成过程中使用的键值缓存不兼容；必须禁用use_cache才能启用梯度检查点。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| transformers>=4.25.0 | active | — | — |

## 解决方案

1. ```
   Disable use_cache before enabling gradient checkpointing.
   ```
2. ```
   Use the Trainer with gradient_checkpointing=True argument, which handles this automatically.
   ```

## 无效尝试

- **** — The two features are mutually exclusive during training; use_cache is only for inference. (98% 失败率)
- **** — The model configuration is checked at runtime; manual deletion does not bypass the check. (95% 失败率)
