spark-nlp 4.2.6__py2.py3-none-any.whl → 6.2.1__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. com/johnsnowlabs/ml/__init__.py +0 -0
  2. com/johnsnowlabs/ml/ai/__init__.py +10 -0
  3. spark_nlp-6.2.1.dist-info/METADATA +362 -0
  4. spark_nlp-6.2.1.dist-info/RECORD +292 -0
  5. {spark_nlp-4.2.6.dist-info → spark_nlp-6.2.1.dist-info}/WHEEL +1 -1
  6. sparknlp/__init__.py +81 -28
  7. sparknlp/annotation.py +3 -2
  8. sparknlp/annotator/__init__.py +6 -0
  9. sparknlp/annotator/audio/__init__.py +2 -0
  10. sparknlp/annotator/audio/hubert_for_ctc.py +188 -0
  11. sparknlp/annotator/audio/wav2vec2_for_ctc.py +14 -14
  12. sparknlp/annotator/audio/whisper_for_ctc.py +251 -0
  13. sparknlp/{base → annotator}/chunk2_doc.py +4 -7
  14. sparknlp/annotator/chunker.py +1 -2
  15. sparknlp/annotator/classifier_dl/__init__.py +17 -0
  16. sparknlp/annotator/classifier_dl/albert_for_multiple_choice.py +161 -0
  17. sparknlp/annotator/classifier_dl/albert_for_question_answering.py +3 -15
  18. sparknlp/annotator/classifier_dl/albert_for_sequence_classification.py +4 -18
  19. sparknlp/annotator/classifier_dl/albert_for_token_classification.py +3 -17
  20. sparknlp/annotator/classifier_dl/albert_for_zero_shot_classification.py +211 -0
  21. sparknlp/annotator/classifier_dl/bart_for_zero_shot_classification.py +225 -0
  22. sparknlp/annotator/classifier_dl/bert_for_multiple_choice.py +161 -0
  23. sparknlp/annotator/classifier_dl/bert_for_question_answering.py +6 -20
  24. sparknlp/annotator/classifier_dl/bert_for_sequence_classification.py +3 -17
  25. sparknlp/annotator/classifier_dl/bert_for_token_classification.py +3 -17
  26. sparknlp/annotator/classifier_dl/bert_for_zero_shot_classification.py +212 -0
  27. sparknlp/annotator/classifier_dl/camembert_for_question_answering.py +168 -0
  28. sparknlp/annotator/classifier_dl/camembert_for_sequence_classification.py +5 -19
  29. sparknlp/annotator/classifier_dl/camembert_for_token_classification.py +5 -19
  30. sparknlp/annotator/classifier_dl/camembert_for_zero_shot_classification.py +202 -0
  31. sparknlp/annotator/classifier_dl/classifier_dl.py +4 -4
  32. sparknlp/annotator/classifier_dl/deberta_for_question_answering.py +3 -17
  33. sparknlp/annotator/classifier_dl/deberta_for_sequence_classification.py +4 -19
  34. sparknlp/annotator/classifier_dl/deberta_for_token_classification.py +5 -21
  35. sparknlp/annotator/classifier_dl/deberta_for_zero_shot_classification.py +193 -0
  36. sparknlp/annotator/classifier_dl/distil_bert_for_question_answering.py +3 -17
  37. sparknlp/annotator/classifier_dl/distil_bert_for_sequence_classification.py +4 -18
  38. sparknlp/annotator/classifier_dl/distil_bert_for_token_classification.py +3 -17
  39. sparknlp/annotator/classifier_dl/distil_bert_for_zero_shot_classification.py +211 -0
  40. sparknlp/annotator/classifier_dl/distilbert_for_multiple_choice.py +161 -0
  41. sparknlp/annotator/classifier_dl/longformer_for_question_answering.py +3 -17
  42. sparknlp/annotator/classifier_dl/longformer_for_sequence_classification.py +4 -18
  43. sparknlp/annotator/classifier_dl/longformer_for_token_classification.py +3 -17
  44. sparknlp/annotator/classifier_dl/mpnet_for_question_answering.py +148 -0
  45. sparknlp/annotator/classifier_dl/mpnet_for_sequence_classification.py +188 -0
  46. sparknlp/annotator/classifier_dl/mpnet_for_token_classification.py +173 -0
  47. sparknlp/annotator/classifier_dl/multi_classifier_dl.py +3 -3
  48. sparknlp/annotator/classifier_dl/roberta_for_multiple_choice.py +161 -0
  49. sparknlp/annotator/classifier_dl/roberta_for_question_answering.py +3 -17
  50. sparknlp/annotator/classifier_dl/roberta_for_sequence_classification.py +4 -18
  51. sparknlp/annotator/classifier_dl/roberta_for_token_classification.py +1 -1
  52. sparknlp/annotator/classifier_dl/roberta_for_zero_shot_classification.py +225 -0
  53. sparknlp/annotator/classifier_dl/sentiment_dl.py +4 -4
  54. sparknlp/annotator/classifier_dl/tapas_for_question_answering.py +2 -2
  55. sparknlp/annotator/classifier_dl/xlm_roberta_for_multiple_choice.py +149 -0
  56. sparknlp/annotator/classifier_dl/xlm_roberta_for_question_answering.py +3 -17
  57. sparknlp/annotator/classifier_dl/xlm_roberta_for_sequence_classification.py +4 -18
  58. sparknlp/annotator/classifier_dl/xlm_roberta_for_token_classification.py +6 -20
  59. sparknlp/annotator/classifier_dl/xlm_roberta_for_zero_shot_classification.py +225 -0
  60. sparknlp/annotator/classifier_dl/xlnet_for_sequence_classification.py +4 -18
  61. sparknlp/annotator/classifier_dl/xlnet_for_token_classification.py +3 -17
  62. sparknlp/annotator/cleaners/__init__.py +15 -0
  63. sparknlp/annotator/cleaners/cleaner.py +202 -0
  64. sparknlp/annotator/cleaners/extractor.py +191 -0
  65. sparknlp/annotator/coref/spanbert_coref.py +4 -18
  66. sparknlp/annotator/cv/__init__.py +15 -0
  67. sparknlp/annotator/cv/blip_for_question_answering.py +172 -0
  68. sparknlp/annotator/cv/clip_for_zero_shot_classification.py +193 -0
  69. sparknlp/annotator/cv/convnext_for_image_classification.py +269 -0
  70. sparknlp/annotator/cv/florence2_transformer.py +180 -0
  71. sparknlp/annotator/cv/gemma3_for_multimodal.py +346 -0
  72. sparknlp/annotator/cv/internvl_for_multimodal.py +280 -0
  73. sparknlp/annotator/cv/janus_for_multimodal.py +351 -0
  74. sparknlp/annotator/cv/llava_for_multimodal.py +328 -0
  75. sparknlp/annotator/cv/mllama_for_multimodal.py +340 -0
  76. sparknlp/annotator/cv/paligemma_for_multimodal.py +308 -0
  77. sparknlp/annotator/cv/phi3_vision_for_multimodal.py +328 -0
  78. sparknlp/annotator/cv/qwen2vl_transformer.py +332 -0
  79. sparknlp/annotator/cv/smolvlm_transformer.py +426 -0
  80. sparknlp/annotator/cv/swin_for_image_classification.py +242 -0
  81. sparknlp/annotator/cv/vision_encoder_decoder_for_image_captioning.py +240 -0
  82. sparknlp/annotator/cv/vit_for_image_classification.py +36 -4
  83. sparknlp/annotator/dataframe_optimizer.py +216 -0
  84. sparknlp/annotator/date2_chunk.py +88 -0
  85. sparknlp/annotator/dependency/dependency_parser.py +2 -3
  86. sparknlp/annotator/dependency/typed_dependency_parser.py +3 -4
  87. sparknlp/annotator/document_character_text_splitter.py +228 -0
  88. sparknlp/annotator/document_normalizer.py +37 -1
  89. sparknlp/annotator/document_token_splitter.py +175 -0
  90. sparknlp/annotator/document_token_splitter_test.py +85 -0
  91. sparknlp/annotator/embeddings/__init__.py +11 -0
  92. sparknlp/annotator/embeddings/albert_embeddings.py +4 -18
  93. sparknlp/annotator/embeddings/auto_gguf_embeddings.py +539 -0
  94. sparknlp/annotator/embeddings/bert_embeddings.py +9 -22
  95. sparknlp/annotator/embeddings/bert_sentence_embeddings.py +12 -24
  96. sparknlp/annotator/embeddings/bge_embeddings.py +199 -0
  97. sparknlp/annotator/embeddings/camembert_embeddings.py +4 -20
  98. sparknlp/annotator/embeddings/chunk_embeddings.py +1 -2
  99. sparknlp/annotator/embeddings/deberta_embeddings.py +2 -16
  100. sparknlp/annotator/embeddings/distil_bert_embeddings.py +5 -19
  101. sparknlp/annotator/embeddings/doc2vec.py +7 -1
  102. sparknlp/annotator/embeddings/e5_embeddings.py +195 -0
  103. sparknlp/annotator/embeddings/e5v_embeddings.py +138 -0
  104. sparknlp/annotator/embeddings/elmo_embeddings.py +2 -2
  105. sparknlp/annotator/embeddings/instructor_embeddings.py +204 -0
  106. sparknlp/annotator/embeddings/longformer_embeddings.py +3 -17
  107. sparknlp/annotator/embeddings/minilm_embeddings.py +189 -0
  108. sparknlp/annotator/embeddings/mpnet_embeddings.py +192 -0
  109. sparknlp/annotator/embeddings/mxbai_embeddings.py +184 -0
  110. sparknlp/annotator/embeddings/nomic_embeddings.py +181 -0
  111. sparknlp/annotator/embeddings/roberta_embeddings.py +9 -21
  112. sparknlp/annotator/embeddings/roberta_sentence_embeddings.py +7 -21
  113. sparknlp/annotator/embeddings/sentence_embeddings.py +2 -3
  114. sparknlp/annotator/embeddings/snowflake_embeddings.py +202 -0
  115. sparknlp/annotator/embeddings/uae_embeddings.py +211 -0
  116. sparknlp/annotator/embeddings/universal_sentence_encoder.py +3 -3
  117. sparknlp/annotator/embeddings/word2vec.py +7 -1
  118. sparknlp/annotator/embeddings/word_embeddings.py +4 -5
  119. sparknlp/annotator/embeddings/xlm_roberta_embeddings.py +9 -21
  120. sparknlp/annotator/embeddings/xlm_roberta_sentence_embeddings.py +7 -21
  121. sparknlp/annotator/embeddings/xlnet_embeddings.py +4 -18
  122. sparknlp/annotator/er/entity_ruler.py +37 -23
  123. sparknlp/annotator/keyword_extraction/yake_keyword_extraction.py +2 -3
  124. sparknlp/annotator/ld_dl/language_detector_dl.py +2 -2
  125. sparknlp/annotator/lemmatizer.py +3 -4
  126. sparknlp/annotator/matcher/date_matcher.py +35 -3
  127. sparknlp/annotator/matcher/multi_date_matcher.py +1 -2
  128. sparknlp/annotator/matcher/regex_matcher.py +3 -3
  129. sparknlp/annotator/matcher/text_matcher.py +2 -3
  130. sparknlp/annotator/n_gram_generator.py +1 -2
  131. sparknlp/annotator/ner/__init__.py +3 -1
  132. sparknlp/annotator/ner/ner_converter.py +18 -0
  133. sparknlp/annotator/ner/ner_crf.py +4 -5
  134. sparknlp/annotator/ner/ner_dl.py +10 -5
  135. sparknlp/annotator/ner/ner_dl_graph_checker.py +293 -0
  136. sparknlp/annotator/ner/ner_overwriter.py +2 -2
  137. sparknlp/annotator/ner/zero_shot_ner_model.py +173 -0
  138. sparknlp/annotator/normalizer.py +2 -2
  139. sparknlp/annotator/openai/__init__.py +16 -0
  140. sparknlp/annotator/openai/openai_completion.py +349 -0
  141. sparknlp/annotator/openai/openai_embeddings.py +106 -0
  142. sparknlp/annotator/pos/perceptron.py +6 -7
  143. sparknlp/annotator/sentence/sentence_detector.py +2 -2
  144. sparknlp/annotator/sentence/sentence_detector_dl.py +3 -3
  145. sparknlp/annotator/sentiment/sentiment_detector.py +4 -5
  146. sparknlp/annotator/sentiment/vivekn_sentiment.py +4 -5
  147. sparknlp/annotator/seq2seq/__init__.py +17 -0
  148. sparknlp/annotator/seq2seq/auto_gguf_model.py +304 -0
  149. sparknlp/annotator/seq2seq/auto_gguf_reranker.py +334 -0
  150. sparknlp/annotator/seq2seq/auto_gguf_vision_model.py +336 -0
  151. sparknlp/annotator/seq2seq/bart_transformer.py +420 -0
  152. sparknlp/annotator/seq2seq/cohere_transformer.py +357 -0
  153. sparknlp/annotator/seq2seq/cpm_transformer.py +321 -0
  154. sparknlp/annotator/seq2seq/gpt2_transformer.py +1 -1
  155. sparknlp/annotator/seq2seq/llama2_transformer.py +343 -0
  156. sparknlp/annotator/seq2seq/llama3_transformer.py +381 -0
  157. sparknlp/annotator/seq2seq/m2m100_transformer.py +392 -0
  158. sparknlp/annotator/seq2seq/marian_transformer.py +124 -3
  159. sparknlp/annotator/seq2seq/mistral_transformer.py +348 -0
  160. sparknlp/annotator/seq2seq/nllb_transformer.py +420 -0
  161. sparknlp/annotator/seq2seq/olmo_transformer.py +326 -0
  162. sparknlp/annotator/seq2seq/phi2_transformer.py +326 -0
  163. sparknlp/annotator/seq2seq/phi3_transformer.py +330 -0
  164. sparknlp/annotator/seq2seq/phi4_transformer.py +387 -0
  165. sparknlp/annotator/seq2seq/qwen_transformer.py +340 -0
  166. sparknlp/annotator/seq2seq/starcoder_transformer.py +335 -0
  167. sparknlp/annotator/seq2seq/t5_transformer.py +54 -4
  168. sparknlp/annotator/similarity/__init__.py +0 -0
  169. sparknlp/annotator/similarity/document_similarity_ranker.py +379 -0
  170. sparknlp/annotator/spell_check/context_spell_checker.py +116 -17
  171. sparknlp/annotator/spell_check/norvig_sweeting.py +3 -6
  172. sparknlp/annotator/spell_check/symmetric_delete.py +1 -1
  173. sparknlp/annotator/stemmer.py +2 -3
  174. sparknlp/annotator/stop_words_cleaner.py +3 -4
  175. sparknlp/annotator/tf_ner_dl_graph_builder.py +1 -1
  176. sparknlp/annotator/token/__init__.py +0 -1
  177. sparknlp/annotator/token/recursive_tokenizer.py +2 -3
  178. sparknlp/annotator/token/tokenizer.py +2 -3
  179. sparknlp/annotator/ws/word_segmenter.py +35 -10
  180. sparknlp/base/__init__.py +2 -3
  181. sparknlp/base/doc2_chunk.py +0 -3
  182. sparknlp/base/document_assembler.py +5 -5
  183. sparknlp/base/embeddings_finisher.py +14 -2
  184. sparknlp/base/finisher.py +15 -4
  185. sparknlp/base/gguf_ranking_finisher.py +234 -0
  186. sparknlp/base/image_assembler.py +69 -0
  187. sparknlp/base/light_pipeline.py +53 -21
  188. sparknlp/base/multi_document_assembler.py +9 -13
  189. sparknlp/base/prompt_assembler.py +207 -0
  190. sparknlp/base/token_assembler.py +1 -2
  191. sparknlp/common/__init__.py +2 -0
  192. sparknlp/common/annotator_type.py +1 -0
  193. sparknlp/common/completion_post_processing.py +37 -0
  194. sparknlp/common/match_strategy.py +33 -0
  195. sparknlp/common/properties.py +914 -9
  196. sparknlp/internal/__init__.py +841 -116
  197. sparknlp/internal/annotator_java_ml.py +1 -1
  198. sparknlp/internal/annotator_transformer.py +3 -0
  199. sparknlp/logging/comet.py +2 -2
  200. sparknlp/partition/__init__.py +16 -0
  201. sparknlp/partition/partition.py +244 -0
  202. sparknlp/partition/partition_properties.py +902 -0
  203. sparknlp/partition/partition_transformer.py +200 -0
  204. sparknlp/pretrained/pretrained_pipeline.py +1 -1
  205. sparknlp/pretrained/resource_downloader.py +126 -2
  206. sparknlp/reader/__init__.py +15 -0
  207. sparknlp/reader/enums.py +19 -0
  208. sparknlp/reader/pdf_to_text.py +190 -0
  209. sparknlp/reader/reader2doc.py +124 -0
  210. sparknlp/reader/reader2image.py +136 -0
  211. sparknlp/reader/reader2table.py +44 -0
  212. sparknlp/reader/reader_assembler.py +159 -0
  213. sparknlp/reader/sparknlp_reader.py +461 -0
  214. sparknlp/training/__init__.py +1 -0
  215. sparknlp/training/conll.py +8 -2
  216. sparknlp/training/spacy_to_annotation.py +57 -0
  217. sparknlp/util.py +26 -0
  218. spark_nlp-4.2.6.dist-info/METADATA +0 -1256
  219. spark_nlp-4.2.6.dist-info/RECORD +0 -196
  220. {spark_nlp-4.2.6.dist-info → spark_nlp-6.2.1.dist-info}/top_level.txt +0 -0
  221. /sparknlp/annotator/{token/token2_chunk.py → token2_chunk.py} +0 -0
