Skip to content

Commit 04f04a7

Browse files
Remove TornadoVMInitializer and refactor TornadoVM initialization logic directly into GPULlama3Recorder.
1 parent 5cfa986 commit 04f04a7

File tree

2 files changed

+2
-693
lines changed

2 files changed

+2
-693
lines changed

model-providers/gpu-llama3/runtime/src/main/java/io/quarkiverse/langchain4j/gpullama3/runtime/GPULlama3Recorder.java

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package io.quarkiverse.langchain4j.gpullama3.runtime;
22

3-
import java.io.File;
43
import java.nio.file.Paths;
54
import java.util.function.Supplier;
65

7-
import io.quarkiverse.langchain4j.gpullama3.runtime.tornadovm.TornadoVMInitializer;
86
import org.jboss.logging.Logger;
97

108
import dev.langchain4j.model.chat.ChatModel;
@@ -25,18 +23,15 @@ public class GPULlama3Recorder {
2523

2624
public GPULlama3Recorder(RuntimeValue<LangChain4jGPULlama3Config> runtimeConfig,
2725
RuntimeValue<LangChain4jGPULlama3FixedRuntimeConfig> fixedRuntimeConfig) {
28-
LOG.info("GPULlama3Recorder.constructor()");
2926
this.runtimeConfig = runtimeConfig;
3027
this.fixedRuntimeConfig = fixedRuntimeConfig;
3128
}
3229

3330
public Supplier<ChatModel> chatModel(String configName) {
3431
var config = correspondingConfig(configName);
3532
var fixedConfig = correspondingFixedConfig(configName);
36-
LOG.info("GPULlama3Recorder.chatModel()");
37-
if (config.enableIntegration()) {
3833

39-
boolean tornadoInitialized = initTornadoVMRuntime();
34+
if (config.enableIntegration()) {
4035

4136
var chatModelConfig = config.chatModel();
4237
String modelPath = fixedConfig.chatModel().modelPath();
@@ -45,14 +40,6 @@ public Supplier<ChatModel> chatModel(String configName) {
4540
try {
4641
LOG.info("Creating GPULlama3ChatModel for config: " + configName);
4742

48-
// Check if initialization worked
49-
if (!tornadoInitialized) {
50-
LOG.warn("TornadoVM is not properly initialized, using fallback model");
51-
return new FallbackChatModel(
52-
"TornadoVM runtime could not be initialized in Quarkus environment. " +
53-
"This is likely due to class loading or module system issues.");
54-
}
55-
5643
// Create the model normally
5744
var builder = GPULlama3ChatModel.builder()
5845
.modelPath(Paths.get(modelPath));
@@ -66,9 +53,7 @@ public Supplier<ChatModel> chatModel(String configName) {
6653
} catch (Exception e) {
6754
LOG.error("Error creating GPULlama3ChatModel", e);
6855
return new FallbackChatModel(
69-
"Error: " + e.getMessage() + "\n\n" +
70-
"Note: TornadoVM runtime was initialized but may not have backends available. " +
71-
"This may be addressed in a future phase.");
56+
"Error: " + e.getMessage() + "\n\n");
7257
}
7358
};
7459
} else {
@@ -88,50 +73,6 @@ private LangChain4jGPULlama3FixedRuntimeConfig.FixedRuntimeConfig correspondingF
8873
: fixedRuntimeConfig.getValue().namedConfig().get(configName);
8974
}
9075

91-
/**
92-
* Safely initializes TornadoVM.
93-
* This method is intended to be called early in the application lifecycle
94-
* to ensure TornadoVM is properly set up before it's needed.
95-
*
96-
* @return True if successfully initialized, or false otherwise
97-
*/
98-
private boolean initTornadoVMRuntime() {
99-
// Early module path setup
100-
TornadoVMInitializer.setModulePaths();
101-
102-
// Initialize TornadoVM early to detect issues
103-
Object tornadoRuntime = null;
104-
try {
105-
LOG.debug("Early initialization of TornadoVM runtime");
106-
107-
if (inDebugMode()) {
108-
// Print environment info only in debug mode
109-
TornadoVMInitializer.printEnvironmentInfo();
110-
}
111-
112-
// Ensure system properties are set
113-
TornadoVMInitializer.setSystemProperties();
114-
115-
// Configure library path
116-
TornadoVMInitializer.configureLibraryPath();
117-
118-
// Try to adjust class loaders and get runtime
119-
tornadoRuntime = TornadoVMInitializer.adjustClassLoaders();
120-
121-
// Check if initialization was successful
122-
if (TornadoVMInitializer.isTornadoVMInitialized()) {
123-
LOG.info("TornadoVM runtime successfully initialized!");
124-
} else {
125-
LOG.warn("TornadoVM runtime not initialized..");
126-
}
127-
128-
} catch (Exception e) {
129-
LOG.warn("TornadoVM early initialization failed", e);
130-
}
131-
132-
return tornadoRuntime != null;
133-
}
134-
13576
private boolean inDebugMode() {
13677
return LOG.isDebugEnabled();
13778
}

0 commit comments

Comments
 (0)