diff --git a/.lintrunner.toml b/.lintrunner.toml index c060836cb72..ec3db8207c8 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -341,6 +341,7 @@ include_patterns = [ # TODO(https://github.com/pytorch/executorch/issues/7441): Gradually start enabling all folders. # 'backends/**/*.py', 'backends/arm/**/*.py', + 'backends/cadence/**/*.py', 'backends/openvino/**/*.py', 'build/**/*.py', 'codegen/**/*.py', diff --git a/.mypy.ini b/.mypy.ini index cd14cbac7ea..bc9aef1c5f9 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -100,3 +100,6 @@ ignore_missing_imports = True [mypy-torchao.*] follow_untyped_imports = True + +[mypy-facto.*] +ignore_missing_imports = True diff --git a/backends/cadence/aot/compiler.py b/backends/cadence/aot/compiler.py index 5b7aef3c129..2dbd15f2f6a 100644 --- a/backends/cadence/aot/compiler.py +++ b/backends/cadence/aot/compiler.py @@ -166,7 +166,7 @@ def fuse_pt2( """ # Get patterns and apply fusion of dq -> op -> q to qop # pyre-ignore[16]: no attribute - patterns = [q.pattern for q in quantizer.quantizers] + patterns = [q.pattern for q in quantizer.quantizers] # type: ignore[attr-defined] QuantFusion(patterns)(converted_graph_module) return converted_graph_module diff --git a/backends/cadence/aot/compiler_funcs.py b/backends/cadence/aot/compiler_funcs.py index 6ff6057255c..25c99952a94 100644 --- a/backends/cadence/aot/compiler_funcs.py +++ b/backends/cadence/aot/compiler_funcs.py @@ -30,7 +30,7 @@ def trace( decomp_table = torch.export.default_decompositions() # pyre-fixme[6]: For 1st argument expected `Dict[typing.Callable[..., typing.Any - remove_decompositions(decomp_table, ops_to_keep) + remove_decompositions(decomp_table, ops_to_keep) # type: ignore[arg-type] program = torch.export.export(model, inputs, strict=strict).run_decompositions( decomp_table ) diff --git a/backends/cadence/aot/compiler_utils.py b/backends/cadence/aot/compiler_utils.py index b55d388691f..ab2433b8f04 100644 --- a/backends/cadence/aot/compiler_utils.py +++ b/backends/cadence/aot/compiler_utils.py @@ -60,7 +60,7 @@ def get_shape( return fake_tensor.shape # Case 3. node holds a param if node.op == "get_attr": - attr_node = getattr(graph_module, node.target) + attr_node = getattr(graph_module, node.target) # type: ignore[arg-type] return attr_node.shape # Default: return None return None @@ -140,7 +140,7 @@ def get_permuted_dims(node: torch.fx.Node, dims: List[int]) -> List[int]: assert node.target == exir_ops.edge.aten.permute_copy.default # Permute each index of the dimension ordering (dims) # pyre-fixme[6]: This combined typecheck isn't supported yet. - permute_dims: List[int] = list(node.args[1]) + permute_dims: List[int] = list(node.args[1]) # type: ignore[arg-type] assert all(isinstance(x, int) for x in permute_dims) return [dims[x] for x in permute_dims] @@ -156,7 +156,7 @@ def get_tensor_from_attr( if node is None: return None assert node.op == "get_attr" - return getattr(graph_module, node.target) + return getattr(graph_module, node.target) # type: ignore[arg-type] def is_node_with_op(node: torch.fx.Node, op: str) -> bool: diff --git a/backends/cadence/aot/fuse_ops.py b/backends/cadence/aot/fuse_ops.py index dbd19e1d3af..83b6509eba4 100644 --- a/backends/cadence/aot/fuse_ops.py +++ b/backends/cadence/aot/fuse_ops.py @@ -397,14 +397,14 @@ def fuse_quantized_batch_norm_with_conv( # Requantize the fused weight with the scale and zero point of the # quantized::conv's weight if per_tensor_quantization: - fused_weight = torch.quantize_per_tensor( + fused_weight = torch.quantize_per_tensor( # type: ignore[assignment] fused_weight, weight_scale.item(), cast(int, weight_zero_point.item()), weight_dtype, ) else: - fused_weight = torch.quantize_per_channel( + fused_weight = torch.quantize_per_channel( # type: ignore[assignment] fused_weight, weight_scale, weight_zero_point, @@ -693,7 +693,7 @@ def __init__( def _pkg_name_match(self, node1: torch.fx.Node, node2: torch.fx.Node) -> bool: # pyre-ignore[16]: Item `typing.Callable` has no attribute `_op` - return node1.target._op.namespace == node2.target._op.namespace + return node1.target._op.namespace == node2.target._op.namespace # type: ignore[union-attr] def can_fuse_for_chain( self, diff --git a/backends/cadence/aot/graph_builder.py b/backends/cadence/aot/graph_builder.py index 2cfd7900e8e..6f600019e2c 100644 --- a/backends/cadence/aot/graph_builder.py +++ b/backends/cadence/aot/graph_builder.py @@ -61,17 +61,17 @@ def __init__(self) -> None: ) # pyre-ignore[14]: Inconsistent override. - def placeholder( + def placeholder( # type: ignore[override] self, target: str, fake_tensor: Union[FakeTensor, torch.Tensor] ) -> ProxyValue: if not isinstance(fake_tensor, FakeTensor): - fake_tensor = self.fake_tensor_mode.from_tensor(fake_tensor) + fake_tensor = self.fake_tensor_mode.from_tensor(fake_tensor) # type: ignore[union-attr] logging.debug(f"Creating placeholder {target} => {fake_tensor.shape}") placeholder = super().placeholder(target, fake_tensor, NodeMetadata({})) return placeholder # pyre-ignore[14]: Inconsistent override. - def output(self, results: list[ProxyValue]) -> ProxyValue: + def output(self, results: list[ProxyValue]) -> ProxyValue: # type: ignore[override] logging.debug(f"Creating outputs {results}") return super().output(results, NodeMetadata({})) @@ -109,7 +109,7 @@ def _fx( kwargs: dict[str, Argument], meta: NodeMetadata, ) -> ProxyValue: - with self.fake_tensor_mode, enable_python_dispatcher(): + with self.fake_tensor_mode, enable_python_dispatcher(): # type: ignore[union-attr] return super()._fx(kind, target, args, kwargs, meta) diff --git a/backends/cadence/aot/memory_constraints.py b/backends/cadence/aot/memory_constraints.py index 8e784cd2779..07f5f5dfd89 100644 --- a/backends/cadence/aot/memory_constraints.py +++ b/backends/cadence/aot/memory_constraints.py @@ -143,8 +143,8 @@ def is_alias_of(self, node: torch.fx.Node, other_node: torch.fx.Node) -> bool: node_source_spec = node_source_info.source.meta.get("spec") return ( node_source_info.offset == 0 - and math.prod(node_source_spec.shape) == math.prod(node_spec.shape) - and node_source_spec.dtype == node_spec.dtype + and math.prod(node_source_spec.shape) == math.prod(node_spec.shape) # type: ignore[union-attr] + and node_source_spec.dtype == node_spec.dtype # type: ignore[union-attr] and self.is_alias_of(node_source_info.source, other_node) ) @@ -172,7 +172,7 @@ def is_memory_planned( # Check if any node is a param. if node.op == "get_attr": return False - if node.op == "placeholder" and node.meta.get("spec").const: + if node.op == "placeholder" and node.meta.get("spec").const: # type: ignore[union-attr] # Parameters / constants are not memory planned. return False if node.op == "placeholder" and not (self.alloc_graph_input): @@ -213,8 +213,8 @@ def resolve_relative_loc_constraints(self, spec: TensorSpec) -> None: source_info = self.get_relative_placement_source(dependent_node) assert source_info is not None dependent_spec = cast(TensorSpec, dependent_node.meta.get("spec")) - dependent_spec.mem_id = spec.mem_id - dependent_spec.mem_offset = spec.mem_offset + source_info.offset + dependent_spec.mem_id = spec.mem_id # type: ignore[assignment] + dependent_spec.mem_offset = spec.mem_offset + source_info.offset # type: ignore[operator,assignment] # Recursively resolve any relative constraints on this arg_spec self.resolve_relative_loc_constraints(dependent_spec) @@ -280,14 +280,14 @@ def add_relative_placement_constraint( dependent_spec = dependent.meta.get("spec") if update_lifetime: source_spec = source.meta.get("spec") - source.meta.get("spec").lifetime = [ - min(source_spec.lifetime[0], dependent_spec.lifetime[0]), - max(source_spec.lifetime[1], dependent_spec.lifetime[1]), + source.meta.get("spec").lifetime = [ # type: ignore[union-attr] + min(source_spec.lifetime[0], dependent_spec.lifetime[0]), # type: ignore[union-attr] + max(source_spec.lifetime[1], dependent_spec.lifetime[1]), # type: ignore[union-attr] ] self.update_children_nodes(dependent, update_lifetime) - abs_constraint = self.get_absolute_placement_constraint(dependent_spec) + abs_constraint = self.get_absolute_placement_constraint(dependent_spec) # type: ignore[arg-type] if abs_constraint is None: return @@ -366,7 +366,7 @@ def get_relative_offset_of_slice(slice_node: torch.fx.Node) -> int: slice_input = slice_node.args[0] assert isinstance(slice_input, torch.fx.Node) input_spec = slice_input.meta.get("spec") - tensor_shape = list(input_spec.shape) + tensor_shape = list(input_spec.shape) # type: ignore[union-attr] assert tensor_shape # get the slice dimension dim = 0 if len(slice_node.args) == 1 else cast(int, slice_node.args[1]) @@ -390,7 +390,7 @@ def get_relative_offset_of_slice(slice_node: torch.fx.Node) -> int: tensor_shape[dim] = 1 nbytes = num_bytes_from_shape_and_dtype( - torch.Size(tensor_shape), input_spec.scalar_type + torch.Size(tensor_shape), input_spec.scalar_type # type: ignore[union-attr] ) offset = start * nbytes return offset @@ -406,7 +406,7 @@ class GenerateCatNopConstraints(PassBase): def __init__(self, constraint: MemConstraints) -> None: self.constraint = constraint - def call(self, graph_module: torch.fx.GraphModule) -> Optional[PassResult]: + def call(self, graph_module: torch.fx.GraphModule) -> Optional[PassResult]: # type: ignore[return] self.compute_cat_contiguity_constraints(graph_module) def is_slice_view(self, node: torch.fx.Node) -> bool: @@ -545,7 +545,7 @@ class GenerateMemoryViewConstraints(PassBase): def __init__(self, constraint: MemConstraints) -> None: self.constraint = constraint - def call(self, graph_module: torch.fx.GraphModule) -> Optional[PassResult]: + def call(self, graph_module: torch.fx.GraphModule) -> Optional[PassResult]: # type: ignore[return] for node in graph_module.graph.nodes: if node.op != "call_function" or node.target != memory.view: continue @@ -563,7 +563,7 @@ class GenerateSliceAndSelectNopConstraints(PassBase): def __init__(self, constraint: MemConstraints) -> None: self.constraint = constraint - def call(self, graph_module: torch.fx.GraphModule) -> Optional[PassResult]: + def call(self, graph_module: torch.fx.GraphModule) -> Optional[PassResult]: # type: ignore[return] self.compute_slice_and_select_loc_constraints(graph_module) # Return True if the slice or select op can be replaced by a nop after @@ -593,9 +593,9 @@ def removable_slice_or_select_op( # is along the outermost dimension, or (b) all dimensions previous to # slicing/select dimension are 0 or 1. node_spec = node.meta.get("spec") - tensor_shape = list(node_spec.shape) + tensor_shape = list(node_spec.shape) # type: ignore[union-attr] dim = 0 if len(node.args) == 1 else node.args[1] - if dim and not set(tensor_shape[0:dim]).issubset({0, 1}): + if dim and not set(tensor_shape[0:dim]).issubset({0, 1}): # type: ignore[misc] return False # The slice step should be 1 for contiguity. @@ -684,7 +684,7 @@ def __call__(self, graph_module: torch.fx.GraphModule) -> PassResult: for mcg_pass in cast( list[ConstraintsGenPass], # pyre-ignore[6]: Incompatible parameter type. - list(filter(pass_filter, constraint_gen_passes)), + list(filter(pass_filter, constraint_gen_passes)), # type: ignore[arg-type] ) ] # Now run the pass manager on the filtered passes diff --git a/backends/cadence/aot/memory_planning.py b/backends/cadence/aot/memory_planning.py index ecf3fcef01c..6635bfe88ae 100644 --- a/backends/cadence/aot/memory_planning.py +++ b/backends/cadence/aot/memory_planning.py @@ -9,7 +9,7 @@ import collections import itertools import logging -from typing import Iterable, Optional, Sequence +from typing import Any, Iterable, Optional, Sequence import torch from executorch.backends.cadence.aot.memory_constraints import MemConstraints @@ -28,7 +28,7 @@ from executorch.exir.memory_planning import collect_specs_from_nodes, Verifier from executorch.exir.passes import MemoryPlanningPass from executorch.exir.tensor import TensorSpec -from tabulate import tabulate +from tabulate import tabulate # type: ignore[import-untyped] from torch.export.exported_program import ExportGraphSignature from torch.fx.passes.infra.pass_base import PassResult @@ -64,15 +64,15 @@ def plan_spec( """ Greedily place the spec in the first memory that can fit it. """ - for spec.mem_id in range(1, self.get_num_memories()): - spec.mem_offset = 0 + for spec.mem_id in range(1, self.get_num_memories()): # type: ignore[assignment] + spec.mem_offset = 0 # type: ignore[assignment] while self.is_valid_placement(spec, placement_constraints) and ( overlapped := state.get_overlapping_spec(spec) ): # Found an overlapping spec, so we need to adjust the offset = end of the overlapping spec + alignment. - spec.mem_offset = get_aligned_offset( - overlapped.mem_offset + overlapped.allocated_memory, - self.get_alignment(spec.mem_id), + spec.mem_offset = get_aligned_offset( # type: ignore[assignment] + overlapped.mem_offset + overlapped.allocated_memory, # type: ignore[operator] + self.get_alignment(spec.mem_id), # type: ignore[arg-type] ) if self.is_valid_placement(spec, placement_constraints): @@ -115,12 +115,12 @@ def plan_spec( """ Greedily place the spec in the first memory that can fit it. """ - for spec.mem_id in range(1, self.get_num_memories()): - if placement_constraints.is_mem_id_in_blocklist(spec, spec.mem_id): + for spec.mem_id in range(1, self.get_num_memories()): # type: ignore[assignment] + if placement_constraints.is_mem_id_in_blocklist(spec, spec.mem_id): # type: ignore[arg-type] # Skip placement for blocked memory id. continue prev_offset, smallest_gap = 0, float("inf") - for allocated_spec in state.allocated_buffers[spec.mem_id]: + for allocated_spec in state.allocated_buffers[spec.mem_id]: # type: ignore[call-overload] if not Verifier.lifetime_overlap(spec, allocated_spec): continue @@ -128,7 +128,7 @@ def plan_spec( gap := allocated_spec.mem_offset - prev_offset ) >= spec.allocated_memory and gap < smallest_gap: smallest_gap = gap - spec.mem_offset = prev_offset + spec.mem_offset = prev_offset # type: ignore[assignment] # Note that different from the paper, which updates prev_offset for all # allocated tensors, we only update tensors with overlapping lifetime. # Updating prev_offset outside the if statement will include tensors without @@ -138,12 +138,12 @@ def plan_spec( prev_offset = max( get_aligned_offset( allocated_spec.mem_offset + allocated_spec.allocated_memory, - self.get_alignment(spec.mem_id), + self.get_alignment(spec.mem_id), # type: ignore[arg-type] ), prev_offset, ) if spec.mem_offset is None: - spec.mem_offset = prev_offset + spec.mem_offset = prev_offset # type: ignore[assignment] if not self.is_valid_placement(spec, placement_constraints): # Skip placement for invalid memory id. @@ -153,7 +153,7 @@ def plan_spec( state.place_spec(spec) # A data structure used for maintaining the tensor order # by offset, named ordered_allocated_ids in the paper - state.allocated_buffers[spec.mem_id].sort(key=lambda spec: spec.mem_offset) + state.allocated_buffers[spec.mem_id].sort(key=lambda spec: spec.mem_offset) # type: ignore[call-overload] break def plan( @@ -200,7 +200,7 @@ def find_peak_memory_usages_per_memory( # Create a defaultdict to keep track of memory usages: {mem_id: mem_usage} # Use a defaultdict here because we don't know how many unique memory_id in # the memory hierarchy used in memory planning. - usages = collections.defaultdict(int) + usages: collections.defaultdict[Any, int] = collections.defaultdict(int) # type: ignore[var-annotated] # go through all nodes in the graph, collect memory usage per spec.mem_id for spec in collect_specs_from_graph_module( @@ -209,7 +209,7 @@ def find_peak_memory_usages_per_memory( if mem_constraints is not None and mem_constraints.skipped_spec(spec): continue usages[spec.mem_id] = max( - usages[spec.mem_id], spec.mem_offset + spec.allocated_memory + usages[spec.mem_id], spec.mem_offset + spec.allocated_memory # type: ignore[operator] ) # Convert usages dictionary into list of len of max memory id diff --git a/backends/cadence/aot/memory_planning_algo.py b/backends/cadence/aot/memory_planning_algo.py index 672f48a55fd..490f3f7481a 100644 --- a/backends/cadence/aot/memory_planning_algo.py +++ b/backends/cadence/aot/memory_planning_algo.py @@ -42,17 +42,17 @@ def place_spec(self, spec: TensorSpec) -> None: """Place the spec at the given memory and offset.""" logging.debug(f"Placing spec {spec}: {spec.mem_id=}, {spec.mem_offset=}") assert self.get_overlapping_spec(spec) is None - self.allocated_buffers[spec.mem_id].append(spec) - self.bufsizes[spec.mem_id] = max( - self.bufsizes[spec.mem_id], + self.allocated_buffers[spec.mem_id].append(spec) # type: ignore[call-overload] + self.bufsizes[spec.mem_id] = max( # type: ignore[call-overload] + self.bufsizes[spec.mem_id], # type: ignore[call-overload] get_aligned_offset( - spec.mem_offset + spec.allocated_memory, self.alignment[spec.mem_id] + spec.mem_offset + spec.allocated_memory, self.alignment[spec.mem_id] # type: ignore[operator,call-overload] ), ) def get_overlapping_spec(self, spec: TensorSpec) -> Optional[TensorSpec]: """Get the overlapping spec for the given spec.""" - for allocated_spec in self.allocated_buffers[spec.mem_id]: + for allocated_spec in self.allocated_buffers[spec.mem_id]: # type: ignore[call-overload] if Verifier.lifetime_overlap( spec, allocated_spec ) and Verifier.storage_overlap(spec, allocated_spec): @@ -131,13 +131,13 @@ def is_valid_placement( ) -> bool: """Returns true if the spec can be placed at the given memory id.""" end_of_allocation = get_aligned_offset( - spec.mem_offset + spec.allocated_memory, - self.get_alignment(spec.mem_id), + spec.mem_offset + spec.allocated_memory, # type: ignore[operator] + self.get_alignment(spec.mem_id), # type: ignore[arg-type] ) return ( - self.memory_id_is_valid[spec.mem_id] - and end_of_allocation <= self.get_size(spec.mem_id) - and not placement_constraints.is_mem_id_in_blocklist(spec, spec.mem_id) + self.memory_id_is_valid[spec.mem_id] # type: ignore[call-overload] + and end_of_allocation <= self.get_size(spec.mem_id) # type: ignore[arg-type] + and not placement_constraints.is_mem_id_in_blocklist(spec, spec.mem_id) # type: ignore[arg-type] ) @contextmanager @@ -180,8 +180,8 @@ def _place_pinned_specs( if c is not None and c.offset is not None } for spec, constraint in pinned_specs.items(): - spec.mem_id = constraint.pinned_memory_id - spec.mem_offset = constraint.offset + spec.mem_id = constraint.pinned_memory_id # type: ignore[assignment] + spec.mem_offset = constraint.offset # type: ignore[assignment] state.place_spec(spec) placement_constraints.resolve_relative_loc_constraints(spec) diff --git a/backends/cadence/aot/ops_registrations.py b/backends/cadence/aot/ops_registrations.py index 8ba19b8106c..4e51b90532d 100644 --- a/backends/cadence/aot/ops_registrations.py +++ b/backends/cadence/aot/ops_registrations.py @@ -493,7 +493,7 @@ ) -@register_fake("cadence::quantize_per_tensor") +@register_fake("cadence::quantize_per_tensor") # type: ignore[misc] def quantize_per_tensor_meta( input: torch.Tensor, scale: float, @@ -505,7 +505,7 @@ def quantize_per_tensor_meta( return input.new_empty(input.size(), dtype=dtype) -@register_fake("cadence::dequantize_per_tensor") +@register_fake("cadence::dequantize_per_tensor") # type: ignore[misc] def dequantize_per_tensor_meta( input: torch.Tensor, scale: float, @@ -517,7 +517,7 @@ def dequantize_per_tensor_meta( return input.new_empty(input.size(), dtype=torch.float) -@register_fake("cadence::quantized_add") +@register_fake("cadence::quantized_add") # type: ignore[misc] def quantized_add_meta( X: torch.Tensor, X_scale: torch.Tensor, @@ -534,7 +534,7 @@ def quantized_add_meta( return X.new_empty(out_size, dtype=X.dtype) -@register_fake("cadence::quantized_add.per_tensor") +@register_fake("cadence::quantized_add.per_tensor") # type: ignore[misc] def quantized_add_per_tensor_meta( X: torch.Tensor, X_scale: float, @@ -550,7 +550,7 @@ def quantized_add_per_tensor_meta( return X.new_empty(out_size, dtype=X.dtype) -@register_fake("cadence::quantized_add_asym8sxasym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_add_asym8sxasym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_add_asym8sxasym8s_asym8s_per_tensor_meta( X: torch.Tensor, X_scale: float, @@ -565,7 +565,7 @@ def quantized_add_asym8sxasym8s_asym8s_per_tensor_meta( return X.new_empty(out_size, dtype=X.dtype) -@register_fake("cadence::quantized_add_asym8uxasym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_add_asym8uxasym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_add_asym8uxasym8u_asym8u_per_tensor_meta( X: torch.Tensor, X_scale: float, @@ -580,7 +580,7 @@ def quantized_add_asym8uxasym8u_asym8u_per_tensor_meta( return X.new_empty(out_size, dtype=X.dtype) -@register_fake("cadence::quantized_linear") +@register_fake("cadence::quantized_linear") # type: ignore[misc] def quantized_linear_meta( src: torch.Tensor, weight: torch.Tensor, @@ -602,7 +602,7 @@ def quantized_linear_meta( return src.new_empty(out_size, dtype=src.dtype) -@register_fake("cadence::quantized_linear.per_tensor") +@register_fake("cadence::quantized_linear.per_tensor") # type: ignore[misc] def quantized_linear_per_tensor_meta( src: torch.Tensor, weight: torch.Tensor, @@ -624,7 +624,7 @@ def quantized_linear_per_tensor_meta( return src.new_empty(out_size, dtype=src.dtype) -@register_fake("cadence::quantized_linear_asym8sxasym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_linear_asym8sxasym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_linear_asym8sxasym8s_asym8s_per_tensor_meta( src: torch.Tensor, weight: torch.Tensor, @@ -646,7 +646,7 @@ def quantized_linear_asym8sxasym8s_asym8s_per_tensor_meta( return src.new_empty(out_size, dtype=src.dtype) -@register_fake("cadence::quantized_linear_asym8uxasym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_linear_asym8uxasym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_linear_asym8uxasym8u_asym8u_per_tensor_meta( src: torch.Tensor, weight: torch.Tensor, @@ -668,7 +668,7 @@ def quantized_linear_asym8uxasym8u_asym8u_per_tensor_meta( return src.new_empty(out_size, dtype=src.dtype) -@register_fake("cadence::quantized_conv_nhwc") +@register_fake("cadence::quantized_conv_nhwc") # type: ignore[misc] def quantized_conv_nhwc_meta( input: torch.Tensor, weight: torch.Tensor, @@ -697,9 +697,9 @@ def quantized_conv_nhwc_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], True, ) @@ -712,7 +712,7 @@ def quantized_conv_nhwc_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nchw") +@register_fake("cadence::quantized_conv_nchw") # type: ignore[misc] def quantized_conv_nchw_meta( input: torch.Tensor, weight: torch.Tensor, @@ -741,9 +741,9 @@ def quantized_conv_nchw_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], False, ) @@ -756,7 +756,7 @@ def quantized_conv_nchw_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nchw.per_tensor") +@register_fake("cadence::quantized_conv_nchw.per_tensor") # type: ignore[misc] def quantized_conv_nchw_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -785,9 +785,9 @@ def quantized_conv_nchw_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], False, ) @@ -800,7 +800,7 @@ def quantized_conv_nchw_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nhwc.per_tensor") +@register_fake("cadence::quantized_conv_nhwc.per_tensor") # type: ignore[misc] def quantized_conv_nhwc_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -829,9 +829,9 @@ def quantized_conv_nhwc_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], True, ) @@ -844,7 +844,7 @@ def quantized_conv_nhwc_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nchw_asym8sxsym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_conv_nchw_asym8sxsym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_conv_nchw_asym8sxsym8s_asym8s_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -873,9 +873,9 @@ def quantized_conv_nchw_asym8sxsym8s_asym8s_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], False, ) @@ -888,7 +888,7 @@ def quantized_conv_nchw_asym8sxsym8s_asym8s_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nchw_asym8uxsym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_conv_nchw_asym8uxsym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_conv_nchw_asym8uxsym8u_asym8u_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -917,9 +917,9 @@ def quantized_conv_nchw_asym8uxsym8u_asym8u_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], False, ) @@ -932,7 +932,7 @@ def quantized_conv_nchw_asym8uxsym8u_asym8u_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nhwc_asym8sxsym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_conv_nhwc_asym8sxsym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_conv_nhwc_asym8sxsym8s_asym8s_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -961,9 +961,9 @@ def quantized_conv_nhwc_asym8sxsym8s_asym8s_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], True, ) @@ -976,7 +976,7 @@ def quantized_conv_nhwc_asym8sxsym8s_asym8s_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nhwc_asym8uxsym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_conv_nhwc_asym8uxsym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_conv_nhwc_asym8uxsym8u_asym8u_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1005,9 +1005,9 @@ def quantized_conv_nhwc_asym8uxsym8u_asym8u_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], True, ) @@ -1020,7 +1020,7 @@ def quantized_conv_nhwc_asym8uxsym8u_asym8u_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nchw_dilated_asym8sxsym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_conv_nchw_dilated_asym8sxsym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_conv_nchw_dilated_asym8sxsym8s_asym8s_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1049,9 +1049,9 @@ def quantized_conv_nchw_dilated_asym8sxsym8s_asym8s_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], False, ) @@ -1064,7 +1064,7 @@ def quantized_conv_nchw_dilated_asym8sxsym8s_asym8s_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nchw_dilated_asym8uxsym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_conv_nchw_dilated_asym8uxsym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_conv_nchw_dilated_asym8uxsym8u_asym8u_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1093,9 +1093,9 @@ def quantized_conv_nchw_dilated_asym8uxsym8u_asym8u_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], False, ) @@ -1108,7 +1108,7 @@ def quantized_conv_nchw_dilated_asym8uxsym8u_asym8u_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nhwc_dilated_asym8sxsym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_conv_nhwc_dilated_asym8sxsym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_conv_nhwc_dilated_asym8sxsym8s_asym8s_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1137,9 +1137,9 @@ def quantized_conv_nhwc_dilated_asym8sxsym8s_asym8s_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], True, ) @@ -1152,7 +1152,7 @@ def quantized_conv_nhwc_dilated_asym8sxsym8s_asym8s_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nhwc_dilated_asym8uxsym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_conv_nhwc_dilated_asym8uxsym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_conv_nhwc_dilated_asym8uxsym8u_asym8u_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1181,9 +1181,9 @@ def quantized_conv_nhwc_dilated_asym8uxsym8u_asym8u_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], True, ) @@ -1196,7 +1196,7 @@ def quantized_conv_nhwc_dilated_asym8uxsym8u_asym8u_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nchw_depthwise_asym8sxsym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_conv_nchw_depthwise_asym8sxsym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_conv_nchw_depthwise_asym8sxsym8s_asym8s_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1225,9 +1225,9 @@ def quantized_conv_nchw_depthwise_asym8sxsym8s_asym8s_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], False, ) @@ -1240,7 +1240,7 @@ def quantized_conv_nchw_depthwise_asym8sxsym8s_asym8s_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nchw_depthwise_asym8uxsym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_conv_nchw_depthwise_asym8uxsym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_conv_nchw_depthwise_asym8uxsym8u_asym8u_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1269,9 +1269,9 @@ def quantized_conv_nchw_depthwise_asym8uxsym8u_asym8u_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], False, ) @@ -1284,7 +1284,7 @@ def quantized_conv_nchw_depthwise_asym8uxsym8u_asym8u_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nhwc_depthwise_asym8sxsym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_conv_nhwc_depthwise_asym8sxsym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_conv_nhwc_depthwise_asym8sxsym8s_asym8s_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1313,9 +1313,9 @@ def quantized_conv_nhwc_depthwise_asym8sxsym8s_asym8s_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], True, ) @@ -1328,7 +1328,7 @@ def quantized_conv_nhwc_depthwise_asym8sxsym8s_asym8s_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_conv_nhwc_depthwise_asym8uxsym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_conv_nhwc_depthwise_asym8uxsym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_conv_nhwc_depthwise_asym8uxsym8u_asym8u_per_tensor_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1357,9 +1357,9 @@ def quantized_conv_nhwc_depthwise_asym8uxsym8u_asym8u_per_tensor_meta( get_conv1d_output_size( in_size, out_channels, - stride[1], - padding[1], - dilation[1], + stride[1], # type: ignore[misc] + padding[1], # type: ignore[misc] + dilation[1], # type: ignore[misc] kernel_size[0], True, ) @@ -1372,7 +1372,7 @@ def quantized_conv_nhwc_depthwise_asym8uxsym8u_asym8u_per_tensor_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::quantized_layer_norm") +@register_fake("cadence::quantized_layer_norm") # type: ignore[misc] def quantized_layer_norm_meta( input: torch.Tensor, X_scale: torch.Tensor, @@ -1387,7 +1387,7 @@ def quantized_layer_norm_meta( return input.new_empty(input.size(), dtype=input.dtype) -@register_fake("cadence::quantized_layer_norm.per_tensor") +@register_fake("cadence::quantized_layer_norm.per_tensor") # type: ignore[misc] def quantized_layer_norm_per_tensor_meta( input: torch.Tensor, X_scale: float, @@ -1402,7 +1402,7 @@ def quantized_layer_norm_per_tensor_meta( return input.new_empty(input.size(), dtype=input.dtype) -@register_fake("cadence::quantized_relu") +@register_fake("cadence::quantized_relu") # type: ignore[misc] def quantized_relu_meta( X: torch.Tensor, X_zero_point: torch.Tensor, @@ -1413,7 +1413,7 @@ def quantized_relu_meta( return X.new_empty(X.size(), dtype=X.dtype) -@register_fake("cadence::quantized_matmul") +@register_fake("cadence::quantized_matmul") # type: ignore[misc] def quantized_matmul_meta( X: torch.Tensor, X_zero_point: int, @@ -1456,7 +1456,7 @@ def quantized_matmul_meta( return X.new_empty(out_size, dtype=X.dtype) -@register_fake("cadence::quantized_matmul_asym8sxasym8s_asym8s") +@register_fake("cadence::quantized_matmul_asym8sxasym8s_asym8s") # type: ignore[misc] def quantized_matmul_asym8sxasym8s_asym8s_meta( X: torch.Tensor, X_zero_point: int, @@ -1499,7 +1499,7 @@ def quantized_matmul_asym8sxasym8s_asym8s_meta( return X.new_empty(out_size, dtype=X.dtype) -@register_fake("cadence::quantized_matmul_asym8uxasym8u_asym8u") +@register_fake("cadence::quantized_matmul_asym8uxasym8u_asym8u") # type: ignore[misc] def quantized_matmul_asym8uxasym8u_asym8u_meta( X: torch.Tensor, X_zero_point: int, @@ -1542,7 +1542,7 @@ def quantized_matmul_asym8uxasym8u_asym8u_meta( return X.new_empty(out_size, dtype=X.dtype) -@register_fake("cadence::im2row") +@register_fake("cadence::im2row") # type: ignore[misc] def im2row_meta( input: torch.Tensor, kernel_size: Tuple[int], @@ -1558,7 +1558,7 @@ def im2row_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::im2row.per_tensor") +@register_fake("cadence::im2row.per_tensor") # type: ignore[misc] def im2row_per_tensor_meta( input: torch.Tensor, kernel_size: Tuple[int], @@ -1575,7 +1575,7 @@ def im2row_per_tensor_meta( # Define the abstract implementations of the operators as required -@register_fake("cadence::linalg_vector_norm") +@register_fake("cadence::linalg_vector_norm") # type: ignore[misc] def linalg_vector_norm_meta( X: torch.Tensor, ) -> torch.Tensor: @@ -1583,7 +1583,7 @@ def linalg_vector_norm_meta( return X.new_empty([], dtype=X.dtype) -@register_fake("cadence::linalg_svd") +@register_fake("cadence::linalg_svd") # type: ignore[misc] def linalg_svd_meta( A: torch.Tensor, full_matrices: bool = False, @@ -1603,7 +1603,7 @@ def linalg_svd_meta( return U_contiguous, S_contiguous, Vh_contiguous -@register_fake("cadence::requantize") +@register_fake("cadence::requantize") # type: ignore[misc] def requantize_meta( input: torch.Tensor, in_scale: torch.Tensor, @@ -1612,14 +1612,14 @@ def requantize_meta( out_zero_point: torch.Tensor, dtype: ScalarType, ) -> torch.Tensor: - return input.new_empty( + return input.new_empty( # type: ignore[call-overload] input.size(), # pyre-ignore[6]: Incompatible type dtype=dtype, ) -@register_fake("cadence::requantize.per_tensor") +@register_fake("cadence::requantize.per_tensor") # type: ignore[misc] def requantize_per_tensor_meta( input: torch.Tensor, in_scale: float, @@ -1628,14 +1628,14 @@ def requantize_per_tensor_meta( out_zero_point: int, dtype: ScalarType, ) -> torch.Tensor: - return input.new_empty( + return input.new_empty( # type: ignore[call-overload] input.size(), # pyre-ignore[6]: Incompatible type dtype=dtype, ) -@register_fake("cadence::quantized_relu.per_tensor") +@register_fake("cadence::quantized_relu.per_tensor") # type: ignore[misc] def quantized_relu_per_tensor_meta( input: torch.Tensor, in_zero_point: int, @@ -1646,7 +1646,7 @@ def quantized_relu_per_tensor_meta( return input.new_empty(input.size(), dtype=input.dtype) -@register_fake("cadence::quantized_relu_asym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_relu_asym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_relu_asym8s_asym8s_per_tensor_meta( input: torch.Tensor, in_zero_point: int, @@ -1657,7 +1657,7 @@ def quantized_relu_asym8s_asym8s_per_tensor_meta( return input.new_empty(input.size(), dtype=input.dtype) -@register_fake("cadence::quantized_relu_asym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_relu_asym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_relu_asym8u_asym8u_per_tensor_meta( input: torch.Tensor, in_zero_point: int, @@ -1668,7 +1668,7 @@ def quantized_relu_asym8u_asym8u_per_tensor_meta( return input.new_empty(input.size(), dtype=input.dtype) -@register_fake("cadence::fully_connected") +@register_fake("cadence::fully_connected") # type: ignore[misc] def fully_connected_meta( src: torch.Tensor, weight: torch.Tensor, @@ -1684,7 +1684,7 @@ def fully_connected_meta( return src.new_empty(out_size, dtype=src.dtype) -@register_fake("cadence::quantized_fully_connected") +@register_fake("cadence::quantized_fully_connected") # type: ignore[misc] def quantized_fully_connected_meta( src: torch.Tensor, weight: torch.Tensor, @@ -1706,7 +1706,7 @@ def quantized_fully_connected_meta( return src.new_empty(out_size, dtype=src.dtype) -@register_fake("cadence::quantized_fully_connected.per_tensor") +@register_fake("cadence::quantized_fully_connected.per_tensor") # type: ignore[misc] def quantized_fully_connected_per_tensor_meta( src: torch.Tensor, weight: torch.Tensor, @@ -1728,7 +1728,7 @@ def quantized_fully_connected_per_tensor_meta( return src.new_empty(out_size, dtype=src.dtype) -@register_fake("cadence::quantized_fully_connected_asym8sxasym8s_asym8s.per_tensor") +@register_fake("cadence::quantized_fully_connected_asym8sxasym8s_asym8s.per_tensor") # type: ignore[misc] def quantized_fully_connected_asym8sxasym8s_asym8s_per_tensor_meta( src: torch.Tensor, weight: torch.Tensor, @@ -1750,7 +1750,7 @@ def quantized_fully_connected_asym8sxasym8s_asym8s_per_tensor_meta( return src.new_empty(out_size, dtype=src.dtype) -@register_fake("cadence::quantized_fully_connected_asym8uxasym8u_asym8u.per_tensor") +@register_fake("cadence::quantized_fully_connected_asym8uxasym8u_asym8u.per_tensor") # type: ignore[misc] def quantized_fully_connected_asym8uxasym8u_asym8u_per_tensor_meta( src: torch.Tensor, weight: torch.Tensor, @@ -1772,7 +1772,7 @@ def quantized_fully_connected_asym8uxasym8u_asym8u_per_tensor_meta( return src.new_empty(out_size, dtype=src.dtype) -@register_fake("cadence::convolution") +@register_fake("cadence::convolution") # type: ignore[misc] def convolution_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1812,7 +1812,7 @@ def convolution_meta( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::transposed_convolution") +@register_fake("cadence::transposed_convolution") # type: ignore[misc] def transposed_convolution_meta( input: torch.Tensor, weight: torch.Tensor, @@ -1888,10 +1888,10 @@ def get_conv_transpose2d_output_size( + 1 ) wout = ( - (W - 1) * stride[1] - - 2 * padding[1] - + dilation[1] * (kernel_size[1] - 1) - + output_padding[1] + (W - 1) * stride[1] # type: ignore[misc] + - 2 * padding[1] # type: ignore[misc] + + dilation[1] * (kernel_size[1] - 1) # type: ignore[misc] + + output_padding[1] # type: ignore[misc] + 1 ) @@ -1931,7 +1931,7 @@ def get_conv_transpose2d_output_size( return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::avg_pool2d") +@register_fake("cadence::avg_pool2d") # type: ignore[misc] def avg_pool2d_meta( input: torch.Tensor, kernel_size: Tuple[int], @@ -1955,7 +1955,7 @@ def avg_pool2d_meta( ) -@register_fake("cadence::transposed_im2row") +@register_fake("cadence::transposed_im2row") # type: ignore[misc] def transposed_im2row_meta( input: torch.Tensor, kernel_size: Tuple[int], @@ -1982,20 +1982,20 @@ def transposed_im2row_meta( + 1 ) output_width = ( - (input_width - 1) * stride[1] - - 2 * padding[1] - + dilation[1] * (kernel_size[1] - 1) - + output_padding[1] + (input_width - 1) * stride[1] # type: ignore[misc] + - 2 * padding[1] # type: ignore[misc] + + dilation[1] * (kernel_size[1] - 1) # type: ignore[misc] + + output_padding[1] # type: ignore[misc] + 1 ) - n_output_plane = n_input_plane * kernel_size[0] * kernel_size[1] + n_output_plane = n_input_plane * kernel_size[0] * kernel_size[1] # type: ignore[misc] output_length = output_height * output_width output_size = torch.Size((batch_size, output_length, n_output_plane)) return input.new_empty(output_size, dtype=input.dtype) -@register_fake("cadence::where_Scalar") +@register_fake("cadence::where_Scalar") # type: ignore[misc] def where_Scalar_meta( condition: torch.Tensor, self: float, @@ -2004,7 +2004,7 @@ def where_Scalar_meta( return condition.new_empty(condition.size(), dtype=torch.float32) -@register_fake("cadence::rope") +@register_fake("cadence::rope") # type: ignore[misc] def rope_meta( input: torch.Tensor, sin_tensor: torch.Tensor, @@ -2031,7 +2031,7 @@ def rope_meta( return input.new_empty(input.shape, dtype=input.dtype) -@register_fake("cadence::idma_copy") +@register_fake("cadence::idma_copy") # type: ignore[misc] def copy_idma_copy_impl( src: torch.Tensor, task_num: int = 0, @@ -2040,7 +2040,7 @@ def copy_idma_copy_impl( return src.new_empty(*src.shape, dtype=src.dtype) -@register_fake("cadence::idma_wait") +@register_fake("cadence::idma_wait") # type: ignore[misc] def copy_idma_wait_impl( src: torch.Tensor, task_num: int = 0, @@ -2048,7 +2048,7 @@ def copy_idma_wait_impl( return src.new_empty(*src.shape, dtype=src.dtype) -@register_fake("cadence::idma_load") +@register_fake("cadence::idma_load") # type: ignore[misc] def idma_load_impl( src: torch.Tensor, task_num: int = 0, @@ -2057,7 +2057,7 @@ def idma_load_impl( return copy_idma_copy_impl(src, task_num, channel) -@register_fake("cadence::idma_store") +@register_fake("cadence::idma_store") # type: ignore[misc] def idma_store_impl( src: torch.Tensor, task_num: int = 0, @@ -2066,7 +2066,7 @@ def idma_store_impl( return copy_idma_copy_impl(src, task_num, channel) -@register_fake("cadence::roi_align_box_processor") +@register_fake("cadence::roi_align_box_processor") # type: ignore[misc] def roi_align_box_processor_meta( rois: torch.Tensor, output_size_h: int, diff --git a/backends/cadence/aot/program_builder.py b/backends/cadence/aot/program_builder.py index d73cc9fcfbf..64997037fb2 100644 --- a/backends/cadence/aot/program_builder.py +++ b/backends/cadence/aot/program_builder.py @@ -54,7 +54,7 @@ def insert_input_spec( elif input_kind == InputKind.CONSTANT_TENSOR: self.constants[target] = value - def placeholder( + def placeholder( # type: ignore[override] self, target: str, fake_tensor: Tensor, @@ -64,7 +64,7 @@ def placeholder( self.insert_input_spec(target, input_kind, fake_tensor) return placeholder - def output( + def output( # type: ignore[override] self, results: list[ProxyValue], output_kinds: Optional[list[OutputKind]] = None ) -> ProxyValue: if output_kinds is None: @@ -94,12 +94,12 @@ def get_program(self) -> ExportedProgram: input_specs=self.input_specs, output_specs=self.output_specs ), # pyre-ignore[6]: Incompatible parameter type. - constants=self.constants, + constants=self.constants, # type: ignore[arg-type] state_dict=self.state_dict, range_constraints={}, module_call_graph=[], # pyre-ignore[6]: Incompatible parameter type. - verifiers=self.get_verifiers(), + verifiers=self.get_verifiers(), # type: ignore[arg-type] ) def get_edge_program(self) -> EdgeProgramManager: diff --git a/backends/cadence/aot/quantizer/fusion_pass.py b/backends/cadence/aot/quantizer/fusion_pass.py index 729056ea2c8..ba567ea6dbb 100644 --- a/backends/cadence/aot/quantizer/fusion_pass.py +++ b/backends/cadence/aot/quantizer/fusion_pass.py @@ -80,7 +80,7 @@ def get_args_and_kwargs_add( quant_node.args[2], ) - kwargs = {} + kwargs = {} # type: ignore[var-annotated] return args, kwargs @@ -99,8 +99,8 @@ def get_args_and_kwargs_linear( """ weight_scale = dequants_weights[0].args[1] # pyre-fixme[58]: Unsupported operand types - bias_scale = dequants_inputs[0].args[1] * weight_scale - requantize_scale = bias_scale / quant_node.args[1] + bias_scale = dequants_inputs[0].args[1] * weight_scale # type: ignore[operator] + requantize_scale = bias_scale / quant_node.args[1] # type: ignore[operator,arg-type] requantize_scale_t = torch.tensor([requantize_scale]) (out_multiplier, out_shift) = quantize_tensor_multiplier(requantize_scale_t) @@ -109,7 +109,7 @@ def get_args_and_kwargs_linear( if not bias_inputs: weight_node = dequants_weights[0].args[0] assert isinstance(weight_node, fx.Node) - bias = create_zero_bias_int32(graph_module, weight_node, bias_scale) + bias = create_zero_bias_int32(graph_module, weight_node, bias_scale) # type: ignore[arg-type] else: bias = bias_inputs[0] @@ -141,7 +141,7 @@ def get_args_and_kwargs_linear( "out_zero_point": quant_node.args[2], "offset": None, } - return args, kwargs + return args, kwargs # type: ignore[return-value] # Helper function to get the args and kwargs for the layer norm replacement op @@ -213,7 +213,7 @@ def get_args_and_kwargs_layer_norm( "output_scale": quant_node.args[1], "output_zero_point": quant_node.args[2], } - return args, kwargs + return args, kwargs # type: ignore[return-value] def get_args_and_kwargs_matmul( @@ -221,9 +221,9 @@ def get_args_and_kwargs_matmul( dequants_inputs: List[fx.Node], quant_node: fx.Node, ) -> Tuple[Tuple[ArgsType, ...], Dict[str, ArgsType]]: - requantize_scale = ( + requantize_scale = ( # type: ignore[operator,arg-type] # pyre-ignore[58]: Unsupported operand - dequants_inputs[0].args[1] + dequants_inputs[0].args[1] # type: ignore[operator] * dequants_inputs[1].args[1] ) / quant_node.args[1] requantize_scale_t = torch.tensor([requantize_scale]) @@ -250,11 +250,11 @@ def get_args_and_kwargs_matmul( def get_args_and_kwargs_cat( inputs_inputs: List[fx.Node], other_inputs: List[fx.Node], op_node: fx.Node ) -> Tuple[Tuple[ArgsType], Dict[str, ArgsType]]: - args = tuple([inputs_inputs] + other_inputs) + args = tuple([inputs_inputs] + other_inputs) # type: ignore[operator] dim = op_node.args[1] if len(op_node.args) > 1 else 0 # pyre-fixme[6]: Incompatible parameter type - kwargs = {"dim": int(dim)} - return args, kwargs + kwargs = {"dim": int(dim)} # type: ignore[arg-type] + return args, kwargs # type: ignore[return-value] def get_args_and_kwargs_conv( @@ -270,7 +270,7 @@ def get_args_and_kwargs_conv( weight_scale = dequants_weights[0].args[1] weight_zero_point = dequants_weights[0].args[2] # pyre-fixme[58]: Unsupported operand types - bias_scale = dequants_inputs[0].args[1] * weight_scale + bias_scale = dequants_inputs[0].args[1] * weight_scale # type: ignore[operator] stride = [1, 1] if len(op_node.args) < 4 else get_conv_args(op_node.args[3], 1) padding = [0, 0] if len(op_node.args) < 5 else get_conv_args(op_node.args[4], 0) dilation = [1, 1] if len(op_node.args) < 6 else get_conv_args(op_node.args[5], 1) @@ -280,14 +280,14 @@ def get_args_and_kwargs_conv( if not bias_inputs: weight_node = dequants_weights[0].args[0] assert isinstance(weight_node, fx.Node) - bias = create_zero_bias_int32(graph_module, weight_node, bias_scale) + bias = create_zero_bias_int32(graph_module, weight_node, bias_scale) # type: ignore[arg-type] else: bias = bias_inputs[0] # Compute the out multiplier and out shift. They are used when the conv op is # replaced by quantized linear, we compute them a priori for simplicity but # may revisit the decision. - requantize_scale = bias_scale / quant_node.args[1] + requantize_scale = bias_scale / quant_node.args[1] # type: ignore[operator,arg-type] requantize_scale_t = torch.tensor([requantize_scale]) (out_multiplier, out_shift) = quantize_tensor_multiplier(requantize_scale_t) @@ -332,7 +332,7 @@ def get_args_and_kwargs_conv( "out_multiplier": out_multiplier_, "out_shift": out_shift_, } - return args, kwargs + return args, kwargs # type: ignore[return-value] def get_args_and_kwargs_relu( @@ -343,7 +343,7 @@ def get_args_and_kwargs_relu( ) -> Tuple[Tuple[ArgsType], Dict[str, ArgsType]]: input_scale = dequants_inputs[0].args[1] # pyre-fixme[58]: Unsupported operand types - requantize_scale = input_scale / quant_node.args[1] + requantize_scale = input_scale / quant_node.args[1] # type: ignore[operator,arg-type] requantize_scale_t = torch.tensor([requantize_scale]) (out_multiplier, out_shift) = quantize_tensor_multiplier(requantize_scale_t) @@ -373,7 +373,7 @@ def get_args_and_kwargs_relu( "out_multiplier": out_multiplier_, "out_shift": out_shift_, } - return args, kwargs + return args, kwargs # type: ignore[return-value] class QuantFusion(ExportPass): @@ -383,7 +383,9 @@ def __init__(self, patterns) -> None: # pyre-ignore[4]: Parameter `patterns` of class `QuantFusion` has no type specified self.patterns = patterns - def call(self, graph_module: fx.GraphModule) -> PassResult: # noqa: C901 + def call( # noqa: C901 + self, graph_module: fx.GraphModule + ) -> PassResult: # type: ignore[return] for pattern in self.patterns: fused_partitions = find_sequential_partitions_aten( graph_module, @@ -441,7 +443,7 @@ def call(self, graph_module: fx.GraphModule) -> PassResult: # noqa: C901 args = tuple( inputs_inputs + weights_inputs + other_inputs + bias_inputs ) - kwargs = {} + kwargs = {} # type: ignore[var-annotated] if isinstance(pattern, AddPattern): args, kwargs = get_args_and_kwargs_add( graph_module, @@ -523,6 +525,7 @@ def call(self, graph_module: fx.GraphModule) -> PassResult: # noqa: C901 graph_module.graph.eliminate_dead_code() # pyre-fixme[7]: Incompatible return type graph_module.recompile() + return PassResult(graph_module, True) @classmethod # pyre-ignore[2]: Parameter `nodes` has no type specified @@ -531,7 +534,7 @@ def is_fused(cls, nodes) -> bool: @classmethod # pyre-ignore[2]: Parameter `nodes` has no type specified - def mark_fused(cls, nodes) -> bool: + def mark_fused(cls, nodes) -> None: for n in nodes: # pyre-fixme[7]: Incompatible return type n.meta["QuantFusion"] = True diff --git a/backends/cadence/aot/quantizer/patterns.py b/backends/cadence/aot/quantizer/patterns.py index 74987f8b38d..5bb68733ab5 100644 --- a/backends/cadence/aot/quantizer/patterns.py +++ b/backends/cadence/aot/quantizer/patterns.py @@ -87,12 +87,12 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - addmm_node = fused_partition[0].nodes[-1] + addmm_node = fused_partition[0].nodes[-1] # type: ignore[index] bias_qspec = DerivedQuantizationSpec( derived_from=[ - (addmm_node.args[1], addmm_node), - (addmm_node.args[2], addmm_node), + (addmm_node.args[1], addmm_node), # type: ignore[list-item,union-attr] + (addmm_node.args[2], addmm_node), # type: ignore[list-item,union-attr] ], derive_qparams_fn=get_bias_qparams, dtype=torch.int32, @@ -102,10 +102,10 @@ def get_anchors( ) return PartitionAnchors( - inputs=[(addmm_node, 1)], - weights=[(addmm_node, 2)], - biases=[(addmm_node, 0, bias_qspec)], - output=[(addmm_node,)], + inputs=[(addmm_node, 1)], # type: ignore[list-item] + weights=[(addmm_node, 2)], # type: ignore[list-item] + biases=[(addmm_node, 0, bias_qspec)], # type: ignore[list-item] + output=[(addmm_node,)], # type: ignore[list-item] ) def replacement_op(self) -> OpOverload: @@ -120,24 +120,24 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - add_node = fused_partition[0].nodes[-1] + add_node = fused_partition[0].nodes[-1] # type: ignore[index] # Bail if: # - the add node is not a tensor add # - the add node has kwargs (e.g. alpha) - is_tensor_add = isinstance(add_node.args[0], fx.Node) and isinstance( - add_node.args[1], fx.Node + is_tensor_add = isinstance(add_node.args[0], fx.Node) and isinstance( # type: ignore[union-attr] + add_node.args[1], fx.Node # type: ignore[union-attr] ) - if not is_tensor_add or len(add_node.kwargs) > 0: + if not is_tensor_add or len(add_node.kwargs) > 0: # type: ignore[union-attr] return PartitionAnchors( empty=True, ) return PartitionAnchors( - inputs=[(add_node, 0), (add_node, 1)], + inputs=[(add_node, 0), (add_node, 1)], # type: ignore[list-item] weights=[], biases=[], - output=[(add_node,)], + output=[(add_node,)], # type: ignore[list-item] ) def replacement_op(self) -> OpOverload: @@ -152,13 +152,13 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - bmm_node = fused_partition[0].nodes[-1] + bmm_node = fused_partition[0].nodes[-1] # type: ignore[index] return PartitionAnchors( - inputs=[(bmm_node, 0), (bmm_node, 1)], + inputs=[(bmm_node, 0), (bmm_node, 1)], # type: ignore[list-item] weights=[], biases=[], - output=[(bmm_node,)], + output=[(bmm_node,)], # type: ignore[list-item] ) def replacement_op(self) -> OpOverload: @@ -173,7 +173,7 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - cat_node = fused_partition[0].nodes[-1] + cat_node = fused_partition[0].nodes[-1] # type: ignore[index] # Create args. The first argument does not have quant spec and # will inherit from the overall quant spec. All subsequent args @@ -188,13 +188,15 @@ def get_anchors( SharedQuantizationSpec, ], ] - ] = [(cat_node, (0, 0))] - for i in range(1, len(cat_node.args[0])): + ] = [ + (cat_node, (0, 0)) # type: ignore[list-item] + ] + for i in range(1, len(cat_node.args[0])): # type: ignore[union-attr] args.append( ( cat_node, (0, i), - SharedQuantizationSpec((cat_node.args[0][0], cat_node)), + SharedQuantizationSpec((cat_node.args[0][0], cat_node)), # type: ignore[arg-type,union-attr] ) ) @@ -203,7 +205,7 @@ def get_anchors( weights=[], biases=[], output=[ - (cat_node, SharedQuantizationSpec((cat_node.args[0][0], cat_node))) + (cat_node, SharedQuantizationSpec((cat_node.args[0][0], cat_node))) # type: ignore[list-item,arg-type,union-attr] ], ) @@ -219,12 +221,12 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - conv1d_node = fused_partition[0].nodes[-1] + conv1d_node = fused_partition[0].nodes[-1] # type: ignore[index] bias_qspec = DerivedQuantizationSpec( derived_from=[ - (conv1d_node.args[0], conv1d_node), - (conv1d_node.args[1], conv1d_node), + (conv1d_node.args[0], conv1d_node), # type: ignore[list-item,union-attr] + (conv1d_node.args[1], conv1d_node), # type: ignore[list-item,union-attr] ], derive_qparams_fn=get_bias_qparams, dtype=torch.int32, @@ -235,15 +237,15 @@ def get_anchors( # Keep bias empty if not supplied bias = [] - if len(conv1d_node.args) > 2 and conv1d_node.args[2] is not None: + if len(conv1d_node.args) > 2 and conv1d_node.args[2] is not None: # type: ignore[union-attr] bias = [(conv1d_node, 2, bias_qspec)] return PartitionAnchors( - inputs=[(conv1d_node, 0)], - weights=[(conv1d_node, 1)], + inputs=[(conv1d_node, 0)], # type: ignore[list-item] + weights=[(conv1d_node, 1)], # type: ignore[list-item] # pyre-fixme[6]: Incompatible parameter type - biases=bias, - output=[(conv1d_node,)], + biases=bias, # type: ignore[arg-type] + output=[(conv1d_node,)], # type: ignore[list-item] ) def replacement_op(self) -> OpOverload: @@ -258,12 +260,12 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - conv2d_node = fused_partition[0].nodes[-1] + conv2d_node = fused_partition[0].nodes[-1] # type: ignore[index] bias_qspec = DerivedQuantizationSpec( derived_from=[ - (conv2d_node.args[0], conv2d_node), - (conv2d_node.args[1], conv2d_node), + (conv2d_node.args[0], conv2d_node), # type: ignore[list-item,union-attr] + (conv2d_node.args[1], conv2d_node), # type: ignore[list-item,union-attr] ], derive_qparams_fn=get_bias_qparams, dtype=torch.int32, @@ -274,15 +276,15 @@ def get_anchors( # Keep bias empty if not supplied bias = [] - if len(conv2d_node.args) > 2 and conv2d_node.args[2] is not None: + if len(conv2d_node.args) > 2 and conv2d_node.args[2] is not None: # type: ignore[union-attr] bias = [(conv2d_node, 2, bias_qspec)] return PartitionAnchors( - inputs=[(conv2d_node, 0)], - weights=[(conv2d_node, 1)], + inputs=[(conv2d_node, 0)], # type: ignore[list-item] + weights=[(conv2d_node, 1)], # type: ignore[list-item] # pyre-fixme[6]: Incompatible parameter type - biases=bias, - output=[(conv2d_node,)], + biases=bias, # type: ignore[arg-type] + output=[(conv2d_node,)], # type: ignore[list-item] ) def replacement_op(self) -> OpOverload: @@ -297,27 +299,27 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - layer_norm_node = fused_partition[0].nodes[-1] + layer_norm_node = fused_partition[0].nodes[-1] # type: ignore[index] others = [(layer_norm_node, 1)] # Add weights if supplied - if len(layer_norm_node.args) > 2 and layer_norm_node.args[2]: + if len(layer_norm_node.args) > 2 and layer_norm_node.args[2]: # type: ignore[union-attr] others.append((layer_norm_node, 2)) # Add bias if supplied - if len(layer_norm_node.args) > 3 and layer_norm_node.args[3]: + if len(layer_norm_node.args) > 3 and layer_norm_node.args[3]: # type: ignore[union-attr] others.append((layer_norm_node, 3)) # Weights are used in quantized mode by our kernel, so they are # passed in as others here along with the normalized shape. return PartitionAnchors( - inputs=[(layer_norm_node, 0)], + inputs=[(layer_norm_node, 0)], # type: ignore[list-item] weights=[], biases=[], # Ordering: normalized_shape, weights, bias - others=others, - output=[(layer_norm_node,)], + others=others, # type: ignore[arg-type] + output=[(layer_norm_node,)], # type: ignore[list-item] ) def replacement_op(self) -> OpOverload: @@ -332,12 +334,12 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - linear_node = fused_partition[0].nodes[-1] + linear_node = fused_partition[0].nodes[-1] # type: ignore[index] bias_qspec = DerivedQuantizationSpec( derived_from=[ - (linear_node.args[0], linear_node), - (linear_node.args[1], linear_node), + (linear_node.args[0], linear_node), # type: ignore[list-item,union-attr] + (linear_node.args[1], linear_node), # type: ignore[list-item,union-attr] ], derive_qparams_fn=get_bias_qparams, dtype=torch.int32, @@ -348,15 +350,15 @@ def get_anchors( # Keep bias empty if not supplied bias = [] - if len(linear_node.args) > 2: + if len(linear_node.args) > 2: # type: ignore[union-attr] bias = [(linear_node, 2, bias_qspec)] return PartitionAnchors( - inputs=[(linear_node, 0)], - weights=[(linear_node, 1)], + inputs=[(linear_node, 0)], # type: ignore[list-item] + weights=[(linear_node, 1)], # type: ignore[list-item] # pyre-fixme[6]: Incompatible parameter type - biases=bias, - output=[(linear_node,)], + biases=bias, # type: ignore[arg-type] + output=[(linear_node,)], # type: ignore[list-item] ) def replacement_op(self) -> OpOverload: @@ -371,13 +373,13 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - matmul_node = fused_partition[0].nodes[-1] + matmul_node = fused_partition[0].nodes[-1] # type: ignore[index] return PartitionAnchors( - inputs=[(matmul_node, 0), (matmul_node, 1)], + inputs=[(matmul_node, 0), (matmul_node, 1)], # type: ignore[list-item] weights=[], biases=[], - output=[(matmul_node,)], + output=[(matmul_node,)], # type: ignore[list-item] ) def replacement_op(self) -> OpOverload: @@ -394,13 +396,13 @@ def get_anchors( self, gm: fx.GraphModule, fused_partition: List[fx.GraphModule] ) -> PartitionAnchors: # pyre-fixme[29]: `Union[BoundMethod[typing.Callable(torch._C.TensorBase.__ge... - relu_node = fused_partition[0].nodes[-1] + relu_node = fused_partition[0].nodes[-1] # type: ignore[index] return PartitionAnchors( - inputs=[(relu_node, 0)], + inputs=[(relu_node, 0)], # type: ignore[list-item] weights=[], biases=[], - output=[(relu_node,)], + output=[(relu_node,)], # type: ignore[list-item] ) def replacement_op(self) -> OpOverload: diff --git a/backends/cadence/aot/quantizer/quantizer.py b/backends/cadence/aot/quantizer/quantizer.py index 8c78ac87e58..b0fd75d7771 100644 --- a/backends/cadence/aot/quantizer/quantizer.py +++ b/backends/cadence/aot/quantizer/quantizer.py @@ -164,7 +164,7 @@ def annotate_weights_or_biases( weights_or_biases: List[Tuple[fx.Node, int]], spec: Optional[QuantizationSpec], ) -> None: - for node, idx, *custom_spec in weights_or_biases: + for node, idx, *custom_spec in weights_or_biases: # type: ignore[var-annotated] annotation = node.meta.get( Q_ANNOTATION_KEY, QuantizationAnnotation(_annotated=True), @@ -175,10 +175,10 @@ def annotate_weights_or_biases( node.meta[Q_ANNOTATION_KEY] = annotation # pyre-ignore[6]: incompatible parameter type - annotate_inputs(anchors.inputs, input_act_qspec) + annotate_inputs(anchors.inputs, input_act_qspec) # type: ignore[arg-type] annotate_weights_or_biases(anchors.weights, weight_qspec) # pyre-ignore[6]: incompatible parameter type - annotate_weights_or_biases(anchors.biases, bias_qspec) + annotate_weights_or_biases(anchors.biases, bias_qspec) # type: ignore[arg-type] return model def validate(self, model: fx.GraphModule) -> None: diff --git a/backends/cadence/aot/quantizer/utils.py b/backends/cadence/aot/quantizer/utils.py index beacd1b9e86..9e2a46d2cb9 100644 --- a/backends/cadence/aot/quantizer/utils.py +++ b/backends/cadence/aot/quantizer/utils.py @@ -114,7 +114,7 @@ def create_zero_bias_int32( """ Creates a zero bias tensor with the shape of weight[0] """ - attr_node = getattr(graph_module, weight_node.target) + attr_node = getattr(graph_module, weight_node.target) # type: ignore[arg-type] weight_shape = list(attr_node.shape) bias_shape = weight_shape[0] return graph_module.graph.call_function( @@ -135,7 +135,7 @@ def get_bias_qparams( def get_conv_args(arg, first_val: int) -> List[fx.Node]: - return arg if len(arg) == 2 else [first_val, arg[0]] + return arg if len(arg) == 2 else [first_val, arg[0]] # type: ignore[list-item] def get_aten_node_target_partitions( @@ -231,6 +231,6 @@ def find_sequential_partitions_aten( fusion_candidates = itertools.product(*typed_partitions_list) fused_partitions = [] for candidate in fusion_candidates: - if _partitions_sequential(candidate): + if _partitions_sequential(candidate): # type: ignore[arg-type] fused_partitions.append(candidate) return fused_partitions diff --git a/backends/cadence/aot/ref_implementations.py b/backends/cadence/aot/ref_implementations.py index 21d1efe6398..67b35175050 100644 --- a/backends/cadence/aot/ref_implementations.py +++ b/backends/cadence/aot/ref_implementations.py @@ -135,9 +135,9 @@ def requantize( quant_min = torch.iinfo(input.dtype).min quant_max = torch.iinfo(input.dtype).max # pyre-fixme[6]: This dtype is actually the right one. - out_quant_min = torch.iinfo(dtype).min + out_quant_min = torch.iinfo(dtype).min # type: ignore[arg-type] # pyre-fixme[6]: This dtype is actually the right one. - out_quant_max = torch.iinfo(dtype).max + out_quant_max = torch.iinfo(dtype).max # type: ignore[arg-type] return torch.ops.quantized_decomposed.quantize_per_tensor( torch.ops.quantized_decomposed.dequantize_per_tensor( input, diff --git a/backends/cadence/aot/remove_ops.py b/backends/cadence/aot/remove_ops.py index 663c5825e52..47c07ee5ee0 100644 --- a/backends/cadence/aot/remove_ops.py +++ b/backends/cadence/aot/remove_ops.py @@ -106,7 +106,7 @@ def call_operator( # Otherwise, we replace args[0] with cat_inputs. new_args = list(args) # pyre error introduced after D66937105 - new_args[0] = cat_inputs # pyre-ignore[6] + new_args[0] = cat_inputs # type: ignore[assignment] return super().call_operator(op, tuple(new_args), kwargs, meta) @@ -797,7 +797,7 @@ def handle_squeeze(self, view_node: Node, visited_view_nodes: Set[Node]) -> None view_node.replace_all_uses_with(input_node) def call(self, graph_module: torch.fx.GraphModule) -> PassResult: - visited_view_nodes = set() + visited_view_nodes = set() # type: ignore[var-annotated] for view_node in graph_module.graph.find_nodes( op="call_function", target=exir_ops.edge.aten.view_copy.default, sort=True ): diff --git a/backends/cadence/aot/reorder_ops.py b/backends/cadence/aot/reorder_ops.py index 675c8e6cecd..4ecde6a4088 100644 --- a/backends/cadence/aot/reorder_ops.py +++ b/backends/cadence/aot/reorder_ops.py @@ -185,7 +185,7 @@ def advance_quantize_op(self, graph_module: torch.fx.GraphModule): if len(descendent_quant_ops) == 1: quant_node = descendent_quant_ops.pop() # Replace the uses of quant node with its predecessor - quant_node.replace_all_uses_with(quant_node.args[0]) # pyre-fixme[6] + quant_node.replace_all_uses_with(quant_node.args[0]) # type: ignore[arg-type] # Hoist the quant node after the current node. Make sure that # the insertion is after placeholders with graph.inserting_after(insertion_pt): @@ -271,7 +271,7 @@ def advancing_feasible(self, quant_node: torch.fx.Node): if isinstance(inp.target, EdgeOpOverload): inp_overloadpkt = get_edge_overload_packet(inp.target) else: - inp_overloadpkt = get_overload_packet(inp.target) + inp_overloadpkt = get_overload_packet(inp.target) # type: ignore[assignment] if ( inp_overloadpkt not in trivially_quantizable_ops_overloadpkt @@ -683,13 +683,13 @@ def insert_nodes( ): with graph.inserting_after(view_node): new_view_node = graph.call_function( - view_node.target, # pyre-fixme[6] + view_node.target, # type: ignore[arg-type] args=(pred, new_view_shape), ) with graph.inserting_after(new_view_node): new_permute_node = graph.call_function( - permute_node.target, # pyre-fixme[6] + permute_node.target, # type: ignore[arg-type] args=(new_view_node, new_permute_dims), ) new_permute_node.meta = view_node.meta diff --git a/backends/cadence/aot/replace_ops.py b/backends/cadence/aot/replace_ops.py index 7f493e1645d..02b156273da 100644 --- a/backends/cadence/aot/replace_ops.py +++ b/backends/cadence/aot/replace_ops.py @@ -97,7 +97,7 @@ def replace_logical_nop_where_with_where( ) # If the logical_not input is not a boolean tensor, bail. - if logical_not_input_tensor.meta["spec"].dtype != torch.bool: + if logical_not_input_tensor.meta["spec"].dtype != torch.bool: # type: ignore[union-attr] continue # Replace the where op with another one, flipping the inputs and using the boolean @@ -943,7 +943,7 @@ def transpose_dims( canonicalize_transposed_dim(dim1, shape), ) dim0, dim1 = min(dim0, dim1), max(dim0, dim1) - return super().call_operator( + return super().call_operator( # type: ignore[misc] exir_ops.edge.aten.transpose_copy.int, (proxy, dim0, dim1), {}, meta ) @@ -1864,22 +1864,22 @@ def call_operator( # If the args are not full ops, bail # pyre-ignore[16]: `ProxyValue` has no attribute `node`. - if (args[1].node.target != exir_ops.edge.aten.full.default) or ( - args[2].node.target != exir_ops.edge.aten.full.default + if (args[1].node.target != exir_ops.edge.aten.full.default) or ( # type: ignore[union-attr] + args[2].node.target != exir_ops.edge.aten.full.default # type: ignore[union-attr] ): return super().call_operator(op, args, kwargs, meta) # If one of the full ops is a different size than than the cond tensor, we need to broadcast. Bail. if ( # pyre-ignore[16]: `ProxyValue` has no attribute `node`. - list(args[0].to_tensor().shape) != args[1].node.args[0] - or list(args[0].to_tensor().shape) != args[2].node.args[0] + list(args[0].to_tensor().shape) != args[1].node.args[0] # type: ignore[union-attr] + or list(args[0].to_tensor().shape) != args[2].node.args[0] # type: ignore[union-attr] ): return super().call_operator(op, args, kwargs, meta) # Get the scalar values from the full ops - scalar_value_1 = args[1].node.args[1] - scalar_value_2 = args[2].node.args[1] + scalar_value_1 = args[1].node.args[1] # type: ignore[union-attr] + scalar_value_2 = args[2].node.args[1] # type: ignore[union-attr] # Replace the where op with a scalar where op return super().call_operator( @@ -1946,7 +1946,7 @@ def get_split_sizes( slice_ops.append(slice_args) split_start = split_end - return slice_ops + return slice_ops # type: ignore[return-value] def call(self, graph_module: torch.fx.GraphModule) -> PassResult: graph = graph_module.graph @@ -2004,8 +2004,8 @@ def call_operator( if not ( len(args) > 1 and isinstance(args[1], int) - and cast(int, args[1]) > 1 - and cast(int, args[1]) < 5 + and cast(int, args[1]) > 1 # type: ignore[redundant-cast] + and cast(int, args[1]) < 5 # type: ignore[redundant-cast] and op in { exir_ops.edge.aten.pow.Tensor_Scalar, @@ -2014,11 +2014,11 @@ def call_operator( return super().call_operator(op, args, kwargs, meta) x = args[0] - exponent = cast(int, args[1]) + exponent = cast(int, args[1]) # type: ignore[redundant-cast] if exponent > 2: for _ in range(exponent, 2, -1): - x = super().call_operator( + x = super().call_operator( # type: ignore[assignment] exir_ops.edge.aten.mul.Tensor, (x, args[0]), {}, diff --git a/backends/cadence/aot/tests/test_fusion_ops_passes.py b/backends/cadence/aot/tests/test_fusion_ops_passes.py index d160a02721a..b081f01b601 100644 --- a/backends/cadence/aot/tests/test_fusion_ops_passes.py +++ b/backends/cadence/aot/tests/test_fusion_ops_passes.py @@ -895,20 +895,20 @@ def test_fuse_transpose_permute_pairs( self.check_op_counts( gm, # pyre-fixme[6]: Incompatible parameter type - expected_op_counts=expected_op_counts, + expected_op_counts=expected_op_counts, # type: ignore[arg-type] ) # Check that the pass fuses the two transpose/permute ops. fusion_pass_result = FuseTransposeOrPermuteOpPairsPass()(gm) self.assertIsNotNone(fusion_pass_result) - gm_after_pass = fusion_pass_result.graph_module + gm_after_pass = fusion_pass_result.graph_module # type: ignore[union-attr] if expected_is_fused: expected_op_counts[op1] = 0 expected_op_counts[op2] = 0 self.check_op_counts( gm_after_pass, # pyre-fixme[6]: Incompatible parameter type - expected_op_counts=expected_op_counts, + expected_op_counts=expected_op_counts, # type: ignore[arg-type] ) def test_fusion_for_forked_transposes(self) -> None: diff --git a/backends/cadence/aot/tests/test_graph_builder.py b/backends/cadence/aot/tests/test_graph_builder.py index c3506dc4c07..06763c917d6 100644 --- a/backends/cadence/aot/tests/test_graph_builder.py +++ b/backends/cadence/aot/tests/test_graph_builder.py @@ -18,7 +18,7 @@ from executorch.backends.cadence.aot.pass_utils import count_node from executorch.exir.dialects._ops import ops as exir_ops from executorch.exir.pass_base import ExportPass, NodeMetadata -from later.unittest import TestCase +from later.unittest import TestCase # type: ignore[import-not-found] class TestGraphBuilder(TestCase): diff --git a/backends/cadence/aot/tests/test_idma_ops.py b/backends/cadence/aot/tests/test_idma_ops.py index 6320bfc482b..1339bd036a3 100644 --- a/backends/cadence/aot/tests/test_idma_ops.py +++ b/backends/cadence/aot/tests/test_idma_ops.py @@ -8,7 +8,7 @@ from executorch.backends.cadence.aot.graph_builder import GraphBuilder from executorch.exir.dialects._ops import ops as exir_ops -from later.unittest import TestCase +from later.unittest import TestCase # type: ignore[import-not-found] class TestIdmaOps(TestCase): diff --git a/backends/cadence/aot/tests/test_memory_passes.py b/backends/cadence/aot/tests/test_memory_passes.py index 41f903ccf06..f285d02ade1 100644 --- a/backends/cadence/aot/tests/test_memory_passes.py +++ b/backends/cadence/aot/tests/test_memory_passes.py @@ -48,7 +48,7 @@ from executorch.exir.pass_base import PassBase, PassResult from executorch.exir.passes.spec_prop_pass import SpecPropPass from executorch.exir.tests.models import MultiLayerPerceptron -from parameterized import parameterized +from parameterized import parameterized # type: ignore[import-untyped] from torch.fx import GraphModule @@ -161,38 +161,38 @@ def _verify_cat_nop_memory_alloc(self, node: torch.fx.Node) -> None: node_spec = node.meta.get("spec", None) self.assertIsNotNone(node_spec) dim: int = cast(int, node.kwargs["dim"]) if "dim" in node.kwargs else 0 - outer_size = math.prod(node_spec.shape[:dim]) + outer_size = math.prod(node_spec.shape[:dim]) # type: ignore[union-attr] self.assertEqual( outer_size, 1, f"{node=} has wrong outer size: {outer_size=}, expected 1.", ) inner_dim_elements = ( - math.prod(node_spec.shape[dim + 1 :]) * node_spec.dtype.itemsize + math.prod(node_spec.shape[dim + 1 :]) * node_spec.dtype.itemsize # type: ignore[union-attr] ) dim_offset = 0 for arg in cast(list[torch.fx.Node], node.args[0]): arg_spec = arg.meta.get("spec", None) - self.assertEqual(arg_spec.mem_id, node_spec.mem_id) - actual_offset = node_spec.mem_offset + dim_offset * inner_dim_elements + self.assertEqual(arg_spec.mem_id, node_spec.mem_id) # type: ignore[union-attr] + actual_offset = node_spec.mem_offset + dim_offset * inner_dim_elements # type: ignore[union-attr] self.assertEqual( - arg_spec.mem_offset, + arg_spec.mem_offset, # type: ignore[union-attr] actual_offset, - 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=}", + 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=}", # type: ignore[union-attr] ) - dim_offset += arg_spec.shape[dim] + dim_offset += arg_spec.shape[dim] # type: ignore[union-attr] def _verify_slice_nop_memory_alloc(self, node: torch.fx.Node) -> None: spec = node.meta.get("spec", None) self.assertIsNotNone(spec) dim: int = cast(int, node.args[1]) if len(node.args) > 1 else 0 - outer_size = math.prod(spec.shape[:dim]) + outer_size = math.prod(spec.shape[:dim]) # type: ignore[union-attr] self.assertEqual( outer_size, 1, f"{node=} has wrong outer size: {outer_size=}, expected 1.", ) - inner_dim_elements = math.prod(spec.shape[dim + 1 :]) * spec.dtype.itemsize + inner_dim_elements = math.prod(spec.shape[dim + 1 :]) * spec.dtype.itemsize # type: ignore[union-attr] start: int = ( cast(int, node.args[2]) if (len(node.args) > 2 and node.args[2] is not None) @@ -200,24 +200,24 @@ def _verify_slice_nop_memory_alloc(self, node: torch.fx.Node) -> None: ) arg = cast(torch.fx.Node, node.args[0]) arg_spec = arg.meta.get("spec", None) - self.assertEqual(arg_spec.mem_id, spec.mem_id) + self.assertEqual(arg_spec.mem_id, spec.mem_id) # type: ignore[union-attr] self.assertEqual( - spec.mem_offset, - arg_spec.mem_offset + start * inner_dim_elements, - f"{arg=} for node {node=} has wrong memory offset: {arg_spec.mem_offset=} {start=} for slice on {dim=}, but output has {spec.mem_offset=}", + spec.mem_offset, # type: ignore[union-attr] + arg_spec.mem_offset + start * inner_dim_elements, # type: ignore[union-attr] + f"{arg=} for node {node=} has wrong memory offset: {arg_spec.mem_offset=} {start=} for slice on {dim=}, but output has {spec.mem_offset=}", # type: ignore[union-attr] ) def _verify_select_nop_memory_alloc(self, node: torch.fx.Node) -> None: spec = node.meta.get("spec", None) self.assertIsNotNone(spec) dim: int = cast(int, node.args[1]) if len(node.args) > 1 else 0 - outer_size = math.prod(spec.shape[:dim]) + outer_size = math.prod(spec.shape[:dim]) # type: ignore[union-attr] self.assertEqual( outer_size, 1, f"{node=} has wrong outer size: {outer_size=}, expected 1.", ) - inner_dim_elements = math.prod(spec.shape[dim:]) * spec.dtype.itemsize + inner_dim_elements = math.prod(spec.shape[dim:]) * spec.dtype.itemsize # type: ignore[union-attr] index: int = ( cast(int, node.args[2]) if (len(node.args) > 2 and node.args[2] is not None) @@ -225,11 +225,11 @@ def _verify_select_nop_memory_alloc(self, node: torch.fx.Node) -> None: ) arg = cast(torch.fx.Node, node.args[0]) arg_spec = arg.meta.get("spec", None) - self.assertEqual(arg_spec.mem_id, spec.mem_id) + self.assertEqual(arg_spec.mem_id, spec.mem_id) # type: ignore[union-attr] self.assertEqual( - spec.mem_offset, - arg_spec.mem_offset + index * inner_dim_elements, - f"{arg=} for node {node=} has wrong memory offset: {arg_spec.mem_offset=} for select on {dim=} {index=}, " + spec.mem_offset, # type: ignore[union-attr] + arg_spec.mem_offset + index * inner_dim_elements, # type: ignore[union-attr] + f"{arg=} for node {node=} has wrong memory offset: {arg_spec.mem_offset=} for select on {dim=} {index=}, " # type: ignore[union-attr] f"but output has {spec.mem_offset=}" f"{spec=} {arg_spec=}", ) @@ -1017,7 +1017,7 @@ def forward(self, x: torch.Tensor, y: torch.Tensor): if spec and spec.mem_offset: self.assertEqual(spec.mem_offset % 37, 0) - @parameterized.expand([0, 1]) + @parameterized.expand([0, 1]) # type: ignore[misc] def test_block_mem_id(self, mem_algo: int) -> None: builder = GraphBuilder() x = builder.placeholder("x", torch.randn(16)) @@ -1047,7 +1047,7 @@ class DummyMemIdBlockConstraintGen(PassBase): def __init__(self, memory_constraints: MemConstraints): self.memory_constraints = memory_constraints - def call(self, graph_module: torch.fx.GraphModule) -> PassResult: + def call(self, graph_module: torch.fx.GraphModule) -> PassResult: # type: ignore[return] for node in graph_module.graph.find_nodes( op="call_function", target=torch.ops.aten.add.Scalar ): @@ -1133,7 +1133,7 @@ def _run_mem_planning( specs, gm, # pyre-ignore[6] - None, + None, # type: ignore[arg-type] state, placement_constraints, ) diff --git a/backends/cadence/aot/tests/test_program_builder.py b/backends/cadence/aot/tests/test_program_builder.py index a16d42e2378..4396ac77fd4 100644 --- a/backends/cadence/aot/tests/test_program_builder.py +++ b/backends/cadence/aot/tests/test_program_builder.py @@ -4,7 +4,7 @@ import torch from executorch.backends.cadence.aot.program_builder import IrMode, ProgramBuilder from executorch.exir.dialects._ops import ops as exir_ops -from later.unittest import TestCase +from later.unittest import TestCase # type: ignore[import-not-found] from torch._export.verifier import SpecViolationError from torch.export.graph_signature import InputKind, OutputKind @@ -127,7 +127,7 @@ def test_get_verifier_exir_mode(self) -> None: builder = ProgramBuilder(mode=IrMode.EXIR) verifiers = builder.get_verifiers() self.assertIsNotNone(verifiers) - self.assertEqual(len(verifiers), 1) + self.assertEqual(len(verifiers), 1) # type: ignore[arg-type] def test_get_verifier_aten_mode(self) -> None: """Test that get_verifier returns None for ATEN mode.""" @@ -141,7 +141,7 @@ def test_get_verifier_default_mode(self) -> None: self.assertEqual(builder.mode, IrMode.EXIR) verifiers = builder.get_verifiers() self.assertIsNotNone(verifiers) - self.assertEqual(len(verifiers), 1) + self.assertEqual(len(verifiers), 1) # type: ignore[arg-type] def test_aten_add_tensor_exir_mode(self) -> None: """Test using torch.ops.aten.add.Tensor with EXIR mode.""" diff --git a/backends/cadence/aot/tests/test_remove_ops_passes.py b/backends/cadence/aot/tests/test_remove_ops_passes.py index a38416c0ff1..d45e3b8ee97 100644 --- a/backends/cadence/aot/tests/test_remove_ops_passes.py +++ b/backends/cadence/aot/tests/test_remove_ops_passes.py @@ -38,7 +38,7 @@ ) from executorch.backends.cadence.aot.typing_stubs import expand from executorch.exir.dialects._ops import ops as exir_ops -from pyre_extensions import none_throws +from pyre_extensions import none_throws # type: ignore[import-not-found] from torch.fx.passes.infra.pass_base import PassResult diff --git a/backends/cadence/aot/tests/test_replace_ops_passes.py b/backends/cadence/aot/tests/test_replace_ops_passes.py index bd02cb0ae11..a44e559922b 100644 --- a/backends/cadence/aot/tests/test_replace_ops_passes.py +++ b/backends/cadence/aot/tests/test_replace_ops_passes.py @@ -1473,7 +1473,7 @@ def create_conv1d_graphmodule( b = torch.randn(16) args = (x, w, b, (2, 2), (1, 1), (0, 0), 1) if channels_last is not None: - args = args + (channels_last,) + args = args + (channels_last,) # type: ignore[assignment] return single_op_builder( placeholders=(x, w, b), op=exir_ops.edge.cadence.convolution.default, @@ -1550,7 +1550,7 @@ def create_convolution_graph_module( b = torch.randn(16) args = (x, w, b, (2, 2), (1, 1), (0, 0), 1) if channels_last is not None: - args = args + (channels_last,) + args = args + (channels_last,) # type: ignore[assignment] return single_op_builder( placeholders=(x, w, b), op=exir_ops.edge.cadence.convolution.default, @@ -1941,8 +1941,8 @@ def test_extract_mul_argument_to_full( op_counts_match( graph_after_passes, expected_op_counts={ - torch.ops.aten.mul.Tensor: 1, - torch.ops.aten.full.default: 1, + torch.ops.aten.mul.Tensor: 1, # type: ignore[dict-item] + torch.ops.aten.full.default: 1, # type: ignore[dict-item] }, ) ) diff --git a/backends/cadence/aot/type_dispatch.py b/backends/cadence/aot/type_dispatch.py index ec9cecb03ed..2dca8965191 100644 --- a/backends/cadence/aot/type_dispatch.py +++ b/backends/cadence/aot/type_dispatch.py @@ -108,13 +108,13 @@ def call_operator( config = self._SUPPORTED_OPS[op] # pyre-ignore[16]: None has no attribute `to_tensor`. - input_dtype = args[0].to_tensor().dtype + input_dtype = args[0].to_tensor().dtype # type: ignore[union-attr] if config.weight_arg_idx is not None: - weight_dtype = args[config.weight_arg_idx].to_tensor().dtype + weight_dtype = args[config.weight_arg_idx].to_tensor().dtype # type: ignore[union-attr] dtype_key = (input_dtype, weight_dtype) else: - dtype_key = (input_dtype,) + dtype_key = (input_dtype,) # type: ignore[assignment] if dtype_key not in config.type_dispatch_suffixes: raise RuntimeError(f"Unsupported input types for {op}: {dtype_key}") @@ -128,15 +128,15 @@ def call_operator( ]: groups = args[6] input_channels = ( - args[0].to_tensor().shape[1] + args[0].to_tensor().shape[1] # type: ignore[union-attr] if op == exir_ops.edge.cadence.quantized_conv_nchw.per_tensor - else args[0].to_tensor().shape[-1] + else args[0].to_tensor().shape[-1] # type: ignore[union-attr] ) is_depthwise = groups == input_channels dilation = args[5] # pyre-ignore[16]: None has no attribute '__iter__'. - is_dilated = any(d > 1 for d in dilation) + is_dilated = any(d > 1 for d in dilation) # type: ignore[operator,union-attr] if is_dilated: type_suffix = f"dilated_{type_suffix}" diff --git a/backends/cadence/aot/utils.py b/backends/cadence/aot/utils.py index b711d45994b..31cac657757 100644 --- a/backends/cadence/aot/utils.py +++ b/backends/cadence/aot/utils.py @@ -19,7 +19,7 @@ from executorch.exir.dialects._ops import ops as exir_ops from executorch.exir.dialects.edge._ops import EdgeOpOverload, EdgeOpOverloadPacket from executorch.exir.pass_base import Argument -from tabulate import tabulate +from tabulate import tabulate # type: ignore[import-untyped] from torch.fx.operator_schemas import get_signature_for_torch_op from torch.utils._pytree import tree_flatten @@ -93,7 +93,7 @@ def get_conv2d_output_size( hout = (H + 2 * padding[0] - dilation[0] * (kernel_size[0] - 1) - 1) // stride[ 0 ] + 1 - wout = (W + 2 * padding[1] - dilation[1] * (kernel_size[1] - 1) - 1) // stride[ + wout = (W + 2 * padding[1] - dilation[1] * (kernel_size[1] - 1) - 1) // stride[ # type: ignore[misc] 1 ] + 1 if channel_last: @@ -121,9 +121,11 @@ def get_im2row_output_size( input_height + 2 * padding[0] - (dilation[0] * (kernel_size[0] - 1) + 1) ) // stride[0] + 1 output_width = ( - input_width + 2 * padding[1] - (dilation[1] * (kernel_size[1] - 1) + 1) - ) // stride[1] + 1 - n_output_plane = n_input_plane * kernel_size[0] * kernel_size[1] + input_width + 2 * padding[1] - (dilation[1] * (kernel_size[1] - 1) + 1) # type: ignore[misc] + ) // stride[ + 1 + ] + 1 # type: ignore[misc] + n_output_plane = n_input_plane * kernel_size[0] * kernel_size[1] # type: ignore[misc] output_size = torch.Size((batch_size, output_height * output_width, n_output_plane)) return torch.Size(output_size) @@ -142,7 +144,7 @@ def get_edge_overload_packet(edge_op: EdgeOpOverload) -> EdgeOpOverloadPacket: # Get the frequency list of ops in a graph module def get_ops_count(graph_module: torch.fx.GraphModule) -> Dict[str, int]: - freq = {} + freq = {} # type: ignore[var-annotated] # Loop over nodes to count the number of times each op occurs for node in graph_module.graph.nodes: if node.op == "call_function": @@ -197,7 +199,7 @@ def get_shape( return fake_tensor.shape # Case 3. node holds a param if node.op == "get_attr": - attr_node = getattr(graph_module, node.target) + attr_node = getattr(graph_module, node.target) # type: ignore[arg-type] return attr_node.shape # Default: return None return None @@ -230,7 +232,7 @@ def print_ops_info( ] for op in final_ops_count ] - sorted_ops_count = sorted(ops_count, key=lambda x: x[1], reverse=True) + sorted_ops_count = sorted(ops_count, key=lambda x: x[1], reverse=True) # type: ignore[arg-type,return-value] # Create a dict of deleted ops and their counts to pass to tabulate removed_ops_count = [ diff --git a/backends/cadence/runtime/executor.py b/backends/cadence/runtime/executor.py index 7aea3fde0dc..34e7e63cd12 100644 --- a/backends/cadence/runtime/executor.py +++ b/backends/cadence/runtime/executor.py @@ -45,17 +45,17 @@ def _execute_subprocess(cmd: List[str], cwd: Optional[str] = None) -> Tuple[str, sel = selectors.DefaultSelector() # pyre-fixme[6]: For 1st argument expected `Union[HasFileno, int]` but got # `Optional[IO[bytes]]`. - sel.register(p.stdout, selectors.EVENT_READ) + sel.register(p.stdout, selectors.EVENT_READ) # type: ignore[arg-type] # pyre-fixme[6]: For 1st argument expected `Union[HasFileno, int]` but got # `Optional[IO[bytes]]`. - sel.register(p.stderr, selectors.EVENT_READ) + sel.register(p.stderr, selectors.EVENT_READ) # type: ignore[arg-type] done = False while not done: for key, _ in sel.select(): # pyre-fixme[16]: Item `HasFileno` of `Union[HasFileno, int]` has no # attribute `read1`. - data = key.fileobj.read1().decode() + data = key.fileobj.read1().decode() # type: ignore[union-attr] if not data: done = True break diff --git a/backends/cadence/runtime/runtime.py b/backends/cadence/runtime/runtime.py index 4d1c876bcdb..87cd3ecf4fe 100644 --- a/backends/cadence/runtime/runtime.py +++ b/backends/cadence/runtime/runtime.py @@ -67,7 +67,7 @@ def get_outputs(self, log_to_stdout: bool = False) -> Tuple[torch.Tensor]: if event_block.name == "Execute" ] logging.debug(f"[ETdump] output: {output}") - return output[0] + return output[0] # type: ignore[return-value] def print_event_block(self) -> None: logging.debug("[ETdump] data tabular:") diff --git a/docs/source/tutorials_source/devtools-integration-tutorial.py b/docs/source/tutorials_source/devtools-integration-tutorial.py index d5212bc3f32..5087554d604 100644 --- a/docs/source/tutorials_source/devtools-integration-tutorial.py +++ b/docs/source/tutorials_source/devtools-integration-tutorial.py @@ -250,7 +250,7 @@ def forward(self, x): slowest = None for event in event_block.events: if event.name == "native_call_convolution.out": - if slowest is None or event.perf_data.p50 > slowest.perf_data.p50: + if slowest is None or event.perf_data.p50 > slowest.perf_data.p50: # type: ignore[union-attr] slowest = event if slowest is not None: print(slowest.name) diff --git a/requirements-lintrunner.txt b/requirements-lintrunner.txt index d659185f893..a2949b25096 100644 --- a/requirements-lintrunner.txt +++ b/requirements-lintrunner.txt @@ -19,4 +19,4 @@ cmakelang==0.6.13 cmakelint==1.4.1 # MyPy -mypy==1.14.1 +mypy==1.17.1