11package com .example .core .model ;
22
33import com .example .auxiliary .Timer ;
4+ import com .example .core .model .GGUF .GGUFTensorInfo ;
45import com .example .core .model .tensor .FloatTensor ;
56import com .example .core .model .tensor .GGMLTensorEntry ;
67import com .example .core .types .MetadataValueType ;
78import com .example .core .types .Pair ;
89
10+ import java .io .FileNotFoundException ;
911import java .io .IOException ;
1012import java .lang .foreign .Arena ;
1113import java .lang .foreign .MemorySegment ;
1214import java .nio .ByteBuffer ;
1315import java .nio .ByteOrder ;
1416import java .nio .channels .FileChannel ;
1517import java .nio .charset .StandardCharsets ;
18+ import java .nio .file .Files ;
1619import java .nio .file .Path ;
1720import java .util .HashMap ;
1821import java .util .List ;
@@ -36,10 +39,19 @@ public final class GGUF {
3639 private long tensorDataOffset ;
3740
3841 public static GGUF loadModel (Path modelPath ) throws IOException {
42+
43+ // file existence check
44+ if (!Files .exists (modelPath )) {
45+ throw new FileNotFoundException ("Model file not found: " + modelPath );
46+ }
47+
48+ // second check to make sure that nothing goes wrong during model loading
3949 try (FileChannel fileChannel = FileChannel .open (modelPath ); var ignored = Timer .log ("Parse " + modelPath )) {
4050 GGUF gguf = new GGUF ();
4151 gguf .loadModelImpl (fileChannel );
4252 return gguf ;
53+ } catch (Exception e ) {
54+ throw new RuntimeException ("Unexpected error while loading GGUF model from " + modelPath , e );
4355 }
4456 }
4557
0 commit comments