djl icon indicating copy to clipboard operation
djl copied to clipboard

Error when load Pytorch

Open ColainCYY opened this issue 1 year ago • 1 comments

Here is my pom.xml:

<dependency>
            <groupId>ai.djl</groupId>
            <artifactId>api</artifactId>
            <version>0.18.0</version>
        </dependency>
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-engine</artifactId>
            <version>0.18.0</version>
        </dependency>
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-native-auto</artifactId>
            <version>1.9.1</version>
        </dependency>
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-native-cpu</artifactId>
            <classifier>linux-x86_64</classifier>
            <version>1.11.0</version>
        </dependency>
        <dependency>
            <groupId>ai.djl.pytorch</groupId>
            <artifactId>pytorch-jni</artifactId>
            <version>1.11.0-0.18.0</version>
        </dependency>

My code is:

Engine engine = Engine.getEngine("PyTorch");

My Error is:

Exception in thread "main" ai.djl.engine.EngineException: Failed to load PyTorch native library
	at ai.djl.pytorch.engine.PtEngine.newInstance(PtEngine.java:83)
	at ai.djl.pytorch.engine.PtEngineProvider.getEngine(PtEngineProvider.java:40)
	at ai.djl.engine.Engine.getEngine(Engine.java:181)
	at com.netease.is.textalg.tmp.provider.A.main(A.java:292)
Caused by: java.lang.UnsatisfiedLinkError: E:\Anaconda3\Lib\site-packages\torch\lib\asmjit.lib: %1 不是有效的 Win32 应用程序。
	at java.lang.ClassLoader$NativeLibrary.load(Native Method)
	at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
	at java.lang.Runtime.load0(Runtime.java:809)
	at java.lang.System.load(System.java:1086)
	at ai.djl.pytorch.jni.LibUtils.loadNativeLibrary(LibUtils.java:359)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.Iterator.forEachRemaining(Iterator.java:116)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
	at ai.djl.pytorch.jni.LibUtils.loadLibTorch(LibUtils.java:139)
	at ai.djl.pytorch.jni.LibUtils.loadLibrary(LibUtils.java:76)
	at ai.djl.pytorch.engine.PtEngine.newInstance(PtEngine.java:52)
	... 3 more

Shoud I installed Pytorch on my computer before using DJL?

ColainCYY avatar Dec 07 '23 10:12 ColainCYY

DJL doesn't depend on python and PyTorch. Why it try to load files from: E:\Anaconda3\Lib\site-packages\torch\lib\asmjit.lib? Did you send PYTORCH_LIBRARY_PATH env var?

By the way, your dependencies in your POM file is messed up.

  1. you version is mismatched between DJL's libraries, see: https://docs.djl.ai/master/engines/pytorch/pytorch-engine/index.html#supported-pytorch-versions
  2. Can you use latest DJL, 0.18.0 is very old
  3. Please use BOM to manage DJL's dependency: see: https://docs.djl.ai/master/bom/index.html#djl-bill-of-materials-bom

frankfliu avatar Dec 07 '23 17:12 frankfliu

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

github-actions[bot] avatar Feb 26 '24 00:02 github-actions[bot]