@@ -12,6 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
  """Contains classes for Annotator properties."""
15
+ from typing import List, Dict
15
16
 
16
17
  from pyspark.ml.param import Param, Params, TypeConverters
17
18
 
@@ -37,7 +38,7 @@ class HasBatchedAnnotate:
37
38
  int
38
39
  Current batch size
39
40
  """
40
- return self.getOrDefault("batchSize")
41
+ return self.getOrDefault(self.batchSize)
41
42
 
42
43
 
43
44
  class HasCaseSensitiveProperties:
@@ -67,12 +68,49 @@ class HasCaseSensitiveProperties:
67
68
  return self.getOrDefault(self.caseSensitive)
68
69
 
69
70
 
71
+ class HasClsTokenProperties:
72
+ useCLSToken = Param(Params._dummy(),
73
+ "useCLSToken",
74
+ "Whether to use CLS token for pooling (true) or attention-based average pooling (false)",
75
+ typeConverter=TypeConverters.toBoolean)
76
+
77
+ def setUseCLSToken(self, value):
78
+ """Sets whether to ignore case in tokens for embeddings matching.
79
+
80
+ Parameters
81
+ ----------
82
+ value : bool
83
+ Whether to use CLS token for pooling (true) or attention-based average pooling (false)
84
+ """
85
+ return self._set(useCLSToken=value)
86
+
87
+ def getUseCLSToken(self):
88
+ """Gets whether to use CLS token for pooling (true) or attention-based average pooling (false)
89
+
90
+ Returns
91
+ -------
92
+ bool
93
+ Whether to use CLS token for pooling (true) or attention-based average pooling (false)
94
+ """
95
+ return self.getOrDefault(self.useCLSToken)
96
+
97
+
70
98
  class HasClassifierActivationProperties:
71
99
  activation = Param(Params._dummy(),
72
100
  "activation",
73
101
  "Whether to calculate logits via Softmax or Sigmoid. Default is Softmax",
74
102
  typeConverter=TypeConverters.toString)
75
103
 
104
+ multilabel = Param(Params._dummy(),
105
+ "multilabel",
106
+ "Whether to calculate logits via Multiclass(softmax) or Multilabel(sigmoid). Default is False i.e. Multiclass",
107
+ typeConverter=TypeConverters.toBoolean)
108
+
109
+ threshold = Param(Params._dummy(),
110
+ "threshold",
111
+ "Choose the threshold to determine which logits are considered to be positive or negative",
112
+ typeConverter=TypeConverters.toFloat)
113
+
76
114
  def setActivation(self, value):
77
115
  """Sets whether to calculate logits via Softmax or Sigmoid. Default is Softmax
