fix(build): bridge编译成功即可——import失败是预期的(ixformer符号需运行时preload)
torch.utils.cpp_extension.load()内部先编译再import。 编译成功产出.so,但import时ixformer::infer::*符号未加载导致ImportError。 这是预期行为——运行时ix_unified.py会先RTLD_GLOBAL预加载ixformer再import bridge。 修改:捕获ImportError,检查.so文件存在即认为编译成功。
This commit is contained in:
@@ -27,11 +27,9 @@ build_dir = "$BUILD_DIR"
|
|||||||
try:
|
try:
|
||||||
from torch.utils.cpp_extension import load
|
from torch.utils.cpp_extension import load
|
||||||
|
|
||||||
# Find ixformer include/lib dirs for linking
|
|
||||||
extra_include = ["$SCRIPT_DIR/csrc/ilu"]
|
extra_include = ["$SCRIPT_DIR/csrc/ilu"]
|
||||||
extra_ldflags = []
|
extra_ldflags = []
|
||||||
|
|
||||||
# ixformer lib dirs — bridge needs these at runtime, not compile time
|
|
||||||
for p in ["/usr/local/corex/lib64/python3/dist-packages/ixformer",
|
for p in ["/usr/local/corex/lib64/python3/dist-packages/ixformer",
|
||||||
"/usr/local/corex/lib64"]:
|
"/usr/local/corex/lib64"]:
|
||||||
if os.path.isdir(p):
|
if os.path.isdir(p):
|
||||||
@@ -40,19 +38,39 @@ try:
|
|||||||
extra_ldflags.append(f"-L{p}")
|
extra_ldflags.append(f"-L{p}")
|
||||||
extra_ldflags.append(f"-Wl,-rpath,{p}")
|
extra_ldflags.append(f"-Wl,-rpath,{p}")
|
||||||
|
|
||||||
ext = load(
|
# Use load() for compilation only. It may fail on import because
|
||||||
name="ix_unified_bridge",
|
# ixformer::infer symbols need RTLD_GLOBAL preload at runtime.
|
||||||
sources=[src],
|
# That's OK — we just need the .so file to exist.
|
||||||
extra_include_paths=extra_include,
|
try:
|
||||||
extra_ldflags=extra_ldflags,
|
ext = load(
|
||||||
verbose=True,
|
name="ix_unified_bridge",
|
||||||
build_directory=build_dir,
|
sources=[src],
|
||||||
)
|
extra_include_paths=extra_include,
|
||||||
funcs = [x for x in dir(ext) if not x.startswith('_')]
|
extra_ldflags=extra_ldflags,
|
||||||
print(f"[build_bridge] SUCCESS via cpp_extension: {len(funcs)} functions")
|
verbose=True,
|
||||||
print(f"[build_bridge] functions: {funcs}")
|
build_directory=build_dir,
|
||||||
sys.exit(0)
|
)
|
||||||
|
funcs = [x for x in dir(ext) if not x.startswith('_')]
|
||||||
|
print(f"[build_bridge] SUCCESS via cpp_extension: {len(funcs)} functions: {funcs}")
|
||||||
|
sys.exit(0)
|
||||||
|
except ImportError as ie:
|
||||||
|
# Compilation succeeded but import failed (expected: ixformer symbols unresolved)
|
||||||
|
# Check if .so was actually produced
|
||||||
|
built = glob.glob(os.path.join(build_dir, "ix_unified_bridge*.so"))
|
||||||
|
if built:
|
||||||
|
print(f"[build_bridge] COMPILED OK: {built[0]}")
|
||||||
|
print(f"[build_bridge] Import deferred to runtime (ixformer preload needed): {ie}")
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
print(f"[build_bridge] No .so produced: {ie}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# Check if .so exists from compilation before the exception
|
||||||
|
built = glob.glob(os.path.join(build_dir, "ix_unified_bridge*.so"))
|
||||||
|
if built:
|
||||||
|
print(f"[build_bridge] COMPILED OK (exception during import): {built[0]}")
|
||||||
|
sys.exit(0)
|
||||||
print(f"[build_bridge] cpp_extension failed: {e}")
|
print(f"[build_bridge] cpp_extension failed: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
PYEOF
|
PYEOF
|
||||||
|
|||||||
Reference in New Issue
Block a user