forked from kherud/java-llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathModelParameters.java
More file actions
1486 lines (1348 loc) · 45.4 KB
/
Copy pathModelParameters.java
File metadata and controls
1486 lines (1348 loc) · 45.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package net.ladenthin.llama;
import net.ladenthin.llama.args.*;
import net.ladenthin.llama.json.ParameterJsonSerializer;
/***
* Parameters used for initializing a {@link LlamaModel}.
*/
@SuppressWarnings("unused")
public final class ModelParameters extends CliParameters {
private final ParameterJsonSerializer serializer = new ParameterJsonSerializer();
private static final String ARG_FIT = "--fit";
static final String ARG_POOLING = "--pooling";
public static final String FIT_ON = "on";
public static final String FIT_OFF = "off";
/** Mirrors the llama.cpp default: {@code fit_params = true}. */
public static final String DEFAULT_FIT_VALUE = FIT_ON;
public ModelParameters() {
parameters.put(ARG_FIT, DEFAULT_FIT_VALUE);
}
static String fitValue(boolean fit) {
return fit ? FIT_ON : FIT_OFF;
}
/**
* Whether to adjust unset arguments to fit in device memory (default: {@value #DEFAULT_FIT_VALUE}).
*
* @param fit whether to adjust unset arguments to fit in device memory
* @return this builder
*/
public ModelParameters setFit(boolean fit) {
parameters.put(ARG_FIT, fitValue(fit));
return this;
}
/**
* Set the number of threads to use during generation (default: -1).
*
* @param nThreads the number of threads to use during generation
* @return this builder
*/
public ModelParameters setThreads(int nThreads) {
parameters.put("--threads", String.valueOf(nThreads));
return this;
}
/**
* Set the number of threads to use during batch and prompt processing (default: same as --threads).
*
* @param nThreads the number of threads for batch and prompt processing
* @return this builder
*/
public ModelParameters setThreadsBatch(int nThreads) {
parameters.put("--threads-batch", String.valueOf(nThreads));
return this;
}
/**
* Set the CPU affinity mask: arbitrarily long hex. Complements cpu-range (default: "").
*
* @param mask the CPU affinity mask as an arbitrarily long hex string
* @return this builder
*/
public ModelParameters setCpuMask(String mask) {
parameters.put("--cpu-mask", mask);
return this;
}
/**
* Set the range of CPUs for affinity. Complements --cpu-mask.
*
* @param range the range of CPUs for affinity
* @return this builder
*/
public ModelParameters setCpuRange(String range) {
parameters.put("--cpu-range", range);
return this;
}
/**
* Use strict CPU placement (default: 0).
*
* @param strictCpu 1 to enable strict CPU placement, 0 to disable
* @return this builder
*/
public ModelParameters setCpuStrict(int strictCpu) {
parameters.put("--cpu-strict", String.valueOf(strictCpu));
return this;
}
/**
* Set process/thread priority: 0-normal, 1-medium, 2-high, 3-realtime (default: 0).
*
* @param priority process/thread priority (0=normal, 1=medium, 2=high, 3=realtime)
* @return this builder
*/
public ModelParameters setPriority(int priority) {
if (priority < 0 || priority > 3) {
throw new IllegalArgumentException("Invalid value for priority");
}
parameters.put("--prio", String.valueOf(priority));
return this;
}
/**
* Set the polling level to wait for work (0 - no polling, default: 0).
*
* @param poll the polling level (0 = no polling)
* @return this builder
*/
public ModelParameters setPoll(int poll) {
parameters.put("--poll", String.valueOf(poll));
return this;
}
/**
* Set the CPU affinity mask for batch processing: arbitrarily long hex. Complements cpu-range-batch (default: same as --cpu-mask).
*
* @param mask the CPU affinity mask for batch processing
* @return this builder
*/
public ModelParameters setCpuMaskBatch(String mask) {
parameters.put("--cpu-mask-batch", mask);
return this;
}
/**
* Set the ranges of CPUs for batch affinity. Complements --cpu-mask-batch.
*
* @param range the ranges of CPUs for batch affinity
* @return this builder
*/
public ModelParameters setCpuRangeBatch(String range) {
parameters.put("--cpu-range-batch", range);
return this;
}
/**
* Use strict CPU placement for batch processing (default: same as --cpu-strict).
*
* @param strictCpuBatch 1 to enable strict CPU placement for batch processing, 0 to disable
* @return this builder
*/
public ModelParameters setCpuStrictBatch(int strictCpuBatch) {
parameters.put("--cpu-strict-batch", String.valueOf(strictCpuBatch));
return this;
}
/**
* Set process/thread priority for batch processing: 0-normal, 1-medium, 2-high, 3-realtime (default: 0).
*
* @param priorityBatch batch process/thread priority (0=normal, 1=medium, 2=high, 3=realtime)
* @return this builder
*/
public ModelParameters setPriorityBatch(int priorityBatch) {
if (priorityBatch < 0 || priorityBatch > 3) {
throw new IllegalArgumentException("Invalid value for priority batch");
}
parameters.put("--prio-batch", String.valueOf(priorityBatch));
return this;
}
/**
* Set the polling level for batch processing (default: same as --poll).
*
* @param pollBatch the polling level for batch processing
* @return this builder
*/
public ModelParameters setPollBatch(int pollBatch) {
parameters.put("--poll-batch", String.valueOf(pollBatch));
return this;
}
/**
* Set the size of the prompt context (default: 0, 0 = loaded from model).
*
* @param ctxSize the prompt context size in tokens (0 = loaded from model)
* @return this builder
*/
public ModelParameters setCtxSize(int ctxSize) {
parameters.put("--ctx-size", String.valueOf(ctxSize));
return this;
}
/**
* Set the number of tokens to predict (default: -1 = infinity, -2 = until context filled).
*
* @param nPredict the maximum number of tokens to predict (-1 = infinity, -2 = until context filled)
* @return this builder
*/
public ModelParameters setPredict(int nPredict) {
parameters.put("--predict", String.valueOf(nPredict));
return this;
}
/**
* Set the logical maximum batch size (default: 0).
*
* @param batchSize the logical maximum batch size
* @return this builder
*/
public ModelParameters setBatchSize(int batchSize) {
parameters.put("--batch-size", String.valueOf(batchSize));
return this;
}
/**
* Set the physical maximum batch size (default: 0).
*
* @param ubatchSize the physical maximum batch size
* @return this builder
*/
public ModelParameters setUbatchSize(int ubatchSize) {
parameters.put("--ubatch-size", String.valueOf(ubatchSize));
return this;
}
/**
* Set the number of tokens to keep from the initial prompt (default: -1 = all).
*
* @param keep the number of tokens to keep from the initial prompt (-1 = all)
* @return this builder
*/
public ModelParameters setKeep(int keep) {
parameters.put("--keep", String.valueOf(keep));
return this;
}
/**
* Disable context shift on infinite text generation (default: enabled).
*
* @return this builder
*/
public ModelParameters disableContextShift() {
return setFlag(ModelFlag.NO_CONTEXT_SHIFT);
}
/**
* Enable Flash Attention (default: disabled).
*
* @return this builder
*/
public ModelParameters enableFlashAttn() {
return setFlag(ModelFlag.FLASH_ATTN);
}
/**
* Disable internal libllama performance timings (default: false).
*
* @return this builder
*/
public ModelParameters disablePerf() {
return setFlag(ModelFlag.NO_PERF);
}
/**
* Process escape sequences (default: true).
*
* @return this builder
*/
public ModelParameters enableEscape() {
return setFlag(ModelFlag.ESCAPE);
}
/**
* Do not process escape sequences (default: false).
*
* @return this builder
*/
public ModelParameters disableEscape() {
return setFlag(ModelFlag.NO_ESCAPE);
}
/**
* Enable special tokens output (default: true).
*
* @return this builder
*/
public ModelParameters enableSpecial() {
return setFlag(ModelFlag.SPECIAL);
}
/**
* Skip warming up the model with an empty run (default: false).
*
* @return this builder
*/
public ModelParameters skipWarmup() {
return setFlag(ModelFlag.NO_WARMUP);
}
/**
* Use Suffix/Prefix/Middle pattern for infill (instead of Prefix/Suffix/Middle) as some models prefer this.
* (default: disabled)
*
* @return this builder
*/
public ModelParameters setSpmInfill() {
return setFlag(ModelFlag.SPM_INFILL);
}
/**
* Set samplers that will be used for generation in the order, separated by ';' (default: all).
*
* @param samplers the samplers to use, separated by semicolons
* @return this builder
*/
public ModelParameters setSamplers(Sampler... samplers) {
if (samplers.length > 0) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < samplers.length; i++) {
builder.append(samplers[i].getArgValue());
if (i < samplers.length - 1) {
builder.append(";");
}
}
parameters.put("--samplers", builder.toString());
}
return this;
}
/**
* Set RNG seed (default: -1, use random seed).
*
* @param seed the RNG seed (-1 = random)
* @return this builder
*/
public ModelParameters setSeed(long seed) {
parameters.put("--seed", String.valueOf(seed));
return this;
}
/**
* Ignore end of stream token and continue generating (implies --logit-bias EOS-inf).
*
* @return this builder
*/
public ModelParameters ignoreEos() {
return setFlag(ModelFlag.IGNORE_EOS);
}
/**
* Set temperature for sampling (default: 0.8).
*
* @param temp the sampling temperature
* @return this builder
*/
public ModelParameters setTemp(float temp) {
parameters.put("--temp", String.valueOf(temp));
return this;
}
/**
* Set top-k sampling (default: 40, 0 = disabled).
*
* @param topK the top-k value (0 = disabled)
* @return this builder
*/
public ModelParameters setTopK(int topK) {
parameters.put("--top-k", String.valueOf(topK));
return this;
}
/**
* Set top-p sampling (default: 0.95, 1.0 = disabled).
*
* @param topP the top-p value (1.0 = disabled)
* @return this builder
*/
public ModelParameters setTopP(float topP) {
parameters.put("--top-p", String.valueOf(topP));
return this;
}
/**
* Set min-p sampling (default: 0.05, 0.0 = disabled).
*
* @param minP the min-p value (0.0 = disabled)
* @return this builder
*/
public ModelParameters setMinP(float minP) {
parameters.put("--min-p", String.valueOf(minP));
return this;
}
/**
* Set xtc probability (default: 0.0, 0.0 = disabled).
*
* @param xtcProbability the XTC probability (0.0 = disabled)
* @return this builder
*/
public ModelParameters setXtcProbability(float xtcProbability) {
parameters.put("--xtc-probability", String.valueOf(xtcProbability));
return this;
}
/**
* Set xtc threshold (default: 0.1, 1.0 = disabled).
*
* @param xtcThreshold the XTC threshold (1.0 = disabled)
* @return this builder
*/
public ModelParameters setXtcThreshold(float xtcThreshold) {
parameters.put("--xtc-threshold", String.valueOf(xtcThreshold));
return this;
}
/**
* Set locally typical sampling parameter p (default: 1.0, 1.0 = disabled).
*
* @param typP the locally typical sampling parameter p (1.0 = disabled)
* @return this builder
*/
public ModelParameters setTypical(float typP) {
parameters.put("--typical", String.valueOf(typP));
return this;
}
/**
* Set last n tokens to consider for penalize (default: 64, 0 = disabled, -1 = ctx_size).
*
* @param repeatLastN the number of last tokens to consider for penalties (0 = disabled, -1 = ctx_size)
* @return this builder
*/
public ModelParameters setRepeatLastN(int repeatLastN) {
if (repeatLastN < -1) {
throw new RuntimeException("Invalid repeat-last-n value");
}
parameters.put("--repeat-last-n", String.valueOf(repeatLastN));
return this;
}
/**
* Set penalize repeat sequence of tokens (default: 1.0, 1.0 = disabled).
*
* @param repeatPenalty the repeat penalty (1.0 = disabled)
* @return this builder
*/
public ModelParameters setRepeatPenalty(float repeatPenalty) {
parameters.put("--repeat-penalty", String.valueOf(repeatPenalty));
return this;
}
/**
* Set repeat alpha presence penalty (default: 0.0, 0.0 = disabled).
*
* @param presencePenalty the alpha presence penalty (0.0 = disabled)
* @return this builder
*/
public ModelParameters setPresencePenalty(float presencePenalty) {
parameters.put("--presence-penalty", String.valueOf(presencePenalty));
return this;
}
/**
* Set repeat alpha frequency penalty (default: 0.0, 0.0 = disabled).
*
* @param frequencyPenalty the alpha frequency penalty (0.0 = disabled)
* @return this builder
*/
public ModelParameters setFrequencyPenalty(float frequencyPenalty) {
parameters.put("--frequency-penalty", String.valueOf(frequencyPenalty));
return this;
}
/**
* Set DRY sampling multiplier (default: 0.0, 0.0 = disabled).
*
* @param dryMultiplier the DRY sampling multiplier (0.0 = disabled)
* @return this builder
*/
public ModelParameters setDryMultiplier(float dryMultiplier) {
parameters.put("--dry-multiplier", String.valueOf(dryMultiplier));
return this;
}
/**
* Set DRY sampling base value (default: 1.75).
*
* @param dryBase the DRY sampling base value
* @return this builder
*/
public ModelParameters setDryBase(float dryBase) {
parameters.put("--dry-base", String.valueOf(dryBase));
return this;
}
/**
* Set allowed length for DRY sampling (default: 2).
*
* @param dryAllowedLength the allowed length for DRY sampling
* @return this builder
*/
public ModelParameters setDryAllowedLength(int dryAllowedLength) {
parameters.put("--dry-allowed-length", String.valueOf(dryAllowedLength));
return this;
}
/**
* Set DRY penalty for the last n tokens (default: -1, 0 = disable, -1 = context size).
*
* @param dryPenaltyLastN the DRY penalty window (-1 = context size, 0 = disabled)
* @return this builder
*/
public ModelParameters setDryPenaltyLastN(int dryPenaltyLastN) {
if (dryPenaltyLastN < -1) {
throw new RuntimeException("Invalid dry-penalty-last-n value");
}
parameters.put("--dry-penalty-last-n", String.valueOf(dryPenaltyLastN));
return this;
}
/**
* Add sequence breaker for DRY sampling, clearing out default breakers (default: none).
*
* @param drySequenceBreaker the sequence breaker string for DRY sampling
* @return this builder
*/
public ModelParameters setDrySequenceBreaker(String drySequenceBreaker) {
parameters.put("--dry-sequence-breaker", drySequenceBreaker);
return this;
}
/**
* Set dynamic temperature range (default: 0.0, 0.0 = disabled).
*
* @param dynatempRange the dynamic temperature range (0.0 = disabled)
* @return this builder
*/
public ModelParameters setDynatempRange(float dynatempRange) {
parameters.put("--dynatemp-range", String.valueOf(dynatempRange));
return this;
}
/**
* Set dynamic temperature exponent (default: 1.0).
*
* @param dynatempExponent the dynamic temperature exponent
* @return this builder
*/
public ModelParameters setDynatempExponent(float dynatempExponent) {
parameters.put("--dynatemp-exp", String.valueOf(dynatempExponent));
return this;
}
/**
* Use Mirostat sampling (default: PLACEHOLDER, 0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0).
*
* @param mirostat the Mirostat sampling mode
* @return this builder
*/
public ModelParameters setMirostat(MiroStat mirostat) {
parameters.put("--mirostat", mirostat.getArgValue());
return this;
}
/**
* Set Mirostat learning rate, parameter eta (default: 0.1).
*
* @param mirostatLR the Mirostat learning rate (eta)
* @return this builder
*/
public ModelParameters setMirostatLR(float mirostatLR) {
parameters.put("--mirostat-lr", String.valueOf(mirostatLR));
return this;
}
/**
* Set Mirostat target entropy, parameter tau (default: 5.0).
*
* @param mirostatEnt the Mirostat target entropy (tau)
* @return this builder
*/
public ModelParameters setMirostatEnt(float mirostatEnt) {
parameters.put("--mirostat-ent", String.valueOf(mirostatEnt));
return this;
}
/**
* Modify the likelihood of token appearing in the completion.
*
* @param tokenIdAndBias token id and bias value as a formatted string
* @return this builder
*/
public ModelParameters setLogitBias(String tokenIdAndBias) {
parameters.put("--logit-bias", tokenIdAndBias);
return this;
}
/**
* Set BNF-like grammar to constrain generations (default: empty).
*
* @param grammar the BNF-like grammar string
* @return this builder
*/
public ModelParameters setGrammar(String grammar) {
parameters.put("--grammar", grammar);
return this;
}
/**
* Specify the file to read grammar from.
*
* @param fileName the path to a file containing the grammar
* @return this builder
*/
public ModelParameters setGrammarFile(String fileName) {
parameters.put("--grammar-file", fileName);
return this;
}
/**
* Specify the JSON schema to constrain generations (default: empty).
*
* @param schema the JSON schema string
* @return this builder
*/
public ModelParameters setJsonSchema(String schema) {
parameters.put("--json-schema", schema);
return this;
}
/**
* Set pooling type for embeddings (default: model default if unspecified).
* When {@link net.ladenthin.llama.args.PoolingType#UNSPECIFIED} is passed, the parameter is not forwarded
* to the native layer, leaving the model to use its built-in default pooling strategy.
*
* @param type the pooling type for embeddings
* @return this builder
*/
public ModelParameters setPoolingType(PoolingType type) {
if (type != PoolingType.UNSPECIFIED) {
// Don't set if unspecified, as it will use the model's default pooling type
parameters.put(ARG_POOLING, type.getArgValue());
}
return this;
}
/**
* Set RoPE frequency scaling method (default: linear unless specified by the model).
*
* @param type the RoPE frequency scaling method
* @return this builder
*/
public ModelParameters setRopeScaling(RopeScalingType type) {
parameters.put("--rope-scaling", type.getArgValue());
return this;
}
/**
* Set RoPE context scaling factor, expands context by a factor of N.
*
* @param ropeScale the RoPE context scaling factor
* @return this builder
*/
public ModelParameters setRopeScale(float ropeScale) {
parameters.put("--rope-scale", String.valueOf(ropeScale));
return this;
}
/**
* Set RoPE base frequency, used by NTK-aware scaling (default: loaded from model).
*
* @param ropeFreqBase the RoPE base frequency
* @return this builder
*/
public ModelParameters setRopeFreqBase(float ropeFreqBase) {
parameters.put("--rope-freq-base", String.valueOf(ropeFreqBase));
return this;
}
/**
* Set RoPE frequency scaling factor, expands context by a factor of 1/N.
*
* @param ropeFreqScale the RoPE frequency scaling factor
* @return this builder
*/
public ModelParameters setRopeFreqScale(float ropeFreqScale) {
parameters.put("--rope-freq-scale", String.valueOf(ropeFreqScale));
return this;
}
/**
* Set YaRN: original context size of model (default: model training context size).
*
* @param yarnOrigCtx the original context size of the model
* @return this builder
*/
public ModelParameters setYarnOrigCtx(int yarnOrigCtx) {
parameters.put("--yarn-orig-ctx", String.valueOf(yarnOrigCtx));
return this;
}
/**
* Set YaRN: extrapolation mix factor (default: 0.0 = full interpolation).
*
* @param yarnExtFactor the YaRN extrapolation mix factor (0.0 = full interpolation)
* @return this builder
*/
public ModelParameters setYarnExtFactor(float yarnExtFactor) {
parameters.put("--yarn-ext-factor", String.valueOf(yarnExtFactor));
return this;
}
/**
* Set YaRN: scale sqrt(t) or attention magnitude (default: 1.0).
*
* @param yarnAttnFactor the YaRN attention scale factor
* @return this builder
*/
public ModelParameters setYarnAttnFactor(float yarnAttnFactor) {
parameters.put("--yarn-attn-factor", String.valueOf(yarnAttnFactor));
return this;
}
/**
* Set YaRN: high correction dim or alpha (default: 1.0).
*
* @param yarnBetaSlow the YaRN high correction dimension (alpha)
* @return this builder
*/
public ModelParameters setYarnBetaSlow(float yarnBetaSlow) {
parameters.put("--yarn-beta-slow", String.valueOf(yarnBetaSlow));
return this;
}
/**
* Set YaRN: low correction dim or beta (default: 32.0).
*
* @param yarnBetaFast the YaRN low correction dimension (beta)
* @return this builder
*/
public ModelParameters setYarnBetaFast(float yarnBetaFast) {
parameters.put("--yarn-beta-fast", String.valueOf(yarnBetaFast));
return this;
}
/**
* Set group-attention factor (default: 1).
*
* @param grpAttnN the group-attention factor
* @return this builder
*/
public ModelParameters setGrpAttnN(int grpAttnN) {
parameters.put("--grp-attn-n", String.valueOf(grpAttnN));
return this;
}
/**
* Set group-attention width (default: 512).
*
* @param grpAttnW the group-attention width
* @return this builder
*/
public ModelParameters setGrpAttnW(int grpAttnW) {
parameters.put("--grp-attn-w", String.valueOf(grpAttnW));
return this;
}
/**
* Enable verbose printing of the KV cache.
*
* @return this builder
*/
public ModelParameters enableDumpKvCache() {
return setFlag(ModelFlag.DUMP_KV_CACHE);
}
/**
* Disable KV offload.
*
* @return this builder
*/
public ModelParameters disableKvOffload() {
return setFlag(ModelFlag.NO_KV_OFFLOAD);
}
/**
* Set KV cache data type for K (allowed values: F16).
*
* @param type the KV cache data type for K
* @return this builder
*/
public ModelParameters setCacheTypeK(CacheType type) {
parameters.put("--cache-type-k", type.getArgValue());
return this;
}
/**
* Set KV cache data type for V (allowed values: F16).
*
* @param type the KV cache data type for V
* @return this builder
*/
public ModelParameters setCacheTypeV(CacheType type) {
parameters.put("--cache-type-v", type.getArgValue());
return this;
}
/**
* Set KV cache defragmentation threshold (default: 0.1, < 0 - disabled).
*
* @param defragThold the KV cache defragmentation threshold (negative = disabled)
* @return this builder
*/
public ModelParameters setDefragThold(float defragThold) {
parameters.put("--defrag-thold", String.valueOf(defragThold));
return this;
}
/**
* Set the number of parallel sequences to decode (default: 1).
*
* @param nParallel the number of parallel sequences to decode
* @return this builder
*/
public ModelParameters setParallel(int nParallel) {
parameters.put("--parallel", String.valueOf(nParallel));
return this;
}
/**
* Enable continuous batching (a.k.a dynamic batching) (default: disabled).
*
* @return this builder
*/
public ModelParameters enableContBatching() {
return setFlag(ModelFlag.CONT_BATCHING);
}
/**
* Disable continuous batching.
*
* @return this builder
*/
public ModelParameters disableContBatching() {
return setFlag(ModelFlag.NO_CONT_BATCHING);
}
/**
* Force system to keep model in RAM rather than swapping or compressing.
*
* @return this builder
*/
public ModelParameters enableMlock() {
return setFlag(ModelFlag.MLOCK);
}
/**
* Do not memory-map model (slower load but may reduce pageouts if not using mlock).
*
* @return this builder
*/
public ModelParameters disableMmap() {
return setFlag(ModelFlag.NO_MMAP);
}
/**
* Set NUMA optimization type for system.
*
* @param numaStrategy the NUMA optimization strategy
* @return this builder
*/
public ModelParameters setNuma(NumaStrategy numaStrategy) {
parameters.put("--numa", numaStrategy.getArgValue());
return this;
}
/**
* Set comma-separated list of devices to use for offloading <dev1,dev2,..> (none = don't offload).
*
* @param devices comma-separated list of device names to use for offloading
* @return this builder
*/
public ModelParameters setDevices(String devices) {
parameters.put("--device", devices);
return this;
}
/**
* Set the number of layers to store in VRAM.
*
* @param gpuLayers the number of model layers to store in VRAM
* @return this builder
*/
public ModelParameters setGpuLayers(int gpuLayers) {
parameters.put("--gpu-layers", String.valueOf(gpuLayers));
return this;
}
/**
* Set how to split the model across multiple GPUs (none, layer, row).
*
* @param splitMode how to split the model across multiple GPUs
* @return this builder
*/
public ModelParameters setSplitMode(GpuSplitMode splitMode) {
parameters.put("--split-mode", splitMode.getArgValue());
return this;
}
/**
* Set fraction of the model to offload to each GPU, comma-separated list of proportions N0,N1,N2,....
*
* @param tensorSplit comma-separated proportions for offloading to each GPU
* @return this builder
*/
public ModelParameters setTensorSplit(String tensorSplit) {
parameters.put("--tensor-split", tensorSplit);
return this;
}
/**
* Set the GPU to use for the model (with split-mode = none), or for intermediate results and KV (with split-mode = row).
*
* @param mainGpu the index of the primary GPU
* @return this builder
*/
public ModelParameters setMainGpu(int mainGpu) {
parameters.put("--main-gpu", String.valueOf(mainGpu));
return this;
}
/**
* Enable checking model tensor data for invalid values.
*
* @return this builder
*/
public ModelParameters enableCheckTensors() {
return setFlag(ModelFlag.CHECK_TENSORS);
}
/**
* Override model metadata by key. This option can be specified multiple times.
*
* @param keyValue the key-value metadata override string
* @return this builder
*/
public ModelParameters setOverrideKv(String keyValue) {
parameters.put("--override-kv", keyValue);
return this;
}
/**
* Add a LoRA adapter (can be repeated to use multiple adapters).
*
* @param fname the file path of the LoRA adapter
* @return this builder
*/
public ModelParameters addLoraAdapter(String fname) {
parameters.put("--lora", fname);
return this;
}
/**
* Add a LoRA adapter with user-defined scaling (can be repeated to use multiple adapters).
*
* @param fname the file path of the LoRA adapter
* @param scale the user-defined scaling factor
* @return this builder
*/
public ModelParameters addLoraScaledAdapter(String fname, float scale) {
parameters.put("--lora-scaled", fname + "," + scale);
return this;
}
/**
* Add a control vector (this argument can be repeated to add multiple control vectors).
*
* @param fname the file path of the control vector
* @return this builder
*/
public ModelParameters addControlVector(String fname) {
parameters.put("--control-vector", fname);
return this;
}
/**
* Add a control vector with user-defined scaling (can be repeated to add multiple scaled control vectors).
*
* @param fname the file path of the control vector
* @param scale the user-defined scaling factor
* @return this builder
*/
public ModelParameters addControlVectorScaled(String fname, float scale) {
parameters.put("--control-vector-scaled", fname + "," + scale);
return this;
}
/**
* Set the layer range to apply the control vector(s) to (start and end inclusive).
*
* @param start the first layer to apply the control vector to (inclusive)
* @param end the last layer to apply the control vector to (inclusive)
* @return this builder
*/