Skip to content

Fix ARM test listing failures caused by torch import at collection time (#20284)#20284

Open
Gasoonjia wants to merge 1 commit into
mainfrom
export-D108630941
Open

Fix ARM test listing failures caused by torch import at collection time (#20284)#20284
Gasoonjia wants to merge 1 commit into
mainfrom
export-D108630941

Conversation

@Gasoonjia

@Gasoonjia Gasoonjia commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary:

The ~180 ARM test listings fail in fbcode//mode/opt during pytest
collection with AttributeError: module 'torch' has no attribute '_utils'.

Root cause: torch._utils is importable but is not bound as an attribute on
the torch module, so importing torch._dynamo (pulled in via
executorch.exir / torchao when a test module is collected) reads
torch._utils directly and crashes the whole listing. This is independent of
the seed call and of CinderX lazy imports (already disabled for these targets,
verified at runtime).

The previous version guarded the early seed with try/except, which neither set
the seed internally nor actually fixed the listings (the crash originates in
test-module collection, not the seed call).

Fix: bind torch._utils explicitly in _set_random_seed(), which runs in
pytest_configure before collection, and drop the try/except so the
collection-time seeding from D108449705 is restored. The change is identical
for OSS and internal (a no-op where torch._utils is already bound), which
also addresses the reviewer ask to seed the same way for both.

Verified in fbcode//mode/opt: fixes ~170/180 listings and re-enables the
collection-time seed.

Known follow-up (T275980003): ~10 targets that import
torchao.prototype.mx_formats still fail on torch.device unbound during
torchao's import-time device probing — a separate torch/torchao issue.

Reviewed By: shoumikhin

Differential Revision: D108630941

@Gasoonjia Gasoonjia requested a review from digantdesai as a code owner June 15, 2026 16:57
@pytorch-bot

pytorch-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20284

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 New Failures

As of commit 93b32b3 with merge base e257a71 (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 15, 2026
@meta-codesync

meta-codesync Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@Gasoonjia has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108630941.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@meta-codesync meta-codesync Bot changed the title Fix ARM test listing failures caused by torch import at collection time Fix ARM test listing failures caused by torch import at collection time (#20284) Jun 15, 2026
meta-codesync Bot pushed a commit that referenced this pull request Jun 15, 2026
…me (#20284)

Summary:

The `_set_random_seed()` call added to `pytest_configure()` in D108449705
imports torch during test collection, which triggers the `torch._dynamo`
init chain. In `fbcode//mode/opt`, this crashes with
`AttributeError: module 'torch' has no attribute '_utils'`, causing all
~180 ARM test listings to fail.

Guard the early seed call with try/except. The per-test `set_random_seed`
fixture still seeds before each test execution, so determinism is preserved.

Differential Revision: D108630941
@meta-codesync meta-codesync Bot force-pushed the export-D108630941 branch from af2bd61 to 75040de Compare June 15, 2026 16:59
meta-codesync Bot pushed a commit that referenced this pull request Jun 15, 2026
…me (#20284)

Summary:

The `_set_random_seed()` call added to `pytest_configure()` in D108449705
imports torch during test collection, which triggers the `torch._dynamo`
init chain. In `fbcode//mode/opt`, this crashes with
`AttributeError: module 'torch' has no attribute '_utils'`, causing all
~180 ARM test listings to fail.

Guard the early seed call with try/except. The per-test `set_random_seed`
fixture still seeds before each test execution, so determinism is preserved.

Differential Revision: D108630941
@meta-codesync meta-codesync Bot force-pushed the export-D108630941 branch from 75040de to 29611df Compare June 15, 2026 16:59
meta-codesync Bot pushed a commit that referenced this pull request Jun 15, 2026
…me (#20284)

Summary:

The `_set_random_seed()` call added to `pytest_configure()` in D108449705
imports torch during test collection, which triggers the `torch._dynamo`
init chain. In `fbcode//mode/opt`, this crashes with
`AttributeError: module 'torch' has no attribute '_utils'`, causing all
~180 ARM test listings to fail.

Guard the early seed call with try/except. The per-test `set_random_seed`
fixture still seeds before each test execution, so determinism is preserved.

Differential Revision: D108630941
@meta-codesync meta-codesync Bot force-pushed the export-D108630941 branch from 29611df to 835d3e7 Compare June 15, 2026 17:18
meta-codesync Bot pushed a commit that referenced this pull request Jun 15, 2026
…me (#20284)

Summary:

The ~180 ARM test listings fail in `fbcode//mode/opt` during pytest
collection with `AttributeError: module 'torch' has no attribute '_utils'`.

Root cause: `torch._utils` is importable but is not bound as an attribute on
the `torch` module, so importing `torch._dynamo` (pulled in via
`executorch.exir` / `torchao` when a test module is collected) reads
`torch._utils` directly and crashes the whole listing. This is independent of
the seed call and of CinderX lazy imports (already disabled for these targets,
verified at runtime).

The previous version guarded the early seed with try/except, which neither set
the seed internally nor actually fixed the listings (the crash originates in
test-module collection, not the seed call).

Fix: bind `torch._utils` explicitly in `_set_random_seed()`, which runs in
`pytest_configure` before collection, and drop the try/except so the
collection-time seeding from D108449705 is restored. The change is identical
for OSS and internal (a no-op where `torch._utils` is already bound), which
also addresses the reviewer ask to seed the same way for both.

Verified in `fbcode//mode/opt`: fixes ~170/180 listings and re-enables the
collection-time seed.

Known follow-up (T275980003): ~10 targets that import
`torchao.prototype.mx_formats` still fail on `torch.device` unbound during
torchao's import-time device probing — a separate torch/torchao issue.

Reviewed By: shoumikhin

Differential Revision: D108630941
@meta-codesync meta-codesync Bot force-pushed the export-D108630941 branch from 835d3e7 to 5419b2c Compare June 15, 2026 23:03
…me (#20284)

Summary:

The ~180 ARM test listings fail in `fbcode//mode/opt` during pytest
collection with `AttributeError: module 'torch' has no attribute '_utils'`.

Root cause: `torch._utils` is importable but is not bound as an attribute on
the `torch` module, so importing `torch._dynamo` (pulled in via
`executorch.exir` / `torchao` when a test module is collected) reads
`torch._utils` directly and crashes the whole listing. This is independent of
the seed call and of CinderX lazy imports (already disabled for these targets,
verified at runtime).

The previous version guarded the early seed with try/except, which neither set
the seed internally nor actually fixed the listings (the crash originates in
test-module collection, not the seed call).

Fix: bind `torch._utils` explicitly in `_set_random_seed()`, which runs in
`pytest_configure` before collection, and drop the try/except so the
collection-time seeding from D108449705 is restored. The change is identical
for OSS and internal (a no-op where `torch._utils` is already bound), which
also addresses the reviewer ask to seed the same way for both.

Verified in `fbcode//mode/opt`: fixes ~170/180 listings and re-enables the
collection-time seed.

Known follow-up (T275980003): ~10 targets that import
`torchao.prototype.mx_formats` still fail on `torch.device` unbound during
torchao's import-time device probing — a separate torch/torchao issue.

Reviewed By: shoumikhin

Differential Revision: D108630941
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. meta-exported module: arm Issues related to arm backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants