Skip to content

Enable Pyrefly in fbcode/executorch (#21045)#21045

Open
maggiemoss wants to merge 1 commit into
pytorch:mainfrom
maggiemoss:export-D112856308
Open

Enable Pyrefly in fbcode/executorch (#21045)#21045
maggiemoss wants to merge 1 commit into
pytorch:mainfrom
maggiemoss:export-D112856308

Conversation

@maggiemoss

@maggiemoss maggiemoss commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary:

Automated migration to enable Pyrefly type checking for fbcode/executorch.

  • Added python.set_pyrefly(True) to PACKAGE file
  • Suppressed pre-existing type errors

Pyrefly is Meta's next-generation Python type checker, replacing Pyre.

If you encounter issues, you can revert the PACKAGE change by removing
the python.set_pyrefly(True) line.
#pyreupgrade

Differential Revision: D112856308

Copilot AI review requested due to automatic review settings July 20, 2026 19:57
@maggiemoss
maggiemoss requested a review from SS-JIA as a code owner July 20, 2026 19:57
@pytorch-bot

pytorch-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit adad0ed with merge base 2524691 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 20, 2026

Copy link
Copy Markdown

CLA Missing ID

  • ❌ The email address for the commit (adad0ed) is not linked to the GitHub account, preventing the EasyCLA check. Consult this Help Article and GitHub Help to resolve. (To view the commit's email address, add .patch at the end of this PR page's URL.) For further assistance with EasyCLA, please visit our EasyCLA portal and chat with our support bot.

@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 Jul 20, 2026
@meta-codesync

meta-codesync Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

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

@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.

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 is an automated migration to enable Pyrefly type checking for fbcode/executorch by adding targeted # pyrefly: ignore [...] suppressions for pre-existing type errors across Vulkan and Cadence backend code (plus backend test utilities).

Changes:

  • Added Pyrefly suppressions in Vulkan pattern-rewrite code paths to unblock type checking in FX node manipulation and metadata access.
  • Added Pyrefly suppressions in Cadence AOT passes/quantizer code paths where dynamic FX structures and heterogeneous argument types trip strict typing.
  • Added Pyrefly suppressions in backend test utilities/tests to accommodate type-checker limitations around verifier types and FX node metadata.

Reviewed changes

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

Show a summary per file
File Description
backends/vulkan/patterns/select_as_symint.py Add Pyrefly suppressions for FX node/metadata typing in a pattern replacement.
backends/vulkan/patterns/sdpa.py Add Pyrefly suppressions for FX users/metadata usage in SDPA rewrite.
backends/vulkan/patterns/rms_norm.py Add Pyrefly suppressions for decorator typing and FX metadata propagation.
backends/vulkan/patterns/quantized_unary.py Add Pyrefly suppressions around FX node target checks / attributes.
backends/vulkan/patterns/quantized_pixel_shuffle.py Add Pyrefly suppressions for PatternMatch attribute typing and decorator usage.
backends/vulkan/patterns/quantized_linear.py Add Pyrefly suppressions across quantized linear matching/rewrite and param mutation utilities.
backends/vulkan/patterns/quantized_embedding.py Add Pyrefly suppressions for param extraction/mutation and FX metadata propagation.
backends/vulkan/patterns/quantized_convolution.py Add Pyrefly suppressions for symbolic/int-like arithmetic and param update calls.
backends/vulkan/patterns/quantized_binary.py Add Pyrefly suppressions for FX node target checks on binary quantized ops.
backends/vulkan/partitioner/vulkan_partitioner.py Add Pyrefly suppression for calling a feature-provided predicate callback.
backends/test/program_builder.py Add Pyrefly suppression for verifier list return typing.
backends/test/graph_builder.py Add Pyrefly suppressions for attribute overrides in a helper ExportPass subclass.
backends/cadence/utils/facto_util.py Add Pyrefly suppressions for constraint/spec mutation typing mismatches.
backends/cadence/aot/type_dispatch.py Add Pyrefly suppressions for FX arg/shape access typing in operator dispatch.
backends/cadence/aot/tests/test_replace_ops_passes.py Add Pyrefly suppression for expected-op-counts typing in a test helper call.
backends/cadence/aot/tests/test_quantizer_ops.py Add Pyrefly suppression for a complex typed test-case table assignment.
backends/cadence/aot/tests/test_memory_passes.py Add Pyrefly suppressions around optional metadata access in memory-allocation assertions.
backends/cadence/aot/tests/test_fusion_ops_passes.py Add Pyrefly suppression for generator/sort specialization typing in a test.
backends/cadence/aot/replace_ops.py Add Pyrefly suppressions for mixed FX arg types and slice/index computations in passes.
backends/cadence/aot/quantizer/quantizer.py Add Pyrefly suppressions for pattern anchor extraction and quantizer list construction.
backends/cadence/aot/quantizer/patterns.py Add Pyrefly suppressions across PartitionAnchors construction and FX-arg structure checks.
backends/cadence/aot/fuse_ops.py Add Pyrefly suppressions for getattr-based packed-weight extraction typing.
backends/cadence/aot/compiler_utils.py Add Pyrefly suppressions for getattr-based param access typing.
backends/cadence/aot/compiler_funcs.py Add Pyrefly suppressions for numeric casts from heterogeneous FX arg tuples.
Comments suppressed due to low confidence (1)

backends/cadence/aot/tests/test_memory_passes.py:245

  • Same pattern again: arg_spec may be None but is used as if it’s always present. Add a direct assertion and drop the pyrefly: ignore [missing-attribute] suppressions so failures are clearer and type checking can narrow correctly.
        arg = cast(torch.fx.Node, node.args[0])
        arg_spec = arg.meta.get("spec", None)
        # pyrefly: ignore [missing-attribute]
        self.assertEqual(arg_spec.mem_id, spec.mem_id)
        self.assertEqual(
            spec.mem_offset,
            # pyrefly: ignore [missing-attribute]
            arg_spec.mem_offset + index * inner_dim_elements,
            # pyrefly: ignore [missing-attribute]
            f"{arg=} for node {node=} has wrong memory offset: {arg_spec.mem_offset=} for select on {dim=} {index=}, "
            f"but output has {spec.mem_offset=}"
            f"{spec=} {arg_spec=}",
        )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 174 to 187
for arg in cast(list[torch.fx.Node], node.args[0]):
arg_spec = arg.meta.get("spec", None)
# pyrefly: ignore [missing-attribute]
self.assertEqual(arg_spec.mem_id, node_spec.mem_id)
actual_offset = node_spec.mem_offset + dim_offset * inner_dim_elements
self.assertEqual(
# pyrefly: ignore [missing-attribute]
arg_spec.mem_offset,
actual_offset,
# pyrefly: ignore [missing-attribute]
f"{arg=} of node {node=} has wrong memory offset: expected {arg_spec.mem_offset=}, but got {actual_offset=} = {node_spec.mem_offset=} + {dim_offset=} * {inner_dim_elements=}",
)
# pyrefly: ignore [missing-attribute]
dim_offset += arg_spec.shape[dim]
Comment on lines 205 to 215
arg = cast(torch.fx.Node, node.args[0])
arg_spec = arg.meta.get("spec", None)
# pyrefly: ignore [missing-attribute]
self.assertEqual(arg_spec.mem_id, spec.mem_id)
self.assertEqual(
spec.mem_offset,
# pyrefly: ignore [missing-attribute]
arg_spec.mem_offset + start * inner_dim_elements,
# pyrefly: ignore [missing-attribute]
f"{arg=} for node {node=} has wrong memory offset: {arg_spec.mem_offset=} {start=} for slice on {dim=}, but output has {spec.mem_offset=}",
)
Comment on lines +267 to 270
# pyrefly: ignore [not-callable]
if not features.are_node_inputs_supported_fn(node):
self.log_skip(node, "op args not supported")
return False
Comment on lines 95 to 99
def get_verifiers(self) -> Optional[list[Verifier]]:
if self.mode == IrMode.ATEN:
return None
# pyrefly: ignore [bad-return]
return [
Comment on lines 269 to 271
if bias_tensor is not None:
# pyrefly: ignore [bad-argument-type]
utils.align_width_and_update_state_dict(ep, match.bias_node, bias_tensor)
Summary:
Pull Request resolved: pytorch#21045

Automated migration to enable Pyrefly type checking for `fbcode/executorch`.

- Added `python.set_pyrefly(True)` to PACKAGE file
- Suppressed pre-existing type errors

Pyrefly is Meta's next-generation Python type checker, replacing Pyre.

If you encounter issues, you can revert the PACKAGE change by removing
the `python.set_pyrefly(True)` line.
#pyreupgrade

Differential Revision: D112856308
Copilot AI review requested due to automatic review settings July 20, 2026 20:37
@meta-codesync meta-codesync Bot changed the title Enable Pyrefly in fbcode/executorch Enable Pyrefly in fbcode/executorch (#21045) Jul 20, 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

Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

backends/test/program_builder.py:100

  • get_verifiers() advertises Optional[list[Verifier]] but it returns the result of EXIREdgeDialectVerifier(..., class_only=True), which is a verifier class (type[Verifier]) rather than a Verifier instance. The added pyrefly ignore hides a real type/API mismatch and makes it harder to reason about what ExportedProgram.verifiers expects.
    def get_verifiers(self) -> Optional[list[Verifier]]:
        if self.mode == IrMode.ATEN:
            return None
        # pyrefly: ignore [bad-return]
        return [
            EXIREdgeDialectVerifier(

backends/vulkan/partitioner/vulkan_partitioner.py:269

  • features.are_node_inputs_supported_fn is typed as Optional[Callable] (see op_registry), so calling it unconditionally can be a runtime error if it is ever set to None. The pyrefly ignore masks this; adding an assert keeps behavior the same today (default is non-None) while making the assumption explicit and satisfying the type checker.
        # pyrefly: ignore [not-callable]
        if not features.are_node_inputs_supported_fn(node):
            self.log_skip(node, "op args not supported")

Comment on lines +110 to 113
# pyrefly: ignore [unsupported-operation]
if (self.groups > 1 and self.groups < out_channels) and (
out_channels / self.groups
) % 4 != 0:
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. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants