# PR #47755 完整报告

- 仓库：`vllm-project/vllm`
- 标题：[Bug] Fix tmp directory for `lm_eval`
- 合并时间：2026-07-08 00:40
- 原文链接：http://prhub.com.cn/vllm-project/vllm/pull/47755

---

# 执行摘要

- 一句话：修复 GSM8K 评测硬编码 /tmp 权限问题
- 推荐动作：该 PR 变更简单清晰，风险低，建议快速合并。可关注类似硬编码路径问题是否存在于其他评测配置中。

# 功能与动机

运行 GSM8K 评测时，由于 `download_and_cache_file` 函数硬编码缓存路径为 `/tmp`，在某些没有写入权限的环境中会抛出 `PermissionError: [Errno 13] Permission denied: '/tmp/train.jsonl'`。PR 作者在 body 中给出了完整的报错堆栈。

# 实现拆解

1. **添加导入**：在 `tests/evals/gsm8k/gsm8k_eval.py` 中新增 `import tempfile`。
2. **替换硬编码路径**：在 `download_and_cache_file` 函数中，当 `filename` 为 `None` 时，将原来的 `os.path.join("/tmp", url.split("/")[-1])` 改为 `os.path.join(tempfile.gettempdir(), url.split("/")[-1])`，从而使用平台推荐的临时目录。
3. **测试验证**：PR 作者在 body 中展示测试已通过。

关键文件：
- `tests/evals/gsm8k/gsm8k_eval.py`（模块 评测工具；类别 test；类型 test-coverage）: 唯一变更文件，修复硬编码 `/tmp` 为 `tempfile.gettempdir()`，提升便携性。

关键符号：download_and_cache_file

## 关键源码片段

### `tests/evals/gsm8k/gsm8k_eval.py`

唯一变更文件，修复硬编码 `/tmp` 为 `tempfile.gettempdir()`，提升便携性。

```python
import os
import tempfile  # 新增：使用平台临时目录而非硬编码 /tmp

def download_and_cache_file(url: str, filename: str | None = None) -> str:
    """Download and cache a file from a URL."""
    if filename is None:
        # 旧代码：os.path.join("/tmp", url.split("/")[-1])
        # 新代码：使用 tempfile.gettempdir() 避免权限问题
        filename = os.path.join(tempfile.gettempdir(), url.split("/")[-1])

    if os.path.exists(filename):
        return filename

    print(f"Downloading from {url} to {filename}")
    response = requests.get(url, stream=True)
    response.raise_for_status()

    with open(filename, "wb") as f:
        for chunk in response.iter_content(chunk_size=1024):
            f.write(chunk)

    return filename

```

# 评论区精华

无实质性 Review 讨论。`LucasWilkinson` 和 `AndreasKaratzas` 直接批准，Claude Bot 是自动回复。

- 暂无高价值评论线程

# 风险与影响

- 风险：风险极低。`tempfile.gettempdir()` 在大多数环境中返回 `/tmp`，因此不会有行为变化，且可移植性更强。唯一需要注意的风险是并发测试可能写入相同文件，但原始 `download_and_cache_file` 已有 `os.path.exists` 检查，因此风险可控。
- 影响：影响范围极小，仅涉及 GSM8K 评测工具的缓存路径，不影响其他模块。用户无需修改任何配置即可在无 `/tmp` 写入权限的环境中正常运行评测。
- 风险标记：暂无

# 关联脉络

- 暂无明显关联 PR