Skip to content

[Docs] Fix python specifiers in tutorials#19280

Open
vacu9708 wants to merge 2 commits intopytorch:mainfrom
vacu9708:fix-conda-python-version
Open

[Docs] Fix python specifiers in tutorials#19280
vacu9708 wants to merge 2 commits intopytorch:mainfrom
vacu9708:fix-conda-python-version

Conversation

@vacu9708
Copy link
Copy Markdown

@vacu9708 vacu9708 commented May 4, 2026

Fixes #18073 (This issue was already fixed before this PR)

Problem

The setup tutorial prescribes:

conda create -yn executorch python=3.10.0

This version has a CPython bug that leaves PyTorch's LeafSpec's init=False
fields uninitialized. run_decompositions() in ExecuTorch deepcopies the
LeafSpec nodes and crashes.
This breaks the export pipeline (to_edge_transform_and_lower, to_edge, run_decompositions),
which leads to any model export attempt failing unconditionally on Python 3.10.0.

The error message (AttributeError: 'LeafSpec' object has no attribute 'type')
gives no indication that Python version is the cause, making it hard for tutorial followers to diagnose.

Upstream Fix Status

The fix has already landed in PyTorch main via pytorch/pytorch#177154 and is available in recent nightly builds.
However, ExecuTorch currently pins to torch==2.11.
The 2.11 branch was cut before the fix was merged, which means
the upstream fix does not apply until the ExecutTorch's torch pin is bumped to 2.12.
Until then, this PR is necessary to prevent tutorial followers from hitting the bug and getting lost.

Resolution

The CI build script (.ci/docker/build.sh) uses:

PYTHON_VERSION=3.10

conda interprets python=3.10 as a prefix, installing the latest available
3.10.x — currently 3.10.16 — which does not have this bug.
The CPython fix landed in 3.10.1.
This discrepancy (3.10 vs 3.10.0) makes the bug invisible to CI while affecting any user who follows the setup tutorial.

Fix python=3.10.0 -> python=3.10 to align the docs with CI.

Test plan

Not working

conda create -yn executorch3100 python=3.10.0
conda activate executorch3100

Working

conda create -yn executorch310 python=3.10
conda activate executorch310
import torch
from executorch.exir import to_edge_transform_and_lower
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner

class MyModel(torch.nn.Module):
    def forward(self, x):
        return x + 1

# 1. Export your PyTorch model
model = MyModel().eval()
example_inputs = (torch.randn(1, 3, 224, 224),)
exported_program = torch.export.export(model, example_inputs)

# 2. Optimize for target hardware (switch backends with one line)
program = to_edge_transform_and_lower(
    exported_program,
    partitioner=[XnnpackPartitioner()]  # CPU | CoreMLPartitioner() for iOS | QnnPartitioner() for Qualcomm
).to_executorch()

The tutorial pages prescribe 'python=3.10.0', which has a CPython
bug (python/cpython#89683) that leaves PyTorch's LeafSpec's init=False
fields uninitialized. run_decompositions() in ExecuTorch deepcopies the
LeafSpec nodes and crashes, so any model export attempt fails
unconditionally on Python 3.10.0.

The CI pipeline uses PYTHON_VERSION=3.10 in .ci/docker/build.sh, which
conda resolves to the latest 3.10.x (currently 3.10.16) — unaffected by
the bug. This fix aligns the docs with CI.
@vacu9708 vacu9708 requested a review from mergennachin as a code owner May 4, 2026 14:02
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 4, 2026

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures, 1 Cancelled Job, 3 Unrelated Failures

As of commit a645615 with merge base a79521b (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOB - The following job was cancelled. Please retry:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 4, 2026

Hi @vacu9708!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

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-cla
Copy link
Copy Markdown

meta-cla Bot commented May 4, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 May 4, 2026
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 4, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'LeafSpec' object has no attribute 'type' when using nightly pytorch

3 participants