Skip to content

Commit 23f4fb4

Browse files
authored
Add memory planning to oss tests (pytorch#17596)
### Summary add to pytest.ini, and add cmake path-finding import for OSS ### Test plan python -m unittest exir.tests.test_memory_planning
1 parent 298311e commit 23f4fb4

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

exir/tests/test_memory_planning.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from typing import Any, Callable, List, Optional, Tuple, Type
1212

1313
import executorch.exir as exir
14-
1514
import torch
1615
from executorch.exir import ExecutorchBackendConfig, to_edge
1716
from executorch.exir.capture._capture import patch_forward
@@ -37,7 +36,6 @@
3736
from executorch.exir.tensor import TensorSpec
3837
from functorch.experimental.control_flow import map as torch_map
3938
from parameterized import parameterized
40-
4139
from torch import nn
4240
from torch.ao.quantization import ( # @manual=//caffe2:torch
4341
float_qparams_weight_only_qconfig,
@@ -61,7 +59,21 @@
6159
from torch.nn import functional as F
6260
from torch.utils import _pytree as pytree
6361

64-
torch.ops.load_library("//executorch/kernels/portable:custom_ops_generated_lib")
62+
try:
63+
torch.ops.load_library("//executorch/kernels/portable:custom_ops_generated_lib")
64+
except (OSError, RuntimeError):
65+
# When running outside of Buck (e.g., CMake/pip), find the shared library
66+
# by globbing relative to the kernels/portable directory.
67+
from pathlib import Path
68+
69+
_libs = list(
70+
Path(__file__)
71+
.parent.parent.parent.resolve()
72+
.glob("**/kernels/portable/**/*custom_ops_generated_lib.*")
73+
)
74+
if _libs:
75+
torch.ops.load_library(str(_libs[0]))
76+
del Path
6577

6678

6779
def swap_modules(

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ addopts =
3434
--ignore=exir/backend/test/demos/test_delegate_aten_mode.py
3535
--ignore=exir/backend/test/demos/test_xnnpack_qnnpack.py
3636
--ignore=exir/tests/test_memory_format_ops_pass_aten.py
37-
--ignore=exir/tests/test_memory_planning.py
37+
3838
--ignore=exir/tests/test_passes.py
3939
--ignore=exir/tests/test_quantization.py
4040
--ignore=exir/tests/test_verification.py

0 commit comments

Comments
 (0)