forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace_sym_size_op_pass.py
More file actions
35 lines (28 loc) · 1.21 KB
/
replace_sym_size_op_pass.py
File metadata and controls
35 lines (28 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
# pyre-strict
from typing import Dict
import torch
from executorch.exir.pass_base import PassBase, PassResult
replacements: Dict[torch._ops.OpOverloadPacket, torch._ops.OpOverload] = {
torch.ops.aten.sym_size: torch.ops.aten.sym_size.int,
torch.ops.aten.sym_stride: torch.ops.aten.sym_stride.int,
torch.ops.aten.sym_numel: torch.ops.aten.sym_numel.default,
}
class ReplaceSymSizeOpPass(PassBase):
"""
Replace torch.ops.aten.sym_size with torch.ops.aten.sym_size.int
and torch.ops.aten.sym_stride with torch.ops.aten.sym_stride.int
TODO: this can be refactors into a general OpReplacementPass
"""
def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
for module in graph_module.modules():
if not isinstance(module, torch.fx.GraphModule):
continue
for node in module.graph.nodes:
if node.target in replacements:
node.target = replacements[node.target]
return PassResult(graph_module, True)