DUBJUG_Creating GenAI Apps in Java with SD4J and the ONNX Runtime

juarezjunior 16 views 20 slides Mar 11, 2025
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

DUBJUG_Creating GenAI Apps in Java with SD4J and the ONNX Runtime


Slide Content

. 7
ORACLE 23" fl ll
ORACLE Database ol

Creating GenAl Apps in Java with SD4J and
the ONNX Runtime

ss)
DUBJUG 2024 DUBJUG
Juarez Barbosa Junior @juarezjunior
Senior Principal Java Developer Evangelist
ORACLE
SS

[9] ojuarezjunior Juarez Barbosa Junior
Senior Principal Java Developer Evangelist @ Oracle

+ Coming from Dublin, Ireland

+ 28 years of experience in SW Engineering & DevRel
+ Oracle, Microsoft, IBM, Nokia, Unisys, Accenture, startups
+ Microsoft Azure Developer Relations Lead
+ IBM Watson Tech Evangelist & Cloud Rockstar
+ IBM Mobile Tech Evangelist & Global Thought Leader
+ Nokia Developers Global Champion
. um Python, Cloud, DevOps, SRE, Cloud-native, loT, Al, Blockchain,
ist
+ Speaker at conferences

+ Oracle CloudWorld, Oracle Code, Microsoft Ignite & TechX, ¡Prime,
JCON, DevConf.cz, GeeCon, DevOpsDays, DeveloperWeek, DevOps
Institute, CloudLand, DWX, The Developer's Conference (TDC),
Sec4Dey, JSNation, NodeConf, Conf42, Shift Conf, Global Azure,
Open-Source Lisbon, CodeFrenzy, Mélée Numérique, React Summit,
Tests Summit, Porto TechHub Conf, Pyjamas, MiTechCon, Data
Science Summit, OpenSourceNorth, WeAreDevelopers, Global
Software Architecture Summit, JavaCro, JUGs, OUGs, GDGs,

meetups, hackathons, and customer engagements.

Agenda

+ Stable Diffusion - Concepts

+ Stable Diffusion for Java (SD4J) by
Oracle Labs

+ ONNX and ONNX Runtime Extensions
+ SD4J - Demo

+ Oracle Database 23ai For Developers

+ Technical References

+» Oracle for Java / Database Developers

Stable Diffusion - Concepts

- In a nutshell

- Stable Diffusion is a technique under the umbrella of GenAl used to generate
images primarily from textual descriptions.

- A diffusion model predicts the probability distribution of images using a
diffusion process.

- The diffusion process iteratively applies noise to an image, gradually
increasing the noise level and then reversing the process to reconstruct the
original image - denoising with guidance, aligning with the textual description.

- One of the advantages of Stable Diffusion is its ability to control the diversity
and quality of generated images through the noise level parameter.

- The noise intensity allows users to adjust the image quality and diversity
trade-offs.

Stable Diffusion - Concepts

- In a nutshell

+ Stable Diffusion finds applications in various domains, such as art, design, and
entertainment, by providing image synthesis, augmentation, and
manipulation.

- Itcan run on regular computers with good graphics cards, making it more
accessible.

+ Most projects are Open-Source, allowing developers to experiment and fine-
tune the model to meet specific needs.

Stable Diffusion for Java

- SD4J

A Java implementation of Stable Diffusion (modified port of
a C# implementation) running on top of ONNX Runtime

+ Created by Oracle Labs (R&D) as OSS

It targets ONNX Runtime 1.14

+ It supports using CPUs and CUDA GPUs
+ It supports SD v1.5, SD v2 and SDXL style models

+ It provides a reusable class (com.oracle.labs.mlrg.sd4j.SD4J)

with a clear contract (interface) to allow the creation of
image generation pipelines

Oona

»

ONNX - Open Neural Network Exchange

+ ONNX Format

+ An open-source format designed to represent machine learning models.

+ Expressed as a Protocol Buffers (protobuf) file containing a
computational graph representing the model.

+ Models trained in one framework can be converted to the ONNX format
and used in another.

+ The ONNX ecosystem includes a wide range of tools and libraries for
model conversion, optimization, inference, and visualization.

+ While ONNX can represent models for training, its primary focus is on
inference, which is the process of using a trained model to make
predictions on new data.

Promotes interoperability (frameworks, tools, runtime environments).

Also promotes standardization, efficiency (HW), and ecosystem
development.

ONNX - Open Neural Network Exchange

- ONNX Runtime | |
+ The ONNX Runtime is an optimized inference engine,

offering efficient execution of ONNX models with low latency
and high throughput.

+ It leverages hardware acceleration capabilities, including GPU

acceleration through CUDA, and optimizations for CPUs. O N N x
It provides tools for quantizing and optimizing ONNX models
to'improye performance and dues nemaryı 'ootprint, RUNTIME

making them more suitable for deployment on resource-
constrained devices.

It is also cross-platform, as the ONNX Runtime supports
multiple operating systems, including Windows, Linux, and
macOS, making it versatile tor deployment across different
target environments.

SD4)J - Demo

