Enable Pyrefly in fbcode/executorch (#21045)#21045
Conversation
🔗 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 ( 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. |
|
|
@maggiemoss has exported this pull request. If you are a Meta employee, you can view the originating Diff in D112856308. |
This PR needs a
|
There was a problem hiding this comment.
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_specmay beNonebut is used as if it’s always present. Add a direct assertion and drop thepyrefly: 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.
| 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] |
| 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=}", | ||
| ) |
| # pyrefly: ignore [not-callable] | ||
| if not features.are_node_inputs_supported_fn(node): | ||
| self.log_skip(node, "op args not supported") | ||
| return False |
| def get_verifiers(self) -> Optional[list[Verifier]]: | ||
| if self.mode == IrMode.ATEN: | ||
| return None | ||
| # pyrefly: ignore [bad-return] | ||
| return [ |
| 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
9d05368 to
adad0ed
Compare
There was a problem hiding this comment.
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")
| # pyrefly: ignore [unsupported-operation] | ||
| if (self.groups > 1 and self.groups < out_channels) and ( | ||
| out_channels / self.groups | ||
| ) % 4 != 0: |
Summary:
Automated migration to enable Pyrefly type checking for
fbcode/executorch.python.set_pyrefly(True)to PACKAGE filePyrefly 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