78
116
 
@@ -93,6 +131,50 @@ class HasClassifierActivationProperties:
93
131
  """
94
132
  return self.getOrDefault(self.activation)
95
133
 
134
+ def setMultilabel(self, value):
135
+ """Set whether or not the result should be multi-class (the sum of all probabilities is 1.0) or
136
+ multi-label (each label has a probability between 0.0 to 1.0).
137
+ Default is False i.e. multi-class
138
+
139
+ Parameters
140
+ ----------
141
+ value : bool
142
+ Whether or not the result should be multi-class (the sum of all probabilities is 1.0) or
143
+ multi-label (each label has a probability between 0.0 to 1.0).
144
+ Default is False i.e. multi-class
145
+ """
146
+ return self._set(multilabel=value)
147
+
148
+ def getMultilabel(self):
149
+ """Gets whether or not the result should be multi-class (the sum of all probabilities is 1.0) or
150
+ multi-label (each label has a probability between 0.0 to 1.0).
151
+ Default is False i.e. multi-class
152
+
153
+ Parameters
154
+ ----------
155
+ value : bool
156
+ Whether or not the result should be multi-class (the sum of all probabilities is 1.0) or
157
+ multi-label (each label has a probability between 0.0 to 1.0).
158
+ Default is False i.e. multi-class
159
+ """
160
+ return self.getOrDefault(self.multilabel)
161
+
162
+ def setThreshold(self, value):
163
+ """Set the threshold to determine which logits are considered to be positive or negative.
164
+ (Default: `0.5`). The value should be between 0.0 and 1.0. Changing the threshold value
165
+ will affect the resulting labels and can be used to adjust the balance between precision and
166
+ recall in the classification process.
167
+
168
+ Parameters
169
+ ----------
170
+ value : float
171
+ The threshold to determine which logits are considered to be positive or negative.
172
+ (Default: `0.5`). The value should be between 0.0 and 1.0. Changing the threshold value
173
+ will affect the resulting labels and can be used to adjust the balance between precision and
174
+ recall in the classification process.
175
+ """
176
+ return self._set(threshold=value)
177
+
96
178
 
97
179
  class HasEmbeddingsProperties(Params):
98
180
  dimension = Param(Params._dummy(),
@@ -163,7 +245,7 @@ class HasBatchedAnnotateImage:
163
245
  int
164
246
  Current batch size
165
247
  """
166
- return self.getOrDefault("batchSize")
248
+ return self.getOrDefault(self.batchSize)
167
249
 
168
250
 
169
251
  class HasImageFeatureProperties:
@@ -187,9 +269,8 @@ class HasImageFeatureProperties:
187
269
  TypeConverters.toListFloat)
188
270
 
189
271
  resample = Param(Params._dummy(), "resample",
190
- "An optional resampling filter. This can be one of PIL.Image.NEAREST, PIL.Image.BOX, "
191
- "PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC or PIL.Image.LANCZOS. Only has an "
192
- "effect if do_resize is set to True",
272
+ "An optional resampling filter. This can be one of PIL.Image.NEAREST, PIL.Image.BILINEAR or "
273
+ "PIL.Image.BICUBIC. Only has an effect if do_resize is set to True.",
193
274
  TypeConverters.toInt)
194
275
 
