Skip to content

Commit 9f4f30c

Browse files
committed
added try catch block to loadModel in GGUF class
1 parent 460be99 commit 9f4f30c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/main/java/com/example/core/model/GGUF.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ public static GGUF loadModel(Path modelPath) throws IOException {
4040
GGUF gguf = new GGUF();
4141
gguf.loadModelImpl(fileChannel);
4242
return gguf;
43+
} catch {
44+
45+
IOException e -> {
46+
throw new IOException("Failed to load GGUF model from " + modelPath, e);
47+
}
48+
49+
catch (Exception e) {
50+
throw new RuntimeException("Unexpected error while loading GGUF model from " + modelPath, e);
51+
}
52+
4353
}
4454
}
4555

src/main/java/com/example/loader/weights/ModelLoader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ private static ModelType detectModelType(Map<String, Object> metadata) {
6767

6868
public static Model loadModel(Path ggufPath, int contextLength, boolean loadWeights) throws IOException {
6969
// initial load of metadata from gguf file
70-
GGUF gguf = GGUF.loadModel(ggufPath);
70+
// will throw an IOException if the file does not exist, RuntimeException if there is another problem with loading the model
71+
GGUF gguf = GGUF.loadModel(ggufPath);
7172
FileChannel fileChannel = FileChannel.open(ggufPath, StandardOpenOption.READ);
7273
// detect model type
7374
ModelType modelType = detectModelType(gguf.getMetadata());

0 commit comments

Comments
 (0)