| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This project provides a REST API wrapper for the amazing Llama3.java project from Alfonso² Peterssen. The wrapper is compliant with the OpenAI API specification for chat completions.
Make sure to download an ARM compliant SDK, for example from https://bell-sw.com/pages/downloads/#jdk-21-lts
Demo.mp4Set the JAVA_HOME environment variable to the ARM SDK path.
Example with Zulu JDK 23 (zulu23.30.13-ca-jdk23.0.1-macosx_aarch64)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-23.jdk/Contents/HomeIMPORTANT: Do not use SDKMan because this will fall back to the x86 version of the SDK.
mvn clean packageUse a GraalVM JDK 24 or higher (tested with Graal 24, ea 30)
./mvnw -Pnative native:compile
This will produce ./target/llama3-server. This does not work on MacOS because there is no Vector API support on Graal + MacOS.
Download a GGUF model from the Hugging Face model hub and place it in the 'models' directory. For example:
mkdir models
cd models
curl https://huggingface.co/hugging-quants/Llama-3.2-1B-Instruct-Q8_0-GGUF/blob/main/llama-3.2-1b-instruct-q8_0.ggufUpdate the 'llama.model.name' variable in the application.properties file if you use a different model.
spring.application.name=Llama3.java Server
server.servlet.context-path=/
llama.model.path=models
llama.model.name=Meta-Llama-3.2-1b-instruct-Q8_0.gguf
logging.level.com.llama4j=INFO
server.address=localhost
server.port=8080Start the Spring Boot app which holds the Llama3.java REST wrapper as follows:
java --add-modules jdk.incubator.vector --enable-preview -jar target/llama3-server-1.0.0-SNAPSHOT.jaror use the run.sh script which sets some extra JVM GC and Heap settings
./run.shcurl -X POST http://localhost:8080/chat/completions \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"role": "system",
"content": "You are a comedian."
},
{
"role": "user",
"content": "Tell me a joke."
}
],
"temperature": 0.7,
"top_p": 0.95,
"max_tokens": 100
}'Response
{
"id":"chatcmpl-1",
"object":"chat.completion",
"created":1729447400,
"model":"Meta-Llama-3.2-1b-instruct-Q8_0.gguf",
"systemFingerprint":"fp_178ce5010c913",
"choices":[
{
"index":0,
"message":{
"role":"assistant",
"content":"A man walked into a library and asked the librarian, \"Do you have any books on Pavlov's dogs and Schrödinger's cat?\" The librarian replied, \"It rings a bell, but I'm not sure if it's here or not.\""
},
"logprobs":null,
"finishReason":"stop"
}
],
"usage":{
"promptTokens":25,
"completionTokens":53,
"totalTokens":78,
"completionTokensDetails":{
"reasoningTokens":0
}
}Launch any JetBrains IDE (such as IDEA, CLion, WebStorm, etc.) and install 'DevoxxGenie' from the Plugins marketplace. You can then choose either 'Jlama (Experimental)' or 'Exo (Experimental)', both of which utilize OpenAI's Chat Completion.
Next, enter a prompt and optionally attach files to the window context by using the 'Add File' icon located below the prompt text area.
Example with file attachment in prompt context:
Running on Apple M1 Max with 64Gb (LPDDR5) of RAM (32 number of Cores).
This profiling trace shows a CPU-heavy Java application, likely dealing with machine learning or vectorized computation. Here's a breakdown of key components:
Heavy CPU Usage (java.util.concurrent.ForkJoinWorkerThread.run) at 86%
com.llama4j.core.FloatTensor$$Lambda.accept (61.5%)
jdk.incubator.vector.FloatVector.reduceLanes (49.5%)
com.llama4j.core.ArrayFloatTensor.getFloatVector (7.7%)
com.llama4j.web.rest.LlamaWrapperApplication.chatCompletions (13.9%)
com.llama4j.core.FloatTensor.matmul (12.0%)
com.llama4j.core.FloatTensor$$Lambda$0x0000000080143b048.accept(int) Likely the core model inference bottleneck
jdk.incubator.vector.Float128Vector.reduceLanes(VectorOperators$Associative) Part of the FloatTensor operations
com.llama4j.core.ArrayFloatTensor.getFloatVector(VectorSpecies, int)
com.llama4j.web.rest.LlamaWrapperApplication.chatCompletions(ChatCompletionRequest)
Profile the FloatTensor class to identify specific bottlenecks Consider using more efficient linear algebra libraries or GPU acceleration Optimize memory access patterns and data structures
Investigate the use of more efficient vector operations or libraries Consider using SIMD instructions if not already implemented
Optimize the getFloatVector method in ArrayFloatTensor Consider using more efficient data structures or access patterns
Profile the chatCompletions method to identify specific bottlenecks Consider implementing caching mechanisms or request batching Optimize data serialization/deserialization if applicable
This is just a simple Spring Boot OpenAI REST wrapper around the amazing Llama3.java project from Alfonso² Peterssen!
Thanks Alfonso for leading the way! 💪🏻 ☕️
| Back | FazBrowse Home | New Git URL |