-
Notifications
You must be signed in to change notification settings - Fork 730
Description
Description
I maintain an open-source desktop application that uses DJL (which is great, thanks!).
Our complication is that we
- don't want to inflate our downloads with the engines (which not every user will need)
- don't want to download anything without user agreement
DJL's ability to download engines on demand solves 1.
What we need for 2. is a way to query whether an engine is available without prompting any download if it is not.
I've called this a 'bug' rather than 'enhancement' because it was possible to solve this in DJL v0.24.0 and earlier using System.setProperty("offline", "true");.
However since #2826 this strategy no longer works, so it fails in v0.25.0.
Related issue:
How to Reproduce?
I've written a short demo of the issue at
https://gist.github.com/petebankhead/836c8e0db8a4e4d9f0d5ecdb032a08ba
I have focussed only on PyTorch.
Error Message
Current behavior, after #2826 (v0.25.0)
I get the following messages using the current master:
Creating cache dir /var/folders/5f/l578vlrn29gd42rdsqbsv1380000gn/T/djl-cache350144786515737871
Can't get engine offline, I'd now prompt the user now to get it online
Engine is null
Error getting engine offline: java.lang.ExceptionInInitializerError
Error getting engine online: java.lang.NoClassDefFoundError: Could not initialize class ai.djl.pytorch.engine.PtEngineProvider$InstanceHolder
Without #2826 (v0.24.0)
Replacing PtEngineProvider to remove the changes in #2826 it works as expected
Creating cache dir /var/folders/5f/l578vlrn29gd42rdsqbsv1380000gn/T/djl-cache6785785179087611189
Can't get engine offline, I'd now prompt the user now to get it online
Error getting engine offline: ai.djl.engine.EngineException: Failed to save pytorch index file
[main] INFO ai.djl.pytorch.jni.LibUtils - Downloading https://publish.djl.ai/pytorch/2.1.1/cpu/osx-aarch64/native/lib/libtorch_cpu.dylib.gz ...
[main] INFO ai.djl.pytorch.jni.LibUtils - Downloading https://publish.djl.ai/pytorch/2.1.1/cpu/osx-aarch64/native/lib/libtorch.dylib.gz ...
[main] INFO ai.djl.pytorch.jni.LibUtils - Downloading https://publish.djl.ai/pytorch/2.1.1/cpu/osx-aarch64/native/lib/libc10.dylib.gz ...
[main] INFO ai.djl.pytorch.jni.LibUtils - Extracting jnilib/osx-aarch64/cpu/libdjl_torch.dylib to cache ...
[main] INFO ai.djl.pytorch.engine.PtEngine - PyTorch graph executor optimizer is enabled, this may impact your inference latency and throughput. See: https://docs.djl.ai/docs/development/inference_performance_optimization.html#graph-executor-optimization
[main] INFO ai.djl.pytorch.engine.PtEngine - Number of inter-op threads is 10
[main] INFO ai.djl.pytorch.engine.PtEngine - Number of intra-op threads is 10
Engine is PyTorch:2.1.1, capabilities: [
]
PyTorch Library: /var/folders/5f/l578vlrn29gd42rdsqbsv1380000gn/T/djl-cache6785785179087611189/pytorch/2.1.1-cpu-osx-aarch64
Expected Behavior
It should be possible to query programmatically whether an engine exists without immediately prompting the download.
Any failure to download the engine (because of offline mode) shouldn't prevent requesting the engine later.
What have you tried to solve it?
I can't see a workaround in v0.25, so we will likely need to stay with v0.24.
It seems that InstanceHolder can't be initialized in offline mode if the engine isn't available, so the class then isn't available.
Whenever that happens, all subsequent attempts fail with NoClassDefFoundError even if System.setProperty("offline", "false"); has been called.
Restoring the behavior prior to #2826 would enable our previous workaround to work, although I think a cleaner solution would be to provide an API to query a model that doesn't prompt a download.
I am reluctant to rely upon "offline" as a system property, and share @docent's opinion at #2632 (comment) that an alternative name would help avoid potential clashes.
Environment Info
I'm using Java 17 on Apple Silicon & can provide further detail if needed, but I expect the issue to affect all platforms.