1
1
package com .example .core .model ;
2
2
3
3
import com .example .auxiliary .Timer ;
4
+ import com .example .core .model .GGUF .GGUFTensorInfo ;
4
5
import com .example .core .model .tensor .FloatTensor ;
5
6
import com .example .core .model .tensor .GGMLTensorEntry ;
6
7
import com .example .core .types .MetadataValueType ;
7
8
import com .example .core .types .Pair ;
8
9
10
+ import java .io .FileNotFoundException ;
9
11
import java .io .IOException ;
10
12
import java .lang .foreign .Arena ;
11
13
import java .lang .foreign .MemorySegment ;
12
14
import java .nio .ByteBuffer ;
13
15
import java .nio .ByteOrder ;
14
16
import java .nio .channels .FileChannel ;
15
17
import java .nio .charset .StandardCharsets ;
18
+ import java .nio .file .Files ;
16
19
import java .nio .file .Path ;
17
20
import java .util .HashMap ;
18
21
import java .util .List ;
@@ -36,10 +39,19 @@ public final class GGUF {
36
39
private long tensorDataOffset ;
37
40
38
41
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
39
49
try (FileChannel fileChannel = FileChannel .open (modelPath ); var ignored = Timer .log ("Parse " + modelPath )) {
40
50
GGUF gguf = new GGUF ();
41
51
gguf .loadModelImpl (fileChannel );
42
52
return gguf ;
53
+ } catch (Exception e ) {
54
+ throw new RuntimeException ("Unexpected error while loading GGUF model from " + modelPath , e );
43
55
}
44
56
}
45
57
0 commit comments