195
276
  size = Param(Params._dummy(), "size",
@@ -254,9 +335,8 @@ class HasImageFeatureProperties:
254
335
  Parameters
255
336
  ----------
256
337
  value : int
257
- An optional resampling filter. This can be one of PIL.Image.NEAREST,
258
- PIL.Image.BOX, PIL.Image.BILINEAR PIL.Image.HAMMING, PIL.Image.BICUBIC or PIL.Image.LANCZOS. Only has an
259
- effect if do_resize is set to True
338
+ Resampling filter for resizing. This can be one of `PIL.Image.NEAREST`, `PIL.Image.BILINEAR` or
339
+ `PIL.Image.BICUBIC`. Only has an effect if `do_resize` is set to `True`.
260
340
  """
261
341
  return self._set(resample=value)
262
342
 
@@ -271,6 +351,36 @@ class HasImageFeatureProperties:
271
351
  return self._set(size=value)
272
352
 
273
353
 
354
+ class HasRescaleFactor:
355
+ doRescale = Param(Params._dummy(), "doRescale",
356
+ "Whether to rescale the image values by rescaleFactor.",
357
+ TypeConverters.toBoolean)
358
+
359
+ rescaleFactor = Param(Params._dummy(), "rescaleFactor",
360
+ "Factor to scale the image values",
361
+ TypeConverters.toFloat)
362
+
363
+ def setDoRescale(self, value):
364
+ """Sets Whether to rescale the image values by rescaleFactor, by default `True`.
365
+
366
+ Parameters
367
+ ----------
368
+ value : Boolean
369
+ Whether to rescale the image values by rescaleFactor.
370
+ """
371
+ return self._set(doRescale=value)
372
+
373
+ def setRescaleFactor(self, value):
374
+ """Sets Factor to scale the image values, by default `1/255.0`.
375
+
376
+ Parameters
377
+ ----------
378
+ value : Boolean
379
+ Whether to rescale the image values by rescaleFactor.
380
+ """
381
+ return self._set(rescaleFactor=value)
382
+
383
+
274
384
  class HasBatchedAnnotateAudio:
275
385
  batchSize = Param(Params._dummy(), "batchSize", "Size of every batch", TypeConverters.toInt)
276
386
 
@@ -292,7 +402,7 @@ class HasBatchedAnnotateAudio:
292
402
  int
293
403
  Current batch size
294
404
  """
295
- return self.getOrDefault("batchSize")
405
+ return self.getOrDefault(self.batchSize)
296
406
 
297
407
 
298
408
  class HasAudioFeatureProperties:
@@ -391,3 +501,798 @@ class HasEngine:
391
501
  Deep Learning engine used for this model"
392
502
  """
393
503
  return self.getOrDefault(self.engine)
504
+
505
+
506
+ class HasCandidateLabelsProperties:
507
+ candidateLabels = Param(Params._dummy(), "candidateLabels",
508
+ "Deep Learning engine used for this model",
509
+ typeConverter=TypeConverters.toListString)
510
+
511
+ contradictionIdParam = Param(Params._dummy(), "contradictionIdParam",
512
+ "contradictionIdParam",
513
+ typeConverter=TypeConverters.toInt)
514
+
515
+ entailmentIdParam = Param(Params._dummy(), "entailmentIdParam",
516
+ "contradictionIdParam",
517
+ typeConverter=TypeConverters.toInt)
518
+
519
+ def setCandidateLabels(self, v):
520
+ """Sets candidateLabels.
521
+
522
+ Parameters
523
+ ----------
524
+ v : list[string]
525
+ candidateLabels
526
+ """
527
+ return self._set(candidateLabels=v)
528
+
529
+ def setContradictionIdParam(self, v):
530
+ """Sets contradictionIdParam.
531
+
532
+ Parameters
533
+ ----------
534
+ v : int
535
+ contradictionIdParam
536
+ """
537
+ return self._set(contradictionIdParam=v)
538
+
539
+ def setEntailmentIdParam(self, v):
540
+ """Sets entailmentIdParam.
541
+
542
+ Parameters
543
+ ----------
544
+ v : int
545
+ entailmentIdParam
546
+ """
547
+ return self._set(entailmentIdParam=v)
548
+
549
+
550
+ class HasMaxSentenceLengthLimit:
551
+ # Default Value, can be overridden
552
+ max_length_limit = 512
553
+
554
+ maxSentenceLength = Param(Params._dummy(),
555
+ "maxSentenceLength",
556
+ "Max sentence length to process",
557
+ typeConverter=TypeConverters.toInt)
558
+
559
+ def setMaxSentenceLength(self, value):
560
+ """Sets max sentence length to process.
561
+
562
+ Note that a maximum limit exists depending on the model. If you are working with long single
563
+ sequences, consider splitting up the input first with another annotator e.g. SentenceDetector.
564
+
565
+ Parameters
566
+ ----------
567
+ value : int
568
+ Max sentence length to process
569
+ """
570
+ if value > self.max_length_limit:
571
+ raise ValueError(
572
+ f"{self.__class__.__name__} models do not support token sequences longer than {self.max_length_limit}.\n"
573
+ f"Consider splitting up the input first with another annotator e.g. SentenceDetector.")
574
+ return self._set(maxSentenceLength=value)
575
+
576
+ def getMaxSentenceLength(self):
577
+ """Gets max sentence of the model.
578
+
579
+ Returns
580
+ -------
581
+ int
582
+ Max sentence length to process
583
+ """
584
+ return self.getOrDefault("maxSentenceLength")
585
+
586
+
587
+ class HasLongMaxSentenceLengthLimit(HasMaxSentenceLengthLimit):
588
+ max_length_limit = 4096
589
+
590
+
591
+ class HasGeneratorProperties:
592
+ task = Param(Params._dummy(), "task", "Transformer's task, e.g. summarize>", typeConverter=TypeConverters.toString)
593
+
594
+ minOutputLength = Param(Params._dummy(), "minOutputLength", "Minimum length of the sequence to be generated",
595
+ typeConverter=TypeConverters.toInt)
596
+
597
+ maxOutputLength = Param(Params._dummy(), "maxOutputLength", "Maximum length of output text",
598
+ typeConverter=TypeConverters.toInt)
599
+
600
+ doSample = Param(Params._dummy(), "doSample", "Whether or not to use sampling; use greedy decoding otherwise",
601
+ typeConverter=TypeConverters.toBoolean)
602
+
603
+ temperature = Param(Params._dummy(), "temperature", "The value used to module the next token probabilities",
604
+ typeConverter=TypeConverters.toFloat)
605
+
606
+ topK = Param(Params._dummy(), "topK",
607
+ "The number of highest probability vocabulary tokens to keep for top-k-filtering",
608
+ typeConverter=TypeConverters.toInt)
609
+
610
+ topP = Param(Params._dummy(), "topP",
611
+ "If set to float < 1, only the most probable tokens with probabilities that add up to ``top_p`` or higher are kept for generation",
612
+ typeConverter=TypeConverters.toFloat)
613
+
614
+ repetitionPenalty = Param(Params._dummy(), "repetitionPenalty",
615
+ "The parameter for repetition penalty. 1.0 means no penalty. See `this paper <https://arxiv.org/pdf/1909.05858.pdf>`__ for more details",
616
+ typeConverter=TypeConverters.toFloat)
617
+
618
+ noRepeatNgramSize = Param(Params._dummy(), "noRepeatNgramSize",
619
+ "If set to int > 0, all ngrams of that size can only occur once",
620
+ typeConverter=TypeConverters.toInt)
621
+
622
+ beamSize = Param(Params._dummy(), "beamSize",
623
+ "The Number of beams for beam search.",
624
+ typeConverter=TypeConverters.toInt)
625
+
626
+ nReturnSequences = Param(Params._dummy(),
627
+ "nReturnSequences",
628
+ "The number of sequences to return from the beam search.",
629
+ typeConverter=TypeConverters.toInt)
630
+
631
+ def setTask(self, value):
632
+ """Sets the transformer's task, e.g. ``summarize:``.
633
+
634
+ Parameters
635
+ ----------
636
+ value : str
637
+ The transformer's task
638
+ """
639
+ return self._set(task=value)
640
+
641
+ def setMinOutputLength(self, value):
642
+ """Sets minimum length of the sequence to be generated.
643
+
644
+ Parameters
645
+ ----------
646
+ value : int
647
+ Minimum length of the sequence to be generated
648
+ """
649
+ return self._set(minOutputLength=value)
650
+
651
+ def setMaxOutputLength(self, value):
652
+ """Sets maximum length of output text.
653
+
654
+ Parameters
655
+ ----------
656
+ value : int
657
+ Maximum length of output text
658
+ """
659
+ return self._set(maxOutputLength=value)
660
+
661
+ def setDoSample(self, value):
662
+ """Sets whether or not to use sampling, use greedy decoding otherwise.
663
+
664
+ Parameters
665
+ ----------
666
+ value : bool
667
+ Whether or not to use sampling; use greedy decoding otherwise
668
+ """
669
+ return self._set(doSample=value)
670
+
671
+ def setTemperature(self, value):
672
+ """Sets the value used to module the next token probabilities.
673
+
674
+ Parameters
675
+ ----------
676
+ value : float
677
+ The value used to module the next token probabilities
678
+ """
679
+ return self._set(temperature=value)
680
+
681
+ def setTopK(self, value):
682
+ """Sets the number of highest probability vocabulary tokens to keep for
683
+ top-k-filtering.
684
+
685
+ Parameters
686
+ ----------
687
+ value : int
688
+ Number of highest probability vocabulary tokens to keep
689
+ """
690
+ return self._set(topK=value)
691
+
692
+ def setTopP(self, value):
693
+ """Sets the top cumulative probability for vocabulary tokens.
694
+
695
+ If set to float < 1, only the most probable tokens with probabilities
696
+ that add up to ``topP`` or higher are kept for generation.
697
+
698
+ Parameters
699
+ ----------
700
+ value : float
701
+ Cumulative probability for vocabulary tokens
702
+ """
703
+ return self._set(topP=value)
704
+
705
+ def setRepetitionPenalty(self, value):
706
+ """Sets the parameter for repetition penalty. 1.0 means no penalty.
707
+
708
+ Parameters
709
+ ----------
710
+ value : float
711
+ The repetition penalty
712
+
713
+ References
714
+ ----------
715
+ See `Ctrl: A Conditional Transformer Language Model For Controllable
716
+ Generation <https://arxiv.org/pdf/1909.05858.pdf>`__ for more details.
717
+ """
718
+ return self._set(repetitionPenalty=value)
719
+
720
+ def setNoRepeatNgramSize(self, value):
721
+ """Sets size of n-grams that can only occur once.
722
+
723
+ If set to int > 0, all ngrams of that size can only occur once.
724
+
725
+ Parameters
726
+ ----------
727
+ value : int
728
+ N-gram size can only occur once
729
+ """
730
+ return self._set(noRepeatNgramSize=value)
731
+
732
+ def setBeamSize(self, value):
733
+ """Sets the number of beam size for beam search.
734
+
735
+ Parameters
736
+ ----------
737
+ value : int
738
+ Number of beam size for beam search
739
+ """
740
+ return self._set(beamSize=value)
741
+
742
+ def setNReturnSequences(self, value):
743
+ """Sets the number of sequences to return from the beam search.
744
+
745
+ Parameters
746
+ ----------
747
+ value : int
748
+ Number of sequences to return
749
+ """
750
+ return self._set(nReturnSequences=value)
751
+
752
+
753
+ class HasLlamaCppProperties:
754
+ # -------- MODEl PARAMETERS --------
755
+ nThreads = Param(Params._dummy(), "nThreads", "Set the number of threads to use during generation",
756
+ typeConverter=TypeConverters.toInt)
757
+ # nThreadsDraft = Param(Params._dummy(), "nThreadsDraft", "Set the number of threads to use during draft generation",
758
+ # typeConverter=TypeConverters.toInt)
759
+ nThreadsBatch = Param(Params._dummy(), "nThreadsBatch",
760
+ "Set the number of threads to use during batch and prompt processing",
761
+ typeConverter=TypeConverters.toInt)
762
+ # nThreadsBatchDraft = Param(Params._dummy(), "nThreadsBatchDraft",
763
+ # "Set the number of threads to use during batch and prompt processing",
764
+ # typeConverter=TypeConverters.toInt)
765
+ nCtx = Param(Params._dummy(), "nCtx", "Set the size of the prompt context", typeConverter=TypeConverters.toInt)
766
+ nBatch = Param(Params._dummy(), "nBatch",
767
+ "Set the logical batch size for prompt processing (must be >=32 to use BLAS)",
768
+ typeConverter=TypeConverters.toInt)
769
+ nUbatch = Param(Params._dummy(), "nUbatch",
770
+ "Set the physical batch size for prompt processing (must be >=32 to use BLAS)",
771
+ typeConverter=TypeConverters.toInt)
772
+ nDraft = Param(Params._dummy(), "nDraft", "Set the number of tokens to draft for speculative decoding",
773
+ typeConverter=TypeConverters.toInt)
774
+ # nChunks = Param(Params._dummy(), "nChunks", "Set the maximal number of chunks to process",
775
+ # typeConverter=TypeConverters.toInt)
776
+ # nSequences = Param(Params._dummy(), "nSequences", "Set the number of sequences to decode",
777
+ # typeConverter=TypeConverters.toInt)
778
+ # pSplit = Param(Params._dummy(), "pSplit", "Set the speculative decoding split probability",
779
+ # typeConverter=TypeConverters.toFloat)
780
+ nGpuLayers = Param(Params._dummy(), "nGpuLayers", "Set the number of layers to store in VRAM (-1 - use default)",
781
+ typeConverter=TypeConverters.toInt)
782
+ nGpuLayersDraft = Param(Params._dummy(), "nGpuLayersDraft",
783
+ "Set the number of layers to store in VRAM for the draft model (-1 - use default)",
784
+ typeConverter=TypeConverters.toInt)
785
+ # Set how to split the model across GPUs
786
+ #
787
+ # - NONE: No GPU split
788
+ # - LAYER: Split the model across GPUs by layer
789
+ # - ROW: Split the model across GPUs by rows
790
+ gpuSplitMode = Param(Params._dummy(), "gpuSplitMode", "Set how to split the model across GPUs",
791
+ typeConverter=TypeConverters.toString)
792
+ mainGpu = Param(Params._dummy(), "mainGpu", "Set the main GPU that is used for scratch and small tensors.",
793
+ typeConverter=TypeConverters.toInt)
794
+ # tensorSplit = Param(Params._dummy(), "tensorSplit", "Set how split tensors should be distributed across GPUs",
795
+ # typeConverter=TypeConverters.toListFloat)
796
+ # grpAttnN = Param(Params._dummy(), "grpAttnN", "Set the group-attention factor", typeConverter=TypeConverters.toInt)
797
+ # grpAttnW = Param(Params._dummy(), "grpAttnW", "Set the group-attention width", typeConverter=TypeConverters.toInt)
798
+ ropeFreqBase = Param(Params._dummy(), "ropeFreqBase", "Set the RoPE base frequency, used by NTK-aware scaling",
799
+ typeConverter=TypeConverters.toFloat)
800
+ ropeFreqScale = Param(Params._dummy(), "ropeFreqScale",
801
+ "Set the RoPE frequency scaling factor, expands context by a factor of 1/N",
802
+ typeConverter=TypeConverters.toFloat)
803
+ yarnExtFactor = Param(Params._dummy(), "yarnExtFactor", "Set the YaRN extrapolation mix factor",
804
+ typeConverter=TypeConverters.toFloat)
805
+ yarnAttnFactor = Param(Params._dummy(), "yarnAttnFactor", "Set the YaRN scale sqrt(t) or attention magnitude",
806
+ typeConverter=TypeConverters.toFloat)
807
+ yarnBetaFast = Param(Params._dummy(), "yarnBetaFast", "Set the YaRN low correction dim or beta",
808
+ typeConverter=TypeConverters.toFloat)
809
+ yarnBetaSlow = Param(Params._dummy(), "yarnBetaSlow", "Set the YaRN high correction dim or alpha",
810
+ typeConverter=TypeConverters.toFloat)
811
+ yarnOrigCtx = Param(Params._dummy(), "yarnOrigCtx", "Set the YaRN original context size of model",
812
+ typeConverter=TypeConverters.toInt)
813
+ defragmentationThreshold = Param(Params._dummy(), "defragmentationThreshold",
814
+ "Set the KV cache defragmentation threshold", typeConverter=TypeConverters.toFloat)
815
+ # Set optimization strategies that help on some NUMA systems (if available)
816
+ #
817
+ # Available Strategies:
818
+ #
819
+ # - DISABLED: No NUMA optimizations
820
+ # - DISTRIBUTE: Spread execution evenly over all
821
+ # - ISOLATE: Only spawn threads on CPUs on the node that execution started on
822
+ # - NUMA_CTL: Use the CPU map provided by numactl
823
+ # - MIRROR: Mirrors the model across NUMA nodes
824
+ numaStrategy = Param(Params._dummy(), "numaStrategy",
825
+ "Set optimization strategies that help on some NUMA systems (if available)",
826
+ typeConverter=TypeConverters.toString)
827
+ # Set the RoPE frequency scaling method, defaults to linear unless specified by the model.
828
+ #
829
+ # - NONE: Don't use any scaling
830
+ # - LINEAR: Linear scaling
831
+ # - YARN: YaRN RoPE scaling
832
+ ropeScalingType = Param(Params._dummy(), "ropeScalingType",
833
+ "Set the RoPE frequency scaling method, defaults to linear unless specified by the model",
834
+ typeConverter=TypeConverters.toString)
835
+ # Set the pooling type for embeddings, use model default if unspecified
836
+ #
837
+ # - MEAN: Mean Pooling
838
+ # - CLS: CLS Pooling
839
+ # - LAST: Last token pooling
840
+ # - RANK: For reranked models
841
+ poolingType = Param(Params._dummy(), "poolingType",
842
+ "Set the pooling type for embeddings, use model default if unspecified",
843
+ typeConverter=TypeConverters.toString)
844
+ modelDraft = Param(Params._dummy(), "modelDraft", "Set the draft model for speculative decoding",
845
+ typeConverter=TypeConverters.toString)
846
+ modelAlias = Param(Params._dummy(), "modelAlias", "Set a model alias", typeConverter=TypeConverters.toString)
847
+ # lookupCacheStaticFilePath = Param(Params._dummy(), "lookupCacheStaticFilePath",
848
+ # "Set path to static lookup cache to use for lookup decoding (not updated by generation)",
849
+ # typeConverter=TypeConverters.toString)
850
+ # lookupCacheDynamicFilePath = Param(Params._dummy(), "lookupCacheDynamicFilePath",
851
+ # "Set path to dynamic lookup cache to use for lookup decoding (updated by generation)",
852
+ # typeConverter=TypeConverters.toString)
853
+ # loraAdapters = new StructFeature[Map[String, Float]](this, "loraAdapters")
854
+ embedding = Param(Params._dummy(), "embedding", "Whether to load model with embedding support",
855
+ typeConverter=TypeConverters.toBoolean)
856
+ flashAttention = Param(Params._dummy(), "flashAttention", "Whether to enable Flash Attention",
857
+ typeConverter=TypeConverters.toBoolean)
858
+ # inputPrefixBos = Param(Params._dummy(), "inputPrefixBos",
859
+ # "Whether to add prefix BOS to user inputs, preceding the `--in-prefix` string",
860
+ # typeConverter=TypeConverters.toBoolean)
861
+ useMmap = Param(Params._dummy(), "useMmap",
862
+ "Whether to use memory-map model (faster load but may increase pageouts if not using mlock)",
863
+ typeConverter=TypeConverters.toBoolean)
864
+ useMlock = Param(Params._dummy(), "useMlock",
865
+ "Whether to force the system to keep model in RAM rather than swapping or compressing",
866
+ typeConverter=TypeConverters.toBoolean)
867
+ noKvOffload = Param(Params._dummy(), "noKvOffload", "Whether to disable KV offload",
868
+ typeConverter=TypeConverters.toBoolean)
869
+ systemPrompt = Param(Params._dummy(), "systemPrompt", "Set a system prompt to use",
870
+ typeConverter=TypeConverters.toString)
871
+ chatTemplate = Param(Params._dummy(), "chatTemplate", "The chat template to use",
872
+ typeConverter=TypeConverters.toString)
873
+ logVerbosity = Param(Params._dummy(), "logVerbosity", "Set the log verbosity level",
874
+ typeConverter=TypeConverters.toInt)
875
+ disableLog = Param(Params._dummy(), "disableLog", "Whether to disable logging",
876
+ typeConverter=TypeConverters.toBoolean)
877
+
878
+ # -------- INFERENCE PARAMETERS --------
879
+ inputPrefix = Param(Params._dummy(), "inputPrefix", "Set the prompt to start generation with",
880
+ typeConverter=TypeConverters.toString)
881
+ inputSuffix = Param(Params._dummy(), "inputSuffix", "Set a suffix for infilling",
882
+ typeConverter=TypeConverters.toString)
883
+ cachePrompt = Param(Params._dummy(), "cachePrompt", "Whether to remember the prompt to avoid reprocessing it",
884
+ typeConverter=TypeConverters.toBoolean)
885
+ nPredict = Param(Params._dummy(), "nPredict", "Set the number of tokens to predict",
886
+ typeConverter=TypeConverters.toInt)
887
+ topK = Param(Params._dummy(), "topK", "Set top-k sampling", typeConverter=TypeConverters.toInt)
888
+ topP = Param(Params._dummy(), "topP", "Set top-p sampling", typeConverter=TypeConverters.toFloat)
889
+ minP = Param(Params._dummy(), "minP", "Set min-p sampling", typeConverter=TypeConverters.toFloat)
890
+ tfsZ = Param(Params._dummy(), "tfsZ", "Set tail free sampling, parameter z", typeConverter=TypeConverters.toFloat)
891
+ typicalP = Param(Params._dummy(), "typicalP", "Set locally typical sampling, parameter p",
892
+ typeConverter=TypeConverters.toFloat)
893
+ temperature = Param(Params._dummy(), "temperature", "Set the temperature", typeConverter=TypeConverters.toFloat)
894
+ dynamicTemperatureRange = Param(Params._dummy(), "dynatempRange", "Set the dynamic temperature range",
895
+ typeConverter=TypeConverters.toFloat)
896
+ dynamicTemperatureExponent = Param(Params._dummy(), "dynatempExponent", "Set the dynamic temperature exponent",
897
+ typeConverter=TypeConverters.toFloat)
898
+ repeatLastN = Param(Params._dummy(), "repeatLastN", "Set the last n tokens to consider for penalties",
899
+ typeConverter=TypeConverters.toInt)
900
+ repeatPenalty = Param(Params._dummy(), "repeatPenalty", "Set the penalty of repeated sequences of tokens",
901
+ typeConverter=TypeConverters.toFloat)
902
+ frequencyPenalty = Param(Params._dummy(), "frequencyPenalty", "Set the repetition alpha frequency penalty",
903
+ typeConverter=TypeConverters.toFloat)
904
+ presencePenalty = Param(Params._dummy(), "presencePenalty", "Set the repetition alpha presence penalty",
905
+ typeConverter=TypeConverters.toFloat)
906
+ miroStat = Param(Params._dummy(), "miroStat", "Set MiroStat sampling strategies.",
907
+ typeConverter=TypeConverters.toString)
908
+ miroStatTau = Param(Params._dummy(), "mirostatTau", "Set the MiroStat target entropy, parameter tau",
909
+ typeConverter=TypeConverters.toFloat)
910
+ miroStatEta = Param(Params._dummy(), "mirostatEta", "Set the MiroStat learning rate, parameter eta",
911
+ typeConverter=TypeConverters.toFloat)
912
+ penalizeNl = Param(Params._dummy(), "penalizeNl", "Whether to penalize newline tokens",
913
+ typeConverter=TypeConverters.toBoolean)
914
+ nKeep = Param(Params._dummy(), "nKeep", "Set the number of tokens to keep from the initial prompt",
915
+ typeConverter=TypeConverters.toInt)
916
+ seed = Param(Params._dummy(), "seed", "Set the RNG seed", typeConverter=TypeConverters.toInt)
917
+ nProbs = Param(Params._dummy(), "nProbs", "Set the amount top tokens probabilities to output if greater than 0.",
918
+ typeConverter=TypeConverters.toInt)
919
+ minKeep = Param(Params._dummy(), "minKeep",
920
+ "Set the amount of tokens the samplers should return at least (0 = disabled)",
921
+ typeConverter=TypeConverters.toInt)
922
+ grammar = Param(Params._dummy(), "grammar", "Set BNF-like grammar to constrain generations",
923
+ typeConverter=TypeConverters.toString)
924
+ penaltyPrompt = Param(Params._dummy(), "penaltyPrompt",
925
+ "Override which part of the prompt is penalized for repetition.",
926
+ typeConverter=TypeConverters.toString)
927
+ ignoreEos = Param(Params._dummy(), "ignoreEos",
928
+ "Set whether to ignore end of stream token and continue generating (implies --logit-bias 2-inf)",
929
+ typeConverter=TypeConverters.toBoolean)
930
+ disableTokenIds = Param(Params._dummy(), "disableTokenIds", "Set the token ids to disable in the completion",
931
+ typeConverter=TypeConverters.toListInt)
932
+ stopStrings = Param(Params._dummy(), "stopStrings", "Set strings upon seeing which token generation is stopped",
933
+ typeConverter=TypeConverters.toListString)
934
+ samplers = Param(Params._dummy(), "samplers", "Set which samplers to use for token generation in the given order",
935
+ typeConverter=TypeConverters.toListString)
936
+ useChatTemplate = Param(Params._dummy(), "useChatTemplate",
937
+ "Set whether or not generate should apply a chat template",
938
+ typeConverter=TypeConverters.toBoolean)
939
+
940
+ # -------- MODEL SETTERS --------
941
+ def setNThreads(self, nThreads: int):
942
+ """Set the number of threads to use during generation"""
943
+ return self._set(nThreads=nThreads)
944
+
945
+ # def setNThreadsDraft(self, nThreadsDraft: int):
946
+ # """Set the number of threads to use during draft generation"""
947
+ # return self._set(nThreadsDraft=nThreadsDraft)
948
+
949
+ def setNThreadsBatch(self, nThreadsBatch: int):
950
+ """Set the number of threads to use during batch and prompt processing"""
951
+ return self._set(nThreadsBatch=nThreadsBatch)
952
+
953
+ # def setNThreadsBatchDraft(self, nThreadsBatchDraft: int):
954
+ # """Set the number of threads to use during batch and prompt processing"""
955
+ # return self._set(nThreadsBatchDraft=nThreadsBatchDraft)
956
+
957
+ def setNCtx(self, nCtx: int):
958
+ """Set the size of the prompt context"""
959
+ return self._set(nCtx=nCtx)
960
+
961
+ def setNBatch(self, nBatch: int):
962
+ """Set the logical batch size for prompt processing (must be >=32 to use BLAS)"""
963
+ return self._set(nBatch=nBatch)
964
+
965
+ def setNUbatch(self, nUbatch: int):
966
+ """Set the physical batch size for prompt processing (must be >=32 to use BLAS)"""
967
+ return self._set(nUbatch=nUbatch)
968
+
969
+ def setNDraft(self, nDraft: int):
970
+ """Set the number of tokens to draft for speculative decoding"""
971
+ return self._set(nDraft=nDraft)
972
+
973
+ # def setNChunks(self, nChunks: int):
974
+ # """Set the maximal number of chunks to process"""
975
+ # return self._set(nChunks=nChunks)
976
+
977
+ # def setNSequences(self, nSequences: int):
978
+ # """Set the number of sequences to decode"""
979
+ # return self._set(nSequences=nSequences)
980
+
981
+ # def setPSplit(self, pSplit: float):
982
+ # """Set the speculative decoding split probability"""
983
+ # return self._set(pSplit=pSplit)
984
+
985
+ def setNGpuLayers(self, nGpuLayers: int):
986
+ """Set the number of layers to store in VRAM (-1 - use default)"""
987
+ return self._set(nGpuLayers=nGpuLayers)
988
+
989
+ def setNGpuLayersDraft(self, nGpuLayersDraft: int):
990
+ """Set the number of layers to store in VRAM for the draft model (-1 - use default)"""
991
+ return self._set(nGpuLayersDraft=nGpuLayersDraft)
992
+
993
+ def setGpuSplitMode(self, gpuSplitMode: str):
994
+ """Set how to split the model across GPUs"""
995
+ return self._set(gpuSplitMode=gpuSplitMode)
996
+
997
+ def setMainGpu(self, mainGpu: int):
998
+ """Set the main GPU that is used for scratch and small tensors."""
999
+ return self._set(mainGpu=mainGpu)
1000
+
1001
+ # def setTensorSplit(self, tensorSplit: List[float]):
1002
+ # """Set how split tensors should be distributed across GPUs"""
1003
+ # return self._set(tensorSplit=tensorSplit)
1004
+
1005
+ # def setGrpAttnN(self, grpAttnN: int):
1006
+ # """Set the group-attention factor"""
1007
+ # return self._set(grpAttnN=grpAttnN)
1008
+
1009
+ # def setGrpAttnW(self, grpAttnW: int):
1010
+ # """Set the group-attention width"""
1011
+ # return self._set(grpAttnW=grpAttnW)
1012
+
1013
+ def setRopeFreqBase(self, ropeFreqBase: float):
1014
+ """Set the RoPE base frequency, used by NTK-aware scaling"""
1015
+ return self._set(ropeFreqBase=ropeFreqBase)
1016
+
1017
+ def setRopeFreqScale(self, ropeFreqScale: float):
1018
+ """Set the RoPE frequency scaling factor, expands context by a factor of 1/N"""
1019
+ return self._set(ropeFreqScale=ropeFreqScale)
1020
+
1021
+ def setYarnExtFactor(self, yarnExtFactor: float):
1022
+ """Set the YaRN extrapolation mix factor"""
1023
+ return self._set(yarnExtFactor=yarnExtFactor)
1024
+
1025
+ def setYarnAttnFactor(self, yarnAttnFactor: float):
1026
+ """Set the YaRN scale sqrt(t) or attention magnitude"""
1027
+ return self._set(yarnAttnFactor=yarnAttnFactor)
1028
+
1029
+ def setYarnBetaFast(self, yarnBetaFast: float):
1030
+ """Set the YaRN low correction dim or beta"""
1031
+ return self._set(yarnBetaFast=yarnBetaFast)
1032
+
1033
+ def setYarnBetaSlow(self, yarnBetaSlow: float):
1034
+ """Set the YaRN high correction dim or alpha"""
1035
+ return self._set(yarnBetaSlow=yarnBetaSlow)
1036
+
1037
+ def setYarnOrigCtx(self, yarnOrigCtx: int):
1038
+ """Set the YaRN original context size of model"""
1039
+ return self._set(yarnOrigCtx=yarnOrigCtx)
1040
+
1041
+ def setDefragmentationThreshold(self, defragmentationThreshold: float):
1042
+ """Set the KV cache defragmentation threshold"""
1043
+ return self._set(defragmentationThreshold=defragmentationThreshold)
1044
+
1045
+ def setNumaStrategy(self, numaStrategy: str):
1046
+ """Set optimization strategies that help on some NUMA systems (if available)
1047
+
1048
+ Possible values:
1049
+
1050
+ - DISABLED: No NUMA optimizations
1051
+ - DISTRIBUTE: spread execution evenly over all
1052
+ - ISOLATE: only spawn threads on CPUs on the node that execution started on
1053
+ - NUMA_CTL: use the CPU map provided by numactl
1054
+ - MIRROR: Mirrors the model across NUMA nodes
1055
+ """
1056
+ numaUpper = numaStrategy.upper()
1057
+ numaStrategies = ["DISABLED", "DISTRIBUTE", "ISOLATE", "NUMA_CTL", "MIRROR"]
1058
+ if numaUpper not in numaStrategies:
1059
+ raise ValueError(
1060
+ f"Invalid NUMA strategy: {numaUpper}. "
1061
+ + f"Valid values are: {numaStrategies}"
1062
+ )
1063
+ return self._set(numaStrategy=numaStrategy)
1064
+
1065
+ def setRopeScalingType(self, ropeScalingType: str):
1066
+ """Set the RoPE frequency scaling method, defaults to linear unless specified by the model.
1067
+
1068
+ Possible values:
1069
+
1070
+ - NONE: Don't use any scaling
1071
+ - LINEAR: Linear scaling
1072
+ - YARN: YaRN RoPE scaling
1073
+ """
1074
+ ropeScalingTypeUpper = ropeScalingType.upper()
1075
+ ropeScalingTypes = ["NONE", "LINEAR", "YARN"]
1076
+ if ropeScalingTypeUpper not in ropeScalingTypes:
1077
+ raise ValueError(
1078
+ f"Invalid RoPE scaling type: {ropeScalingType}. "
1079
+ + f"Valid values are: {ropeScalingTypes}"
1080
+ )
1081
+ return self._set(ropeScalingType=ropeScalingTypeUpper)
1082
+
1083
+ def setPoolingType(self, poolingType: str):
1084
+ """Set the pooling type for embeddings, use model default if unspecified
1085
+
1086
+ Possible values:
1087
+
1088
+ - MEAN: Mean Pooling
1089
+ - CLS: CLS Pooling
1090
+ - LAST: Last token pooling
1091
+ - RANK: For reranked models
1092
+ """
1093
+ poolingTypeUpper = poolingType.upper()
1094
+ poolingTypes = ["NONE", "MEAN", "CLS", "LAST", "RANK"]
1095
+ if poolingTypeUpper not in poolingTypes:
1096
+ raise ValueError(
1097
+ f"Invalid pooling type: {poolingType}. "
1098
+ + f"Valid values are: {poolingTypes}"
1099
+ )
1100
+ return self._set(poolingType=poolingType)
1101
+
1102
+ def setModelDraft(self, modelDraft: str):
1103
+ """Set the draft model for speculative decoding"""
1104
+ return self._set(modelDraft=modelDraft)
1105
+
1106
+ def setModelAlias(self, modelAlias: str):
1107
+ """Set a model alias"""
1108
+ return self._set(modelAlias=modelAlias)
1109
+
1110
+ # def setLookupCacheStaticFilePath(self, lookupCacheStaticFilePath: str):
1111
+ # """Set path to static lookup cache to use for lookup decoding (not updated by generation)"""
1112
+ # return self._set(lookupCacheStaticFilePath=lookupCacheStaticFilePath)
1113
+
1114
+ # def setLookupCacheDynamicFilePath(self, lookupCacheDynamicFilePath: str):
1115
+ # """Set path to dynamic lookup cache to use for lookup decoding (updated by generation)"""
1116
+ # return self._set(lookupCacheDynamicFilePath=lookupCacheDynamicFilePath)
1117
+
1118
+ def setFlashAttention(self, flashAttention: bool):
1119
+ """Whether to enable Flash Attention"""
1120
+ return self._set(flashAttention=flashAttention)
1121
+
1122
+ # def setInputPrefixBos(self, inputPrefixBos: bool):
1123
+ # """Whether to add prefix BOS to user inputs, preceding the `--in-prefix` string"""
1124
+ # return self._set(inputPrefixBos=inputPrefixBos)
1125
+
1126
+ def setUseMmap(self, useMmap: bool):
1127
+ """Whether to use memory-map model (faster load but may increase pageouts if not using mlock)"""
1128
+ return self._set(useMmap=useMmap)
1129
+
1130
+ def setUseMlock(self, useMlock: bool):
1131
+ """Whether to force the system to keep model in RAM rather than swapping or compressing"""
1132
+ return self._set(useMlock=useMlock)
1133
+
1134
+ def setNoKvOffload(self, noKvOffload: bool):
1135
+ """Whether to disable KV offload"""
1136
+ return self._set(noKvOffload=noKvOffload)
1137
+
1138
+ def setSystemPrompt(self, systemPrompt: str):
1139
+ """Set a system prompt to use"""
1140
+ return self._set(systemPrompt=systemPrompt)
1141
+
1142
+ def setChatTemplate(self, chatTemplate: str):
1143
+ """The chat template to use"""
1144
+ return self._set(chatTemplate=chatTemplate)
1145
+
1146
+ # -------- INFERENCE SETTERS --------
1147
+ def setInputPrefix(self, inputPrefix: str):
1148
+ """Set the prompt to start generation with"""
1149
+ return self._set(inputPrefix=inputPrefix)
1150
+
1151
+ def setInputSuffix(self, inputSuffix: str):
1152
+ """Set a suffix for infilling"""
1153
+ return self._set(inputSuffix=inputSuffix)
1154
+
1155
+ def setCachePrompt(self, cachePrompt: bool):
1156
+ """Whether to remember the prompt to avoid reprocessing it"""
1157
+ return self._set(cachePrompt=cachePrompt)
1158
+
1159
+ def setNPredict(self, nPredict: int):
1160
+ """Set the number of tokens to predict"""
1161
+ return self._set(nPredict=nPredict)
1162
+
1163
+ def setTopK(self, topK: int):
1164
+ """Set top-k sampling"""
1165
+ return self._set(topK=topK)
1166
+
1167
+ def setTopP(self, topP: float):
1168
+ """Set top-p sampling"""
1169
+ return self._set(topP=topP)
1170
+
1171
+ def setMinP(self, minP: float):
1172
+ """Set min-p sampling"""
1173
+ return self._set(minP=minP)
1174
+
1175
+ def setTfsZ(self, tfsZ: float):
1176
+ """Set tail free sampling, parameter z"""
1177
+ return self._set(tfsZ=tfsZ)
1178
+
1179
+ def setTypicalP(self, typicalP: float):
1180
+ """Set locally typical sampling, parameter p"""
1181
+ return self._set(typicalP=typicalP)
1182
+
1183
+ def setTemperature(self, temperature: float):
1184
+ """Set the temperature"""
1185
+ return self._set(temperature=temperature)
1186
+
1187
+ def setDynamicTemperatureRange(self, dynamicTemperatureRange: float):
1188
+ """Set the dynamic temperature range"""
1189
+ return self._set(dynamicTemperatureRange=dynamicTemperatureRange)
1190
+
1191
+ def setDynamicTemperatureExponent(self, dynamicTemperatureExponent: float):
1192
+ """Set the dynamic temperature exponent"""
1193
+ return self._set(dynamicTemperatureExponent=dynamicTemperatureExponent)
1194
+
1195
+ def setRepeatLastN(self, repeatLastN: int):
1196
+ """Set the last n tokens to consider for penalties"""
1197
+ return self._set(repeatLastN=repeatLastN)
1198
+
1199
+ def setRepeatPenalty(self, repeatPenalty: float):
1200
+ """Set the penalty of repeated sequences of tokens"""
1201
+ return self._set(repeatPenalty=repeatPenalty)
1202
+
1203
+ def setFrequencyPenalty(self, frequencyPenalty: float):
1204
+ """Set the repetition alpha frequency penalty"""
1205
+ return self._set(frequencyPenalty=frequencyPenalty)
1206
+
1207
+ def setPresencePenalty(self, presencePenalty: float):
1208
+ """Set the repetition alpha presence penalty"""
1209
+ return self._set(presencePenalty=presencePenalty)
1210
+
1211
+ def setMiroStat(self, miroStat: str):
1212
+ """Set MiroStat sampling strategies."""
1213
+ return self._set(miroStat=miroStat)
1214
+
1215
+ def setMiroStatTau(self, miroStatTau: float):
1216
+ """Set the MiroStat target entropy, parameter tau"""
1217
+ return self._set(miroStatTau=miroStatTau)
1218
+
1219
+ def setMiroStatEta(self, miroStatEta: float):
1220
+ """Set the MiroStat learning rate, parameter eta"""
1221
+ return self._set(miroStatEta=miroStatEta)
1222
+
1223
+ def setPenalizeNl(self, penalizeNl: bool):
1224
+ """Whether to penalize newline tokens"""
1225
+ return self._set(penalizeNl=penalizeNl)
1226
+
1227
+ def setNKeep(self, nKeep: int):
1228
+ """Set the number of tokens to keep from the initial prompt"""
1229
+ return self._set(nKeep=nKeep)
1230
+
1231
+ def setSeed(self, seed: int):
1232
+ """Set the RNG seed"""
1233
+ return self._set(seed=seed)
1234
+
1235
+ def setNProbs(self, nProbs: int):
1236
+ """Set the amount top tokens probabilities to output if greater than 0."""
1237
+ return self._set(nProbs=nProbs)
1238
+
1239
+ def setMinKeep(self, minKeep: int):
1240
+ """Set the amount of tokens the samplers should return at least (0 = disabled)"""
1241
+ return self._set(minKeep=minKeep)
1242
+
1243
+ def setGrammar(self, grammar: str):
1244
+ """Set BNF-like grammar to constrain generations"""
1245
+ return self._set(grammar=grammar)
1246
+
1247
+ def setPenaltyPrompt(self, penaltyPrompt: str):
1248
+ """Override which part of the prompt is penalized for repetition."""
1249
+ return self._set(penaltyPrompt=penaltyPrompt)
1250
+
1251
+ def setIgnoreEos(self, ignoreEos: bool):
1252
+ """Set whether to ignore end of stream token and continue generating (implies --logit-bias 2-inf)"""
1253
+ return self._set(ignoreEos=ignoreEos)
1254
+
1255
+ def setDisableTokenIds(self, disableTokenIds: List[int]):
1256
+ """Set the token ids to disable in the completion"""
1257
+ return self._set(disableTokenIds=disableTokenIds)
1258
+
1259
+ def setStopStrings(self, stopStrings: List[str]):
1260
+ """Set strings upon seeing which token generation is stopped"""
1261
+ return self._set(stopStrings=stopStrings)
1262
+
1263
+ def setSamplers(self, samplers: List[str]):
1264
+ """Set which samplers to use for token generation in the given order"""
1265
+ return self._set(samplers=samplers)
1266
+
1267
+ def setUseChatTemplate(self, useChatTemplate: bool):
1268
+ """Set whether generate should apply a chat template"""
1269
+ return self._set(useChatTemplate=useChatTemplate)
1270
+
1271
+ def setNParallel(self, nParallel: int):
1272
+ """Sets the number of parallel processes for decoding. This is an alias for `setBatchSize`."""
1273
+ return self.setBatchSize(nParallel)
1274
+
1275
+ def setLogVerbosity(self, logVerbosity: int):
1276
+ """Set the log verbosity level"""
1277
+ return self._set(logVerbosity=logVerbosity)
1278
+
1279
+ def setDisableLog(self, disableLog: bool):
1280
+ """Whether to disable logging"""
1281
+ return self._set(disableLog=disableLog)
1282
+
1283
+ # -------- JAVA SETTERS --------
1284
+ def setTokenIdBias(self, tokenIdBias: Dict[int, float]):
1285
+ """Set token id bias"""
1286
+ return self._call_java("setTokenIdBias", tokenIdBias)
1287
+
1288
+ def setTokenBias(self, tokenBias: Dict[str, float]):
1289
+ """Set token id bias"""
1290
+ return self._call_java("setTokenBias", tokenBias)
1291
+
1292
+ # def setLoraAdapters(self, loraAdapters: Dict[str, float]):
1293
+ # """Set LoRA adapters with their scaling factors"""
1294
+ # return self._call_java("setLoraAdapters", loraAdapters)
1295
+
1296
+ def getMetadata(self):
1297
+ """Gets the metadata of the model"""
1298
+ return self._call_java("getMetadata")