【WSL】Conda 安装 PyTorch 后 import torch 报错:undefined symbol: iJIT_NotifyEvent / iJIT_IsProfilingActive

Qwen3-32B-Chat 私有部署镜像 | RTX4090D 24G 显存 CUDA12.4 优化版

Qwen3-32B-Chat 私有部署镜像 | RTX4090D 24G 显存 CUDA12.4 优化版

Qwen
文本生成
Qwen3

本镜像基于 RTX 4090D 24GB 显存 + CUDA 12.4 + 驱动 550.90.07 深度优化,内置完整运行环境与 Qwen3-32B 模型依赖,开箱即用。

1. 问题现象

在 WSL2 Ubuntu 的 conda 环境里安装 PyTorch(GPU/CPU 都可能遇到),执行:

python -c "import torch; print(torch.__version__)"

报错类似:

ImportError: .../torch/lib/libtorch_cpu.so: undefined symbol: iJIT_NotifyEvent

或者修复后继续报:

ImportError: .../libtorch_cpu.so: undefined symbol: iJIT_IsProfilingActive

导致 PyTorch 无法导入,后续编译自定义算子/训练全部卡死。


2. 原因分析(为什么会这样)

libtorch_cpu.so 在加载时依赖 Intel ITT/JIT profiling 相关符号(例如 iJIT_NotifyEventiJIT_IsProfilingActive)。

正常情况下,这些符号由 libittnotify.so(Intel ITT/VTune 相关运行库)提供。

但在某些 WSL2 + conda + PyTorch 组合下:

  • conda 环境内缺少 libittnotify.so

  • 或者依赖链冲突导致该库未被安装/未被正确加载

于是动态链接器找不到符号,import torch 直接失败。

说明:这些符号主要用于 VTune/性能分析。日常训练推理并不需要它“真的工作”,只要符号存在即可。


3. 尝试过但容易踩坑的方案(可选阅读)

很多人会尝试降级 MKL(如 mkl=2024.0.0),但在 pytorch/nvidia/defaults 与 conda-forge 混用时,可能触发 llvm-openmp 版本冲突,解不出来:

  • conda-forge 的 mkl 可能要求更高版本 llvm-openmp

  • 但 pytorch 2.4.0/torchaudio 2.4.0 可能要求 llvm-openmp <16

最终 conda 直接报 UnsatisfiableError

因此本文给出一个不依赖 solver、命中率极高的方案:自建 stub 的 libittnotify.so + LD_PRELOAD


4. 最终解决方案(已验证可用):自建 libittnotify.so + LD_PRELOAD

4.1 安装编译工具 gcc

sudo apt update sudo apt install -y gcc

4.2 激活 conda 环境

conda activate MOTIP2

环境名按你自己的修改(例如 MOTIP / MOTIP2)。

4.3 在环境里写一个 ITT stub(空实现,提供缺失符号)

cat > "$CONDA_PREFIX/lib/itt_stub.c" <<'EOF' #include <stdint.h> #ifdef __cplusplus extern "C" { #endif // No-op stubs for Intel ITT / JIT profiling symbols. // They satisfy the dynamic linker so PyTorch can load. // Profiling functionality is NOT provided (fine for normal training/inference). void iJIT_NotifyEvent(void) {} void iJIT_NotifyEventW(void) {} void iJIT_NotifyEventStr(void) {} void iJIT_NotifyEventEx(void) {} int iJIT_IsProfilingActive(void) { return 0; } uint32_t iJIT_GetNewMethodID(void) { return 1; } uint32_t iJIT_GetNewMethodIDEx(void) { return 1; } #ifdef __cplusplus } #endif EOF

4.4 编译生成 libittnotify.so

gcc -shared -fPIC -O2 \ -o "$CONDA_PREFIX/lib/libittnotify.so" \ "$CONDA_PREFIX/lib/itt_stub.c"

检查文件是否生成:

ls -l "$CONDA_PREFIX/lib/libittnotify.so"

4.5 临时验证(只对当前命令生效)

LD_PRELOAD="$CONDA_PREFIX/lib/libittnotify.so" \ python -c "import torch; print(torch.__version__, torch.cuda.is_available())"

如果能输出版本号且不再报错,说明修复成功。


5. 永久生效:每次 conda activate 自动 preload(推荐)

不想每次都手打 LD_PRELOAD=... 的话,可以添加 conda 的 activate/deactivate 脚本。

5.1 创建脚本目录

mkdir -p "$CONDA_PREFIX/etc/conda/activate.d" "$CONDA_PREFIX/etc/conda/deactivate.d"

5.2 激活时自动设置 LD_PRELOAD

cat > "$CONDA_PREFIX/etc/conda/activate.d/itt_preload.sh" <<'EOF' export _OLD_LD_PRELOAD="${LD_PRELOAD:-}" export LD_PRELOAD="$CONDA_PREFIX/lib/libittnotify.so${LD_PRELOAD:+:$LD_PRELOAD}" EOF

5.3 退出环境时恢复 LD_PRELOAD

cat > "$CONDA_PREFIX/etc/conda/deactivate.d/itt_preload.sh" <<'EOF' export LD_PRELOAD="$_OLD_LD_PRELOAD" unset _OLD_LD_PRELOAD EOF

5.4 重新激活验证

conda deactivate conda activate MOTIP2 python -c "import torch; print(torch.__version__, torch.cuda.is_available())"

您可能感兴趣的与本文相关的镜像

Qwen3-32B-Chat 私有部署镜像 | RTX4090D 24G 显存 CUDA12.4 优化版

Qwen3-32B-Chat 私有部署镜像 | RTX4090D 24G 显存 CUDA12.4 优化版

Qwen
文本生成
Qwen3

本镜像基于 RTX 4090D 24GB 显存 + CUDA 12.4 + 驱动 550.90.07 深度优化,内置完整运行环境与 Qwen3-32B 模型依赖,开箱即用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值