Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion external/tornadovm
12 changes: 12 additions & 0 deletions src/main/java/com/example/core/model/GGUF.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.example.core.model;

import com.example.auxiliary.Timer;
import com.example.core.model.GGUF.GGUFTensorInfo;
import com.example.core.model.tensor.FloatTensor;
import com.example.core.model.tensor.GGMLTensorEntry;
import com.example.core.types.MetadataValueType;
import com.example.core.types.Pair;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
Expand All @@ -36,10 +39,19 @@ public final class GGUF {
private long tensorDataOffset;

public static GGUF loadModel(Path modelPath) throws IOException {

// file existence check
if (!Files.exists(modelPath)) {
throw new FileNotFoundException("Model file not found: " + modelPath);
}

// second check to make sure that nothing goes wrong during model loading
try (FileChannel fileChannel = FileChannel.open(modelPath); var ignored = Timer.log("Parse " + modelPath)) {
GGUF gguf = new GGUF();
gguf.loadModelImpl(fileChannel);
return gguf;
} catch (Exception e) {
throw new RuntimeException("Unexpected error while loading GGUF model from " + modelPath, e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/loader/weights/ModelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static ModelType detectModelType(Map<String, Object> metadata) {

public static Model loadModel(Path ggufPath, int contextLength, boolean loadWeights) throws IOException {
// initial load of metadata from gguf file
GGUF gguf = GGUF.loadModel(ggufPath);
GGUF gguf = GGUF.loadModel(ggufPath);
FileChannel fileChannel = FileChannel.open(ggufPath, StandardOpenOption.READ);
// detect model type
ModelType modelType = detectModelType(gguf.getMetadata());
Expand Down