Skip to content

Commit 0acefb4

Browse files
Andrew Grebenisanfacebook-github-bot
authored andcommitted
Fix OSS import for ref_implementations (pytorch#16066)
Summary: Was using buck-based loading of quantized decomposed in ref_implementations which isn't CMake-compatible. This fixes that approach. Reviewed By: zonglinpeng Differential Revision: D88303133
1 parent ac4b939 commit 0acefb4

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(
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)