TITAN

- Creating GenAl Apps in Java with SD4J (Stable
Diffusion for Java) and the ONNX Runtime

. https:/ /juarezjunior.medium.com/b72385c59329

Free | Oracle Database 23ai For Developers

Oracle Always Free ADB ADB Free Container Image Oracle Database Free

Available on OCI Available for download Available as RPM, Docker
Image, VBox VM

Very Low Cost Supported Developer Edition of ADB, BaseDB, ExaDB-D, and ExaDB-C@C

Cape © 2024 Orca o/o as Cor ral

Confidential - Oracle Restricted

Technical References

Spring Al - https://spring.io/projects/spring-ai

OpenAl - https://openai.com/

Oracle Al Vector Search - https://rb.gv/sp41uk

Oracle Al Vector Search for Java Developers with the Oracle Database 23ai -

https://rb.gv/7ivwxr

E u / JDBC - https://www.oracle.com/jdbc
Introduction to Oracle JDBC Driver Support for Virtual Threads - https://bit.ly/3UINJWP

+ Developing an Oracle JDBC app with GraalVM Native Image - https://rb.sv/iy3sgh

+ Getting Started with Reactive Relational Database Connectivity and the Oracle R2DBC
Driver - https://rb.gy/42dnz5

* Getting Started with the Java library for Reactive Streams Ingestion (RSI) -
https://bit.ly/3rEiRnC

+ Introduction to JDBC Reactive Extensions with the Oracle Database — Developer
Release - https://rb.; xirbx

+ Pipelined Database Operations - https://rb.ev/iv3sgh

+ What's in Oracle Database 23ai for Java Developers? -
https://www.oracle.com/a/tech/docs/database/whats-in-oracledb23ai-for-java-
developers.pdf

confidential - Oracle

Juarez Junior

Y | @juarezjunior

ORACLE

Confidential - Oracle Restricted

deyeloper.oracle.com
oracle.com/jdbc

Confidential Oracle Restricted

te ©

Grave oca Koon Java App
paa Dev with
Oracle
Database

— Gpgo- 28eecs

Zo

Overview of Oracle DB Access with Java

operators (map, reduce, filters),
concurrency modeling,

monitoring, tracing,
User Java code + JDBC

JavaucFlow

Database Access with

|

ut

Async call with non-blocking backpressut Oracle Database

|" Synchronous blocking cas

Copyright © 2024, Oracle and/or its affiliates

Oracle JDBC - Support for the Latest Java
Versions

. Support to the latest Java versions

(11,17,

* Project Loom - Virtual Threads
support

; 2 sl
J ava 2 2 + Java Virtual Threads and Pipelined
Database Operations

Launch Stream

1) and GraalVM

+ JDBC Standards - 4.2 and 4.3
+ Reactive Streams - Java Flow API
support

Re Reactive Streams Ingestion
March 19th 17 + Pipelined Database Operations

Oracle LiveLabs

Showcasing how Oracle's solutions can
solve your business problems

500+

free workshops,
available or in
development

people have already visited
LiveLabs

600+

events run
using LiveLabs
workshops

developer.oracle.com/livelabs
learn something new ...at your pace!

Qos

Oracle ACE Program

3 membership tiers à Oracle ACE

Oracle ACE à Oracle ACE Oracle ACE ás
Director Pro Associate Nominate

yourself or a candidate:

ace.oracle.com/nominate
Learn more - ace.oracle.com

Connect: EP [email protected] E @oracleace facebook.com/OracleACEs — [8] blogs.oracle.com/ace

Create your FREE
Cloud Account

* Goto

https://signup.cloud.oracle.com/

ORACLE
Cloud Infrastructure

de

~—_

Oracle Cloud Free Tier

Get started with.

Terms of Use