Arm backend: Make pytest collection seeding deterministic#20621
Conversation
Seed the Arm test RNG during pytest configuration in OSS/local test runs so module-level random inputs are deterministic before collection imports test modules. This will make tests behave less random and hopefully fix some flakeynes in testing/CI. For example test_dl3_arm.py failes about 5% of the time before this fix due to it getting non seeded random numbers. Extra cleanup/fixes: Use TEST_SEED for the Arm test session seed, replacing the old ARM_TEST_SEED environment variable name. Keep packaged non-OSS Buck behavior unchanged by skipping that early torch import there, while preserving the per-test seeding fixture. Signed-off-by: Zingo Andersen <Zingo.Andersen@arm.com> Change-Id: If8597f79e0e59bf92d6f00f1b3f12097f08ce21e
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20621
Note: Links to docs will display an error until the docs builds have been completed. ❌ 4 New FailuresAs of commit a764734 with merge base b1ef9a5 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Pull request overview
This PR makes Arm backend pytest runs more deterministic by selecting a single session seed during pytest_configure (early enough to affect module-import-time randomness during collection in OSS/local runs), while preserving the packaged/non-OSS Buck behavior by skipping the early torch import there.
Changes:
- Add session-level seed setup in
pytest_configure, report the chosen seed in the pytest header, and seed torch/python RNG early for OSS/local runs. - Switch Arm test seeding env var to
TEST_SEED(fromARM_TEST_SEED) and update the autouse fixture to re-seed each test using the session seed. - Pass a new Buck test env flag (
TEST_RUNTIME_IS_NOT_OSS) to control whether early seeding is safe in that environment.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| backends/arm/test/targets.bzl | Adds TEST_RUNTIME_IS_NOT_OSS and refactors env construction for Arm pytest Buck targets. |
| backends/arm/test/conftest.py | Implements deterministic session seeding during pytest configuration, updates env var name to TEST_SEED, and reports seed in the pytest header. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @Gasoonjia @digantdesai @rascani Here is a new version of a patch that got reverted due to torch was used to early in you buck setup. This version try to guard this with the runtime.is_oss so hopefully this works both on GutHub and internally, but internally you will not get the same nice locked down randomness in the tests but it will work the same way as today. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| raise TypeError( | ||
| "ARM_TEST_SEED env variable must be integers or the string RANDOM" | ||
| ) | ||
| raise TypeError("TEST_SEED env variable must be integers or the string RANDOM") |
| seed, seed_label = _setup_random_seed() | ||
| config._test_seed = seed | ||
| config._test_seed_label = seed_label | ||
|
|
||
| if os.environ.get("TEST_RUNTIME_IS_NOT_OSS", "0") != "1": |
|
Hi @digantdesai / @rascani is this OK to merge and test if internal Meta build still works? Or do you want to pre-run it? |
I'll do an import just in case. |
|
@rascani has imported this pull request. If you are a Meta employee, you can view this in D110912183. |
Internal tests were green. I unlinked the diff, but it might need a fresh test run. |
|
Testfails are unrelated test only changes test under backends/arm/tests Same/similar fails are visible on other trunk jobs. |
Summary
Seed the Arm test RNG during pytest configuration in OSS/local test runs so module-level random inputs are deterministic before collection imports test modules.
This will make tests behave less random and hopefully fix some flakeynes in testing/CI.
For example test_dl3_arm.py failes about 5% of the time before this fix due to it getting non seeded random numbers.
Extra cleanup/fixes:
Use TEST_SEED for the Arm test session seed, replacing the old ARM_TEST_SEED environment variable name.
Keep packaged non-OSS Buck behavior unchanged by skipping that early torch import there, while preserving the per-test seeding fixture.
Test plan
This is tested by all Arm backend pytests
cc @digantdesai @freddan80 @per @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani