You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tinywisdom (via GitHub)" <gi...@apache.org> on 2026/01/11 02:15:07 UTC
[I] [Bug] Segmentation fault when importing `torchmetrics` after creating a TVM CUDA target (LLVM initialization / COFF OptTable) [tvm]
tinywisdom opened a new issue, #18655:
URL: https://github.com/apache/tvm/issues/18655
### Summary
Creating a TVM `cuda` target and then importing an unrelated Python package (`torchmetrics`) causes an immediate segmentation fault. There is no model compilation or runtime execution involved—simply constructing a target triggers the problem.
The crash occurs inside LLVM initialization, specifically in COFF directive parser global constructors (e.g., `llvm::opt::OptTable::buildPrefixChars()` and `_GLOBAL__sub_I_COFFDirectiveParser.cpp`), during dynamic library loading (`dlopen`).
The behavior suggests a dynamic linking / multiple-LLVM interaction.
---
### Minimal Reproduction
```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import tvm
from tvm import target
from torchmetrics import Accuracy # segmentation fault occurs here in my environment
def main():
print("Creating CUDA target...")
tgt = target.Target("cuda -arch=sm_86")
print("Target created:", tgt)
metric = Accuracy(task="multiclass", num_classes=10)
print("Metric created:", metric)
if __name__ == "__main__":
main()
```
### Actual Behavior
On my machine, the process prints "Creating CUDA target…" and then crashes with segmentation fault during import of `torchmetrics`. The beginning of the backtrace is:
```
!!!!!!! Segfault encountered !!!!!!!
File "<unknown>", in llvm::opt::OptTable::buildPrefixChars()
File "<unknown>", in COFFOptTable::COFFOptTable()
File "<unknown>", in _GLOBAL__sub_I_COFFDirectiveParser.cpp
File "./elf/dl-init.c", in call_init
File "./elf/dl-open.c", in dl_open_worker
...
Segmentation fault (core dumped)
```
Full trace is long but mostly `dlopen` / `dl-init` frames followed by LLVM initialization frames.
---
### Expected Behavior
Importing `torchmetrics` after TVM target construction should not crash, especially before any compilation or runtime invocation occurs. The two libraries are unrelated and no model is passed to TVM.
---
### Notes on Repro Properties
* The issue does **not** require PyTorch, transformers, or CUDA execution.
* The critical step is:
```
tgt = target.Target("cuda -arch=sm_86")
```
followed by importing a package that triggers its own dynamic-library / symbol loading chain.
* The failure happens even if `Accuracy` is never called.
* Removing the TVM target creation avoids the crash.
### Environment
```
OS: Linux x86_64 (glibc-based)
Python: 3.10.16 (conda-forge)
NumPy: 2.2.6
PyTorch: 2.9.0+cu128
Torchmetrics: <version depends on pip/conda> # fill here if needed
TVM: 0.22.0
LLVM: 17.0.6 (from tvm.support.libinfo())
GIT_COMMIT_HASH: 9dbf3f22ff6f44962472f9af310fda368ca85ef2
GPU: sm_86 (Ampere)
TVM target: cuda -keys=cuda,gpu -arch=sm_86 -max_num_threads=1024 -thread_warp_size=32
CUDA toolkit: likely 12.8 (based on PyTorch +cu128 build)
```
### Triage
Please refer to the list of label tags [here](https://github.com/apache/tvm/wiki/Issue-Triage-Labels) to find the relevant tags and add them below in a bullet format (example below).
* needs-triage
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [I] [Bug] Segmentation fault when importing `torchmetrics` after creating a TVM CUDA target (LLVM initialization / COFF OptTable) [tvm]
Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on issue #18655:
URL: https://github.com/apache/tvm/issues/18655#issuecomment-4483840839
Hi @tinywisdom
Thanks for the report, I checked the current main branch, and this specific crash path should no longer occur.
The root cause was likely LLVM symbol collision during dynamic loading(global symbol namespace pollution).
main branch now isolates TVM runtime and compiler loading:
- `libtvm_runtime` is loaded with `RTLD_GLOBAL`(runtime symbols remain globally visible as needed).
- `libtvm_compiler` (which carries LLVM-dependent compiler code) is loaded with `RTLD_LOCAL` (compiler/LLVM internals do not leak globally).
So when another package later loads its own LLVM-related stack(via `dlopen`), it is much less likely to collide with TVM's LLVM symbols.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org