Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates DJL manual engine initialization #2885

Merged
merged 6 commits into from
Jan 9, 2024

Conversation

zachgk
Copy link
Contributor

@zachgk zachgk commented Dec 5, 2023

fixes #2875
reverts #2876, #2884

This adds new support for DJL manual initialization of engines to support DJL_ENGINE_MANUAL_INIT. Once done, no engines providers will be found or loaded on startup. Instead, they can be added manually by:

PtEngineProvider provider = new PtEngineProvider();
provider.getEngine(); // Optional, throws exception if the provider can't load
Engine.registerEngine(provider);
Engine.setDefaultEngine(provider.getEngineName()); // Optional, sets as default

fixes deepjavalibrary#2875
reverts deepjavalibrary#2876

This adds new support for DJL manual initialization of engines to support
`DJL_ENGINE_MANUAL_INIT`. Once done, no engines providers will be found or
loaded on startup. Instead, they can be added manually by:

```java
PtEngineProvider provider = new PtEngineProvider();
provider.getEngine(); // Optional, throws exception if the provider can not load
Engine.registerEngine(provider);
Engine.setDefaultEngine(provider.getEngineName()); // Optional, sets as default
```
@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2023

Codecov Report

Attention: 1344 lines in your changes are missing coverage. Please review.

Comparison is base (bb5073f) 72.08% compared to head (16fbd1f) 72.27%.
Report is 960 commits behind head on master.

Files Patch % Lines
...va/ai/djl/modality/nlp/generate/TextGenerator.java 2.81% 276 Missing ⚠️
.../java/ai/djl/modality/nlp/generate/SeqBatcher.java 0.75% 132 Missing ⚠️
...ity/nlp/generate/ContrastiveSeqBatchScheduler.java 2.97% 98 Missing ⚠️
...i/djl/modality/nlp/generate/SeqBatchScheduler.java 9.83% 55 Missing ⚠️
.../java/ai/djl/modality/cv/BufferedImageFactory.java 40.96% 47 Missing and 2 partials ⚠️
...a/ai/djl/modality/nlp/generate/StepGeneration.java 2.04% 48 Missing ⚠️
api/src/main/java/ai/djl/ndarray/NDArray.java 43.42% 39 Missing and 4 partials ⚠️
...n/java/ai/djl/modality/cv/output/CategoryMask.java 22.00% 39 Missing ⚠️
...i/src/main/java/ai/djl/ndarray/NDArrayAdapter.java 71.21% 31 Missing and 7 partials ⚠️
.../cv/translator/SemanticSegmentationTranslator.java 37.50% 35 Missing ⚠️
... and 75 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2885      +/-   ##
============================================
+ Coverage     72.08%   72.27%   +0.18%     
- Complexity     5126     7277    +2151     
============================================
  Files           473      721     +248     
  Lines         21970    32499   +10529     
  Branches       2351     3389    +1038     
============================================
+ Hits          15838    23488    +7650     
- Misses         4925     7389    +2464     
- Partials       1207     1622     +415     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This makes several updates:
- engines will now initialize once per instance of EngineProvider rather than
re-attempt to initialize
- Registering an engine can overwrite the existing one
- All engines now use the synchronized form rather than the static instance
holder. This allows them to have multiple versions and be local to the instance
rather than global (but the instance is saved globally)
@zachgk zachgk merged commit 6141c48 into deepjavalibrary:master Jan 9, 2024
5 checks passed
@zachgk zachgk deleted the manualInit branch January 9, 2024 20:10
siddvenk added a commit to siddvenk/djl that referenced this pull request Jan 10, 2024
zachgk added a commit to zachgk/djl-serving that referenced this pull request Jan 10, 2024
This updates DJL Serving to follow the engine initialization standards set in
deepjavalibrary/djl#2885. First, it updates the
PyEngineProvider to follow the EngineProvider conventions.

It also updates the DependencyManager, fixing some bugs that inspired
deepjavalibrary/djl#2934. The dependency manager before
this change would always re-register the engine with a new provider. Beforehand,
the engine was fully static and unable to re-initialize, so this would not
accidentally re-initialize engines. After this, it would re-initialize engines
that did not support it causing errors. Instead, it should only register new
engines rather than all providers to avoid these accidental re-initialization.
frankfliu added a commit to onaple/djl that referenced this pull request Feb 26, 2024
frankfliu added a commit that referenced this pull request Feb 26, 2024
…turns null when called concurrently. (#3005)

* Fixes cases where the getEngine method in the EngineProvider class returns null when called concurrently.

* Revert "Creates DJL manual engine initialization (#2885)"

This reverts commit 6141c48.

---------

Co-authored-by: 王旭 <[email protected]>
Co-authored-by: Frank Liu <[email protected]>
frankfliu pushed a commit that referenced this pull request Apr 26, 2024
* Creates DJL manual engine initialization

fixes #2875
reverts #2876

This adds new support for DJL manual initialization of engines to support
`DJL_ENGINE_MANUAL_INIT`. Once done, no engines providers will be found or
loaded on startup. Instead, they can be added manually by:

```java
PtEngineProvider provider = new PtEngineProvider();
provider.getEngine(); // Optional, throws exception if the provider can not load
Engine.registerEngine(provider);
Engine.setDefaultEngine(provider.getEngineName()); // Optional, sets as default
```

* Revert "[tensorflow] Revert InstanceHolder for TensorFlow engine (#2884)"

This reverts commit 586bb07.

* Revert "[api] Replace double-check singlton with lazy initialization (#2826)"

This reverts commit 3927867.

* Make engines initialized

This makes several updates:
- engines will now initialize once per instance of EngineProvider rather than
re-attempt to initialize
- Registering an engine can overwrite the existing one
- All engines now use the synchronized form rather than the static instance
holder. This allows them to have multiple versions and be local to the instance
rather than global (but the instance is saved globally)

* Throws Exception on bad getEngine

* Removes unnecessary check
frankfliu added a commit that referenced this pull request Apr 26, 2024
…turns null when called concurrently. (#3005)

* Fixes cases where the getEngine method in the EngineProvider class returns null when called concurrently.

* Revert "Creates DJL manual engine initialization (#2885)"

This reverts commit 6141c48.

---------

Co-authored-by: 王旭 <[email protected]>
Co-authored-by: Frank Liu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to query engine in offline mode to ask user whether to download
3 participants