Skip to content

Commit 2d1f181

Browse files
authored
Fix OSS import for ref_implementations
Differential Revision: D88303133 Pull Request resolved: #16066
1 parent a09a4b7 commit 2d1f181

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

backends/cadence/aot/ref_implementations.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,25 @@
1111
import torch
1212
import torch.nn as nn
1313
import torch.nn.functional as F
14-
1514
from executorch.exir.scalar_type import ScalarType
1615
from torch.library import impl, Library
1716

1817
m = Library("cadence", "IMPL", "CompositeExplicitAutograd")
19-
torch.ops.load_library("//executorch/kernels/quantized:custom_ops_generated_lib")
18+
19+
try:
20+
torch.ops.load_library("//executorch/kernels/quantized:custom_ops_generated_lib")
21+
except (OSError, RuntimeError):
22+
# Fall back to path-based loading for CMake/OSS builds
23+
from pathlib import Path
24+
25+
custom_libs: list[Path] = list(
26+
Path(__file__)
27+
.parent.parent.parent.resolve()
28+
.glob("**/kernels/quantized/**/*custom_ops_generated_lib.*")
29+
)
30+
if custom_libs:
31+
torch.ops.load_library(str(custom_libs[0]))
32+
del Path
2033

2134
# Registry to track all ops with reference implementations
2235
_REGISTERED_REF_IMPLEMENTATIONS: set[str] = set()

0 commit comments

Comments
 (0)