oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.33k stars 1.63k forks source link

[GR-52267] Can't compile with Onnxruntime library, conflict with svm-enterprise.jar #8431

Open JiangWork opened 8 months ago

JiangWork commented 8 months ago

I worked on a shared library, which uses onnxruntime for inference. When I use native-image -jar ./target/test-1.0-SNAPSHOT-jar-with-dependencies.jar --shared -H:Name=libtest to generate shared library, i get the following error:

Error: Class-path entry file:///xxx/target/test-1.0-SNAPSHOT-jar-with-dependencies.jar contains class ai.onnxruntime.ValueInfo. This class is part of the image builder itself (in file:///xxx/graalvm-jdk-21.0.1+12.1/Contents/Home/lib/svm/builder/svm-enterprise.jar) and must not be passed via -cp. This can be caused by a fat-jar that illegally includes svm.jar (or graal-sdk.jar) due to its build-time dependency on it. As a workaround, -H:+AllowDeprecatedBuilderClassesOnImageClasspath allows turning this error into a warning. Note that this option is deprecated and will be removed in a future version.

When I added the '-H:+AllowDeprecatedBuilderClassesOnImageClasspath' parameter according to the instructions, I can have the shared library, but when use the shared library, it errors with:java.lang.NoClassDefFoundError: ai.onnxruntime.OrtEnvironment

Graal version: graalvm-jdk-21.0.1+12.1

Reproducible code attached: test.zip

run mvn package and then native-image -jar ./target/test-1.0-SNAPSHOT-jar-with-dependencies.jar --shared -H:Name=libtest

JiangWork commented 8 months ago

@oubidar-Abderrahim I have created new issue

fniephaus commented 8 months ago

Thanks for filing the ticket, @JiangWork. As the error correctly suggests, the Native Image builder also has a dependency on ai.onnxruntime. We are looking into a fix for this.

zekronium commented 8 months ago

In my testing version "GraalVM CE 21.0.2+13.1" seems to not throw this error anymore

JiangWork commented 8 months ago

@zekronium Looks like it is community version? I am using enterprise version. Let me try "GraalVM CE 21.0.2+13.1"

zekronium commented 8 months ago

@zekronium Looks like it is community version? I am using enterprise version. Let me try "GraalVM CE 21.0.2+13.1"

I was encountering the same exact issue with CE too

JiangWork commented 7 months ago

hi, @fniephaus. Just want to check, any plan to fix this issue?

fniephaus commented 7 months ago

Yes, we are working on a fix for this as we speak. We'll share an update as soon as it's ready.

sjivan commented 3 months ago

@fniephaus any updates on this? I too am tripping on the same issue. This effectively prevents creation of a native image for AI applications using AllMiniLmL6V2EmbeddingModel because this class has a dependency on the onnxruntime jar.