Files
pytorch/benchmarks
OnOnikhil b04f0b1b27 Replace hard-coded /tmp paths with tempfile.gettempdir() (#171446)
Fixes #171385

Summary
Replaced hardcoded `/tmp` paths with `tempfile.gettempdir()` in production code and key test files to allow users to configure temp directory location via environment variables (e.g., `TMPDIR`).

 Motivation
Users need to specify custom temp directory locations when:
- `/tmp` has limited storage or quota restrictions
- Running on Windows (where `/tmp` doesn't exist)
- Using containerized environments with custom temp directories

Changes
Modified 7 files to use `tempfile.gettempdir()`:
- `torch/_inductor/debug.py` - Inductor saved args
- `torch/_dynamo/convert_frame.py` - cProfile outputs
- `torch/_inductor/compile_fx_ext.py` - Debug serialization files
- `torch/distributed/elastic/agent/server/local_elastic_agent.py` - Watchdog timers
- `torch/distributed/_symmetric_memory/_nvshmem_triton.py` - NVSHMEM PTX files
- `benchmarks/dynamo/torchbench.py` - KALDI_ROOT env var
- `test/test_cuda.py` - GDS filesystem tests

 Scope
Note: This PR focuses on production code and critical test files (~7 files). The codebase has ~96 `/tmp` references across 53 files, but many are in:
- Comments/docstrings (documentation examples)
- Example scripts (functorch examples)
- Less critical test files

These were intentionally excluded to keep the PR focused and minimize risk of breaking existing workflows. Follow-up PRs can address remaining instances if needed.

Backward Compatibility
Fully backward compatible - when `TMPDIR` is not set, `tempfile.gettempdir()` defaults to `/tmp` on Unix/Linux systems, maintaining existing behavior.

Testing
- Verified with `git diff` that only intended changes were made
- All modified paths now respect system temp directory configuration
- Users can test with: `export TMPDIR=/custom/path`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/171446
Approved by: https://github.com/malfet

Co-authored-by: Nikita Shulga <2453524+malfet@users.noreply.github.com>
2025-12-29 20:34:14 +00:00
..
2025-10-21 03:30:57 +00:00
2025-12-05 01:58:13 +00:00

PyTorch Benchmarks

This folder contains scripts that produce reproducible timings of various PyTorch features.

It also provides mechanisms to compare PyTorch with other frameworks.

Setup environment

Make sure you're on a machine with CUDA, torchvision, and pytorch installed. Install in the following order:

# Install torchvision. It comes with the pytorch stable release binary
python -m pip install torch torchvision

# Install the latest pytorch master from source.
# It should supersede the installation from the release binary.
cd $PYTORCH_HOME
python -m pip install --no-build-isolation -v -e .

# Check the pytorch installation version
python -c "import torch; print(torch.__version__)"

Benchmark List

Please refer to each subfolder to discover each benchmark suite. Links are provided where descriptions exist: