Skip to content

Commit 2abf9a6

Browse files
authored
Fix nondeterministic mypy CI dependencies and lint error exposed (pytorch#22482)
Pin the mypy job to the repository's Torch 2.13 stack before installing timm, and include the Torch pin in its pip cache key. This makes it deterministic instead of depending on order of resolution. Adapt Arm shape and dtype checks to the SymInt and SymBool annotations exposed by newer Torch releases. cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani
1 parent e39bda8 commit 2abf9a6

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

‎.github/workflows/lint.yml‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,22 @@ jobs:
4141
with:
4242
python-version: '3.11'
4343
cache: 'pip'
44-
cache-dependency-path: requirements-lintrunner.txt
44+
cache-dependency-path: |
45+
requirements-lintrunner.txt
46+
torch_pin.py
4547
4648
- name: Install dependencies
4749
run: |
48-
pip install torch --index-url https://download.pytorch.org/whl/cpu
50+
TORCH_VERSION=$(python -c "from torch_pin import TORCH_VERSION; print(TORCH_VERSION)")
51+
pip install \
52+
"torch==${TORCH_VERSION}" \
53+
torchvision \
54+
torchaudio \
55+
--index-url https://download.pytorch.org/whl/cpu
4956
pip install lintrunner==0.12.7 lintrunner-adapters==0.14.1
5057
pip install -r requirements-lintrunner.txt
5158
USE_CPP=0 pip install --no-build-isolation third-party/ao
5259
pip install pytest numpy parameterized huggingface_hub transformers timm expecttest types-requests
53-
pip install torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
5460
5561
- name: Generate mypy stubs for C++ bindings
5662
run: |

‎backends/arm/_passes/rewrite_conv_pass.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def _is_direct_int32_rescale(node: torch.fx.Node) -> bool:
528528
node.op == "call_function"
529529
and node.target == exir_ops.backend.tosa.RESCALE.default
530530
and len(node.args) > 1
531-
and node.args[1] == torch.int32
531+
and node.args[1] is torch.int32
532532
)
533533

534534
def _get_direct_int32_rescale_users(

‎backends/arm/tosa/dialect/ops/resize.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def RESIZE(
9696
validation_error = get_tosa_resize_output_hw_validation_error(output_hw)
9797
if validation_error is not None:
9898
raise TosaValueError(validation_error, op="RESIZE")
99+
OH: int | torch.SymInt
100+
OW: int | torch.SymInt
99101
if output_hw is None:
100102
scale_y_n, scale_y_d, scale_x_n, scale_x_d = scale
101103
offset_y, offset_x = offset

‎backends/arm/tosa/partitioner.py‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from executorch.exir.graph_module import get_cond_while_submodules
5151
from torch.export.exported_program import ExportedProgram
5252
from torch.fx import GraphModule
53+
from torch.fx.experimental.symbolic_shapes import statically_known_true
5354
from torch.fx.passes.infra.partitioner import CapabilityBasedPartitioner, Partition
5455
from torch.fx.passes.operator_support import any_chain, OperatorSupportBase
5556

@@ -152,9 +153,22 @@ def _is_noop_as_strided_copy(node: torch.fx.Node) -> bool:
152153
input_tensor = get_first_fake_tensor(ensure_type(torch.fx.Node, node.args[0]))
153154
output_tensor = get_first_fake_tensor(node)
154155
return (
155-
input_tensor.shape == output_tensor.shape
156-
and input_tensor.stride() == output_tensor.stride()
157-
and input_tensor.storage_offset() == output_tensor.storage_offset()
156+
len(input_tensor.shape) == len(output_tensor.shape)
157+
and all(
158+
statically_known_true(input_dim == output_dim)
159+
for input_dim, output_dim in zip(
160+
input_tensor.shape, output_tensor.shape
161+
)
162+
)
163+
and all(
164+
statically_known_true(input_stride == output_stride)
165+
for input_stride, output_stride in zip(
166+
input_tensor.stride(), output_tensor.stride()
167+
)
168+
)
169+
and statically_known_true(
170+
input_tensor.storage_offset() == output_tensor.storage_offset()
171+
)
158172
)
159173

160174

0 commit comments

Comments
 (0)