Skip to content

Arm backend: Make pytest collection seeding deterministic#20621

Merged
zingo merged 3 commits into
pytorch:mainfrom
zingo:Arm-backend-Make-pytest-collection-seeding-deterministic
Jul 7, 2026
Merged

Arm backend: Make pytest collection seeding deterministic#20621
zingo merged 3 commits into
pytorch:mainfrom
zingo:Arm-backend-Make-pytest-collection-seeding-deterministic

Conversation

@zingo

@zingo zingo commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

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

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
Copilot AI review requested due to automatic review settings June 30, 2026 13:53
@zingo zingo requested a review from digantdesai as a code owner June 30, 2026 13:53
@zingo zingo added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: arm Changes to the ARM backend delegate labels Jun 30, 2026
@pytorch-bot

pytorch-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

🔗 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 Failures

As of commit a764734 with merge base b1ef9a5 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 30, 2026
@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels Jun 30, 2026
@zingo zingo requested a review from Gasoonjia June 30, 2026 13:54
@zingo zingo added the help wanted Extra attention is needed label Jun 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (from ARM_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.

Comment thread backends/arm/test/conftest.py Outdated
Comment thread backends/arm/test/conftest.py
@zingo

zingo commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

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.
As we can test this we need help with that.
I have a follow up PR doing the same for cortex-m tests if this works. #20623

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 30, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

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")
Comment on lines +29 to +33
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":
@zingo

zingo commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

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 got an approve and just merged the Cortex-M code doing the same.

@rascani

rascani commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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 got an approve and just merged the Cortex-M code doing the same.

I'll do an import just in case.

@meta-codesync

meta-codesync Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@rascani has imported this pull request. If you are a Meta employee, you can view this in D110912183.

@rascani

rascani commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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 got an approve and just merged the Cortex-M code doing the same.

I'll do an import just in case.

Internal tests were green. I unlinked the diff, but it might need a fresh test run.

@zingo

zingo commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

Testfails are unrelated test only changes test under backends/arm/tests

Same/similar fails are visible on other trunk jobs.

@zingo zingo merged commit dcc04ef into pytorch:main Jul 7, 2026
487 of 496 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. help wanted Extra attention is needed module: arm Issues related to arm backend partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: arm Changes to the ARM backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants