Djl

An Engine-Agnostic Deep Learning Framework in Java

Last verified:

Visit Djl

What is Djl?

Deep Java Library (DJL) is an open-source, high-level, engine-agnostic Java framework for deep learning designed to make machine learning accessible to Java developers. It provides a native Java development experience that functions like any other regular Java library, allowing developers to use their existing IDEs like Eclipse or IntelliJ to build, train, and deploy deep learning models without becoming ML experts.

Key features include engine-agnosticism supporting PyTorch, TensorFlow, Apache MXNet, ONNX Runtime, XGBoost, and LightGBM; a comprehensive Model Zoo with pre-trained models ready for inference out of the box; built-in support for GPU inference and multi-GPU training with automatic hardware detection; high-performance multi-threaded inference; and extensive extensions for Android, audio, AWS S3, Hadoop, OpenCV, Spark, NLP with Huggingface Tokenizers, and time series data.

DJL is primarily for Java developers who want to integrate deep learning into Java applications, teams already invested in Java ecosystems looking to add ML capabilities, developers who want to avoid locking into a single deep learning engine, and educators and students using the Dive into Deep Learning book which has DJL implementations adopted at 175 universities from 40 countries.

Djl pricing

Pricing model: Freemium

Completely free and open-source under Apache-2.0 license. No subscription tiers or paid plans. Distributed via Maven Central as a regular Java library dependency. All features including engine-agnostic deep learning, Model Zoo access, GPU support, and extensions are included at no cost.

Djl pros

  • Open-source under Apache-2.0 license with no cost
  • Engine-agnostic - switch between PyTorch, TensorFlow, MXNet, ONNX anytime
  • Native Java API designed for Java developers
  • Works with familiar IDEs like Eclipse and IntelliJ
  • No ML expertise required to get started
  • Model Zoo with pre-trained models ready for immediate inference
  • Automatic CPU/GPU detection and selection
  • Supports multi-GPU training with easy configuration
  • High-performance multi-threaded inference
  • Write once, run on any deep learning engine
  • Extensive extensions including Android, AWS S3, Spark, Hadoop support
  • NLP support with Huggingface Tokenizers and fastText
  • Built-in Translator for out-of-the-box inference
  • Comprehensive documentation and JavaDoc API reference
  • Dive into Deep Learning book with DJL implementations adopted at 175 universities

Djl cons

  • Does not support distributed training
  • Some known issues with JDK 11, JDK 8 recommended
  • Smaller community compared to Python frameworks
  • Fewer online resources and tutorials than PyTorch/TensorFlow Python
  • Python engine binds code to PyTorch engine
  • Complex PyTorch IValue types require engine-specific code
  • ONNX Runtime requires manual GPU package installation
  • Fewer pre-trained models compared to Python ecosystem

Frequently asked questions about Djl

Why should I use Deep Java Library (DJL)?

DJL prioritizes the Java developer's experience, makes it easy for new machine learning developers to get started, allows developers to write modular reusable code, reduces friction for deploying to production, connects model developers with consumers using the model zoo, allows developers to write code once and run it on any deep learning engine, and allows developers to use engine-specific features.

Which models can I run with DJL?

DJL supports PyTorch TorchScript models, TensorFlow SavedModel bundles, Apache MXNet models, ONNX models, Python script models, XGBoost models, LightGBM models, Sentencepiece models, and fastText/BlazingText models.

Does DJL support inference on GPU?

Yes. DJL supports inference on GPU. If GPUs are available, DJL automatically detects the GPU and runs inference on a single GPU by default. For OnnxRuntime, you need to install the onnxruntime_gpu package to enable GPU support.

Does DJL support multi-threaded inference?

Yes. DJL offers high performance multi-threaded inference for improved performance during model prediction tasks.

Does DJL support training on multiple GPUs?

Yes. DJL offers multi-GPU support and can automatically detect available GPUs. By default it runs on a single GPU unless you specify otherwise in your TrainingConfig. You can configure the number of GPUs to use by setting devices in your TrainingConfig.

Does DJL support distributed training?

No. DJL does not currently support distributed training across multiple machines or nodes.

Can I run DJL with different PyTorch versions?

Yes. Each DJL release supports a range of PyTorch versions. You can set the PYTORCH_VERSION environment variable or Java System properties to choose a different version of PyTorch.

How can I run Python models in DJL?

DJL has a Python engine that allows you to run inference with Python code. The Python engine provides the same code experience as other engines and makes it easy to migrate to native Java models later.

How can I get help if I run into problems?

You can check out the troubleshooting document, discussions, and issues on GitHub. You can also join the DJL Slack channel to get in touch with the development team for questions and discussions.

How do I pass arbitrary input data types to a PyTorch model?

DJL uses NDList as a standard data type to pass to models. You can automatically map NDList to PyTorch's IValue by setting NDArray names with suffix [] for lists, () for tuples, or group.key for dictionaries. For non-tensor inputs or complex IValue, you must use the IValue class directly which binds code to PyTorch engine.

Categories

Use cases

Browse all AI tools on NeedAnAI