Skip to content

Commit 1267d73

Browse files
Merge two ModelLoader.loadModel methods and drop loadWeights parameter for simplicity
1 parent 2e1f34c commit 1267d73

8 files changed

Lines changed: 28 additions & 30 deletions

File tree

src/main/java/org/beehive/gpullama3/model/ModelType.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,55 +24,55 @@
2424
public enum ModelType {
2525
LLAMA_3 {
2626
@Override
27-
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
28-
return new LlamaModelLoader(fileChannel, gguf, contextLength, loadWeights, useTornadovm).loadModel();
27+
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
28+
return new LlamaModelLoader(fileChannel, gguf, contextLength, useTornadovm).loadModel();
2929
}
3030
},
3131

3232
MISTRAL {
3333
@Override
34-
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
35-
return new MistralModelLoader(fileChannel, gguf, contextLength, loadWeights, useTornadovm).loadModel();
34+
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
35+
return new MistralModelLoader(fileChannel, gguf, contextLength, useTornadovm).loadModel();
3636
}
3737
},
3838

3939
QWEN_2 {
4040
@Override
41-
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
42-
return new Qwen2ModelLoader(fileChannel, gguf, contextLength, loadWeights, useTornadovm).loadModel();
41+
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
42+
return new Qwen2ModelLoader(fileChannel, gguf, contextLength, useTornadovm).loadModel();
4343
}
4444
},
4545

4646
QWEN_3 {
4747
@Override
48-
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
49-
return new Qwen3ModelLoader(fileChannel, gguf, contextLength, loadWeights, useTornadovm).loadModel();
48+
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
49+
return new Qwen3ModelLoader(fileChannel, gguf, contextLength, useTornadovm).loadModel();
5050
}
5151
},
5252

5353
DEEPSEEK_R1_DISTILL_QWEN {
5454
@Override
55-
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
56-
return new Qwen2ModelLoader(fileChannel, gguf, contextLength, loadWeights, useTornadovm).loadModel();
55+
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
56+
return new Qwen2ModelLoader(fileChannel, gguf, contextLength, useTornadovm).loadModel();
5757
}
5858
},
5959

6060
PHI_3 {
6161
@Override
62-
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
63-
return new Phi3ModelLoader(fileChannel, gguf, contextLength, loadWeights, useTornadovm).loadModel();
62+
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
63+
return new Phi3ModelLoader(fileChannel, gguf, contextLength, useTornadovm).loadModel();
6464
}
6565
},
6666

6767
UNKNOWN {
6868
@Override
69-
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
69+
public Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
7070
throw new UnsupportedOperationException("Cannot load unknown model type");
7171
}
7272
};
7373

7474
// Abstract method that each enum constant must implement
75-
public abstract Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm);
75+
public abstract Model loadModel(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm);
7676

7777
public boolean isDeepSeekR1() {
7878
return this == DEEPSEEK_R1_DISTILL_QWEN;

src/main/java/org/beehive/gpullama3/model/loader/AbstractModelLoader.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ public abstract class AbstractModelLoader<M extends Model, C extends Configurati
2626
protected final FileChannel fileChannel;
2727
protected final GGUF gguf;
2828
protected final int contextLength;
29-
protected final boolean loadWeights;
3029
protected final boolean useTornadovm;
3130

3231
protected Vocabulary vocabulary;
3332

34-
protected AbstractModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
33+
protected AbstractModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
3534
this.fileChannel = fileChannel;
3635
this.gguf = gguf;
3736
this.contextLength = contextLength;
38-
this.loadWeights = loadWeights;
3937
this.useTornadovm = useTornadovm;
4038
}
4139

src/main/java/org/beehive/gpullama3/model/loader/LlamaModelLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
public class LlamaModelLoader extends AbstractModelLoader<Llama, LlamaConfiguration> {
3030

31-
public LlamaModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
32-
super(fileChannel, gguf, contextLength, loadWeights, useTornadovm);
31+
public LlamaModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
32+
super(fileChannel, gguf, contextLength, useTornadovm);
3333
}
3434

3535
@Override

src/main/java/org/beehive/gpullama3/model/loader/MistralModelLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626

2727
public class MistralModelLoader extends AbstractModelLoader<Mistral, MistralConfiguration> {
2828

29-
public MistralModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
30-
super(fileChannel, gguf, contextLength, loadWeights, useTornadovm);
29+
public MistralModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
30+
super(fileChannel, gguf, contextLength, useTornadovm);
3131
}
3232

3333
@Override

src/main/java/org/beehive/gpullama3/model/loader/ModelLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ private static ModelType detectModelType(Map<String, Object> metadata) {
7979
* if AOT loading is enabled but the preloaded model is unavailable
8080
*/
8181
public static Model loadModel(Options options) throws IOException {
82-
return ModelLoader.loadModel(options.modelPath(), options.maxTokens(), true, options.useTornadovm());
83-
}
82+
Path ggufPath = options.modelPath();
83+
int contextLength = options.maxTokens();
84+
boolean useTornadovm = options.useTornadovm();
8485

85-
public static Model loadModel(Path ggufPath, int contextLength, boolean loadWeights, boolean useTornadovm) throws IOException {
8686
// initial load of metadata from gguf file
8787
GGUF gguf = GGUF.loadGGUFMetadata(ggufPath);
8888
// detect model type

src/main/java/org/beehive/gpullama3/model/loader/Phi3ModelLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
public class Phi3ModelLoader extends AbstractModelLoader<Phi3, Phi3Configuration> {
2828
private int modelContextLength;
2929

30-
public Phi3ModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
31-
super(fileChannel, gguf, contextLength, loadWeights, useTornadovm);
30+
public Phi3ModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
31+
super(fileChannel, gguf, contextLength, useTornadovm);
3232
}
3333

3434
@Override

src/main/java/org/beehive/gpullama3/model/loader/Qwen2ModelLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
public class Qwen2ModelLoader extends AbstractModelLoader<Qwen2, Qwen2Configuration> {
2929

30-
public Qwen2ModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
31-
super(fileChannel, gguf, contextLength, loadWeights, useTornadovm);
30+
public Qwen2ModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
31+
super(fileChannel, gguf, contextLength, useTornadovm);
3232
}
3333

3434
@Override

src/main/java/org/beehive/gpullama3/model/loader/Qwen3ModelLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
public class Qwen3ModelLoader extends AbstractModelLoader<Qwen3, Qwen3Configuration> {
3030

31-
public Qwen3ModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean loadWeights, boolean useTornadovm) {
32-
super(fileChannel, gguf, contextLength, loadWeights, useTornadovm);
31+
public Qwen3ModelLoader(FileChannel fileChannel, GGUF gguf, int contextLength, boolean useTornadovm) {
32+
super(fileChannel, gguf, contextLength, useTornadovm);
3333
}
3434

3535
@Override

0 commit comments

Comments
 (0)