Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions exir/tests/test_memory_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import Any, Callable, List, Optional, Tuple, Type

import executorch.exir as exir

import torch
from executorch.exir import ExecutorchBackendConfig, to_edge
from executorch.exir.capture._capture import patch_forward
Expand All @@ -37,7 +36,6 @@
from executorch.exir.tensor import TensorSpec
from functorch.experimental.control_flow import map as torch_map
from parameterized import parameterized

from torch import nn
from torch.ao.quantization import ( # @manual=//caffe2:torch
float_qparams_weight_only_qconfig,
Expand All @@ -61,7 +59,21 @@
from torch.nn import functional as F
from torch.utils import _pytree as pytree

torch.ops.load_library("//executorch/kernels/portable:custom_ops_generated_lib")
try:
torch.ops.load_library("//executorch/kernels/portable:custom_ops_generated_lib")
except (OSError, RuntimeError):
# When running outside of Buck (e.g., CMake/pip), find the shared library
# by globbing relative to the kernels/portable directory.
from pathlib import Path

_libs = list(
Path(__file__)
.parent.parent.parent.resolve()
.glob("**/kernels/portable/**/*custom_ops_generated_lib.*")
)
if _libs:
torch.ops.load_library(str(_libs[0]))
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Buck target load fails and the glob finds no matches, the module import continues without loading custom_ops_generated_lib, which will likely cause later failures in ToOutVarPass (missing out variants) with a less-direct error. Consider failing fast with a clearer error or skipping these tests when the library cannot be located/loaded.

Suggested change
torch.ops.load_library(str(_libs[0]))
torch.ops.load_library(str(_libs[0]))
else:
# Fail fast or explicitly skip if the custom ops library cannot be found.
# This avoids obscure downstream errors (e.g., in ToOutVarPass).
raise unittest.SkipTest(
"Skipping memory planning tests: could not locate "
"custom_ops_generated_lib shared library."
)

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +75
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recursive glob (**/kernels/portable/**/*custom_ops_generated_lib.*) can be expensive and is also imprecise (it may match non-shared-library artifacts and, when multiple matches exist, _libs[0] is not deterministic). Consider filtering to platform shared-library extensions, sorting the matches, and/or searching only known build/install locations to keep imports fast and deterministic.

Copilot uses AI. Check for mistakes.
del Path


def swap_modules(
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ addopts =
--ignore=exir/backend/test/demos/test_delegate_aten_mode.py
--ignore=exir/backend/test/demos/test_xnnpack_qnnpack.py
--ignore=exir/tests/test_memory_format_ops_pass_aten.py
--ignore=exir/tests/test_memory_planning.py

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol. Didnt realize we had so much stuff disabled

--ignore=exir/tests/test_passes.py
--ignore=exir/tests/test_quantization.py
--ignore=exir/tests/test_verification.py
Expand Down
Loading