Repository navigation
[torchci] Capture the test environment for test run reports - #200339
georgehong wants to merge 3 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/200339
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit fee5881 with merge base 816fc3c ( 🟡 GREEN LIGHT - OUTDATED (earlier commit) - PR requires human review:
reason: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| return "cuda", torch.version.cuda | ||
| if torch.version.hip: | ||
| # The ROCm release (10.1), not HIP's own version (7.16). | ||
| return "rocm", ".".join((torch.version.rocm or "").split(".")[:2]) |
There was a problem hiding this comment.
Curious, why do we care to transform this? Why not just use what torch tells us? Same for xpu
There was a problem hiding this comment.
This retrieves major/minor version from the spec, with the intention of making grouping queries easier.
There was a problem hiding this comment.
I think it would be important to know the patch version too considering they often contain bug fixes, which can affect tests
There was a problem hiding this comment.
Addressed async. Keeping default output, unless we find grouping granularity to be inconvenient.
| "driver_version": driver, | ||
| "host_memory_mib": _host_memory_mib(), | ||
| "build_environment": os.environ.get("BUILD_ENVIRONMENT", ""), | ||
| "test_config": os.environ.get("TEST_CONFIG", ""), |
There was a problem hiding this comment.
TEST_CONFIG should be part of the repro env. This is one of the most important environment variable controlling where tests run.
There was a problem hiding this comment.
Isn't TEST_CONFIG a bit of a PyTorch GH CI idiom that has heavy overlap with the environment flags that we have here? e.g. there's the dynamo_wrapped config, but also already a repro flag for "PYTORCH_TEST_WITH_DYNAMO"?
There was a problem hiding this comment.
It's not just GH, it's used by test/run_test.py. IMO it is one of the most important env that controls the reproducibility of tests, no?
There was a problem hiding this comment.
Addressed async. Given that we're trying to move away from the config description in favor of primitives that describe the modalities, holding off on including it as an env. We'll still be able to refer to them in the source jsonls, and propagate it to the table as necessary.
| return "", "", "" | ||
|
|
||
|
|
||
| def _nvml_device() -> tuple[str, str, str]: |
There was a problem hiding this comment.
My agent says we can use nvidia-ml-py and torch.cuda._get_pynvml_handler to get this info. Can you look into that?
There was a problem hiding this comment.
Since this needs to propagate through CI images as a dependency, this would be a good follow-up at pytorch/test-infra#9079
|
@pytorchbot merge |
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
|
Starting merge as part of PR stack under #200023 |
**Summary** Adds a pytest plugin under `torch/testing/_internal/torchci` that writes one JSONL test run report per test process, for ingestion into the ClickHouse tests tables (schema: pytorch/test-infra `jathu/ci-tables`). Each report is a report line with the environment from #200339, then one line per test run. - It lives under `torch/testing/_internal` because every test process must import it. `tools/` isn't on their `sys.path`, and adding the repo root would shadow the installed torch. It can move to a test-infra package once other repos use it. - `report.py` is the format (standard library only). `plugin.py` is the writer: it derives each test's identity from its pytest item, and it turns itself off on its first error so it never changes a test's outcome. `environment.py` (#200339) is the only PyTorch-aware module. **Testing** `python test/torchci/test_testing.py` runs pytest with the plugin on `test/junit_xml_testdata/pytest_suite.py` and the fixture files in `test/torchci/testdata/` and checks the lines it writes, plus unit tests of the helpers. *e2e*: ``` cd test # in a venv where torch imports python -m pytest junit_xml_testdata/pytest_suite.py -p torch.testing._internal.torchci.plugin \ --torchci-report-prefix=/tmp/torchci-demo/pytest_suite -p no:cacheprovider -q jq . /tmp/torchci-demo/pytest_suite-*.report.jsonl ``` Authored with the help of an AI assistant (Claude). Pull Request resolved: #200022 Approved by: https://github.com/jathu ghstack dependencies: #200339
…200023) **Overview** `--save-torchci-reports DIR` registers the torchci plugin, which writes each test process's report to `<DIR>/<file>-<uuid>.report.jsonl`. Off by default. *run_test.py* only forwards the flag when the installed torch has the writer, since tests sometimes run against a nightly. **Test Plan** ``` python test/run_test.py -i test_type_info --save-torchci-reports /tmp/test/torchci-reports/ ``` Authored with the help of an AI assistant (Claude). Pull Request resolved: #200023 Approved by: https://github.com/jathu ghstack dependencies: #200339, #200022
…200339) **Summary** Adds `torch/testing/_internal/torchci/environment.py`, which captures what a test run report records about its process: machine identity (OS, CPU, Python, compiler, accelerator, devices), `TestEnvironment` flags, and properties. Nothing calls it yet; pytorch#200022 writes it into each report. - `TestEnvironment.env_var_values` (`common_utils.py`) holds each `include_in_repro` flag and setting as its env var is set, e.g. `PYTORCH_CUDA_ALLOC_CONF: expandable_segments:True`. Unset ones are `""`, except a flag that's on by default or implication, which is `"1"`. - `capture()` runs in the test process before its tests, so it creates no device context (device names come from NVML, amdsmi or xpu-smi) and doesn't call `torch.accelerator`. **Testing** Unit tests added in this PR. Authored with the help of an AI assistant (Claude). Pull Request resolved: pytorch#200339 Approved by: https://github.com/jathu
**Summary** Adds a pytest plugin under `torch/testing/_internal/torchci` that writes one JSONL test run report per test process, for ingestion into the ClickHouse tests tables (schema: pytorch/test-infra `jathu/ci-tables`). Each report is a report line with the environment from pytorch#200339, then one line per test run. - It lives under `torch/testing/_internal` because every test process must import it. `tools/` isn't on their `sys.path`, and adding the repo root would shadow the installed torch. It can move to a test-infra package once other repos use it. - `report.py` is the format (standard library only). `plugin.py` is the writer: it derives each test's identity from its pytest item, and it turns itself off on its first error so it never changes a test's outcome. `environment.py` (pytorch#200339) is the only PyTorch-aware module. **Testing** `python test/torchci/test_testing.py` runs pytest with the plugin on `test/junit_xml_testdata/pytest_suite.py` and the fixture files in `test/torchci/testdata/` and checks the lines it writes, plus unit tests of the helpers. *e2e*: ``` cd test # in a venv where torch imports python -m pytest junit_xml_testdata/pytest_suite.py -p torch.testing._internal.torchci.plugin \ --torchci-report-prefix=/tmp/torchci-demo/pytest_suite -p no:cacheprovider -q jq . /tmp/torchci-demo/pytest_suite-*.report.jsonl ``` Authored with the help of an AI assistant (Claude). Pull Request resolved: pytorch#200022 Approved by: https://github.com/jathu ghstack dependencies: pytorch#200339
…ytorch#200023) **Overview** `--save-torchci-reports DIR` registers the torchci plugin, which writes each test process's report to `<DIR>/<file>-<uuid>.report.jsonl`. Off by default. *run_test.py* only forwards the flag when the installed torch has the writer, since tests sometimes run against a nightly. **Test Plan** ``` python test/run_test.py -i test_type_info --save-torchci-reports /tmp/test/torchci-reports/ ``` Authored with the help of an AI assistant (Claude). Pull Request resolved: pytorch#200023 Approved by: https://github.com/jathu ghstack dependencies: pytorch#200339, pytorch#200022
Stack from ghstack (oldest at bottom):
Summary
Adds
torch/testing/_internal/torchci/environment.py, which captures what a test run report records about its process: machine identity (OS, CPU, Python, compiler, accelerator, devices),TestEnvironmentflags, and properties. Nothing calls it yet; #200022 writes it into each report.TestEnvironment.env_var_values(common_utils.py) holds eachinclude_in_reproflag and setting as its env var is set, e.g.PYTORCH_CUDA_ALLOC_CONF: expandable_segments:True. Unset ones are"", except a flag that's on by default or implication, which is"1".capture()runs in the test process before its tests, so it creates no device context (device names come from NVML, amdsmi or xpu-smi) and doesn't calltorch.accelerator.Testing
Unit tests added in this PR.
Authored with the help of an AI assistant (Claude).