spark-nlp 5.5.3__py2.py3-none-any.whl → 6.0.0__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.
Potentially problematic release.
This version of spark-nlp might be problematic. Click here for more details.
- {spark_nlp-5.5.3.dist-info → spark_nlp-6.0.0.dist-info}/METADATA +20 -11
- {spark_nlp-5.5.3.dist-info → spark_nlp-6.0.0.dist-info}/RECORD +32 -17
- sparknlp/__init__.py +2 -2
- sparknlp/annotator/classifier_dl/__init__.py +4 -0
- sparknlp/annotator/classifier_dl/albert_for_multiple_choice.py +161 -0
- sparknlp/annotator/classifier_dl/bert_for_multiple_choice.py +2 -2
- sparknlp/annotator/classifier_dl/distilbert_for_multiple_choice.py +161 -0
- sparknlp/annotator/classifier_dl/roberta_for_multiple_choice.py +161 -0
- sparknlp/annotator/classifier_dl/xlm_roberta_for_multiple_choice.py +149 -0
- sparknlp/annotator/cleaners/__init__.py +15 -0
- sparknlp/annotator/cleaners/cleaner.py +202 -0
- sparknlp/annotator/cleaners/extractor.py +191 -0
- sparknlp/annotator/cv/__init__.py +6 -1
- sparknlp/annotator/cv/janus_for_multimodal.py +356 -0
- sparknlp/annotator/cv/llava_for_multimodal.py +328 -0
- sparknlp/annotator/cv/mllama_for_multimodal.py +340 -0
- sparknlp/annotator/cv/phi3_vision_for_multimodal.py +328 -0
- sparknlp/annotator/cv/qwen2vl_transformer.py +332 -0
- sparknlp/annotator/embeddings/auto_gguf_embeddings.py +10 -6
- sparknlp/annotator/seq2seq/__init__.py +3 -0
- sparknlp/annotator/seq2seq/auto_gguf_model.py +8 -503
- sparknlp/annotator/seq2seq/auto_gguf_vision_model.py +333 -0
- sparknlp/annotator/seq2seq/cohere_transformer.py +357 -0
- sparknlp/annotator/seq2seq/llama3_transformer.py +4 -4
- sparknlp/annotator/seq2seq/olmo_transformer.py +326 -0
- sparknlp/base/image_assembler.py +58 -0
- sparknlp/common/properties.py +605 -96
- sparknlp/internal/__init__.py +100 -2
- sparknlp/reader/pdf_to_text.py +65 -0
- sparknlp/reader/sparknlp_reader.py +222 -14
- spark_nlp-5.5.3.dist-info/.uuid +0 -1
- {spark_nlp-5.5.3.dist-info → spark_nlp-6.0.0.dist-info}/WHEEL +0 -0
- {spark_nlp-5.5.3.dist-info → spark_nlp-6.0.0.dist-info}/top_level.txt +0 -0
|
@@ -32,7 +32,7 @@ class AutoGGUFEmbeddings(AnnotatorModel, HasBatchedAnnotate):
|
|
|
32
32
|
... .setInputCols(["document"]) \\
|
|
33
33
|
... .setOutputCol("embeddings")
|
|
34
34
|
|
|
35
|
-
The default model is ``"
|
|
35
|
+
The default model is ``"Nomic_Embed_Text_v1.5.Q8_0.gguf"``, if no name is provided.
|
|
36
36
|
|
|
37
37
|
For extended examples of usage, see the
|
|
38
38
|
`AutoGGUFEmbeddingsTest <https://github.com/JohnSnowLabs/spark-nlp/tree/master/src/test/scala/com/johnsnowlabs/nlp/embeddings/AutoGGUFEmbeddingsTest.scala>`__
|
|
@@ -471,15 +471,19 @@ class AutoGGUFEmbeddings(AnnotatorModel, HasBatchedAnnotate):
|
|
|
471
471
|
"""Whether to disable KV offload"""
|
|
472
472
|
return self._set(noKvOffload=noKvOffload)
|
|
473
473
|
|
|
474
|
+
def setNParallel(self, nParallel: int):
|
|
475
|
+
"""Sets the number of parallel processes for decoding. This is an alias for `setBatchSize`."""
|
|
476
|
+
return self.setBatchSize(nParallel)
|
|
477
|
+
|
|
474
478
|
def getMetadata(self):
|
|
475
479
|
"""Gets the metadata of the model"""
|
|
476
480
|
return self._call_java("getMetadata")
|
|
477
481
|
|
|
478
482
|
@keyword_only
|
|
479
483
|
def __init__(
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
484
|
+
self,
|
|
485
|
+
classname="com.johnsnowlabs.nlp.embeddings.AutoGGUFEmbeddings",
|
|
486
|
+
java_model=None,
|
|
483
487
|
):
|
|
484
488
|
super(AutoGGUFEmbeddings, self).__init__(
|
|
485
489
|
classname=classname, java_model=java_model
|
|
@@ -513,13 +517,13 @@ class AutoGGUFEmbeddings(AnnotatorModel, HasBatchedAnnotate):
|
|
|
513
517
|
return AutoGGUFEmbeddings(java_model=jModel)
|
|
514
518
|
|
|
515
519
|
@staticmethod
|
|
516
|
-
def pretrained(name="
|
|
520
|
+
def pretrained(name="Nomic_Embed_Text_v1.5.Q8_0.gguf", lang="en", remote_loc=None):
|
|
517
521
|
"""Downloads and loads a pretrained model.
|
|
518
522
|
|
|
519
523
|
Parameters
|
|
520
524
|
----------
|
|
521
525
|
name : str, optional
|
|
522
|
-
Name of the pretrained model, by default "
|
|
526
|
+
Name of the pretrained model, by default "Nomic_Embed_Text_v1.5.Q8_0.gguf"
|
|
523
527
|
lang : str, optional
|
|
524
528
|
Language of the pretrained model, by default "en"
|
|
525
529
|
remote_loc : str, optional
|
|
@@ -22,9 +22,12 @@ from sparknlp.annotator.seq2seq.m2m100_transformer import *
|
|
|
22
22
|
from sparknlp.annotator.seq2seq.phi2_transformer import *
|
|
23
23
|
from sparknlp.annotator.seq2seq.mistral_transformer import *
|
|
24
24
|
from sparknlp.annotator.seq2seq.auto_gguf_model import *
|
|
25
|
+
from sparknlp.annotator.seq2seq.auto_gguf_vision_model import *
|
|
25
26
|
from sparknlp.annotator.seq2seq.phi3_transformer import *
|
|
26
27
|
from sparknlp.annotator.seq2seq.nllb_transformer import *
|
|
27
28
|
from sparknlp.annotator.seq2seq.cpm_transformer import *
|
|
28
29
|
from sparknlp.annotator.seq2seq.qwen_transformer import *
|
|
29
30
|
from sparknlp.annotator.seq2seq.starcoder_transformer import *
|
|
30
31
|
from sparknlp.annotator.seq2seq.llama3_transformer import *
|
|
32
|
+
from sparknlp.annotator.seq2seq.cohere_transformer import *
|
|
33
|
+
from sparknlp.annotator.seq2seq.olmo_transformer import *
|
|
@@ -17,7 +17,7 @@ from typing import List, Dict
|
|
|
17
17
|
from sparknlp.common import *
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
class AutoGGUFModel(AnnotatorModel, HasBatchedAnnotate):
|
|
20
|
+
class AutoGGUFModel(AnnotatorModel, HasBatchedAnnotate, HasLlamaCppProperties):
|
|
21
21
|
"""
|
|
22
22
|
Annotator that uses the llama.cpp library to generate text completions with large language
|
|
23
23
|
models.
|
|
@@ -241,507 +241,6 @@ class AutoGGUFModel(AnnotatorModel, HasBatchedAnnotate):
|
|
|
241
241
|
inputAnnotatorTypes = [AnnotatorType.DOCUMENT]
|
|
242
242
|
outputAnnotatorType = AnnotatorType.DOCUMENT
|
|
243
243
|
|
|
244
|
-
# -------- MODEl PARAMETERS --------
|
|
245
|
-
nThreads = Param(Params._dummy(), "nThreads", "Set the number of threads to use during generation",
|
|
246
|
-
typeConverter=TypeConverters.toInt)
|
|
247
|
-
nThreadsDraft = Param(Params._dummy(), "nThreadsDraft", "Set the number of threads to use during draft generation",
|
|
248
|
-
typeConverter=TypeConverters.toInt)
|
|
249
|
-
nThreadsBatch = Param(Params._dummy(), "nThreadsBatch",
|
|
250
|
-
"Set the number of threads to use during batch and prompt processing",
|
|
251
|
-
typeConverter=TypeConverters.toInt)
|
|
252
|
-
nThreadsBatchDraft = Param(Params._dummy(), "nThreadsBatchDraft",
|
|
253
|
-
"Set the number of threads to use during batch and prompt processing",
|
|
254
|
-
typeConverter=TypeConverters.toInt)
|
|
255
|
-
nCtx = Param(Params._dummy(), "nCtx", "Set the size of the prompt context", typeConverter=TypeConverters.toInt)
|
|
256
|
-
nBatch = Param(Params._dummy(), "nBatch",
|
|
257
|
-
"Set the logical batch size for prompt processing (must be >=32 to use BLAS)",
|
|
258
|
-
typeConverter=TypeConverters.toInt)
|
|
259
|
-
nUbatch = Param(Params._dummy(), "nUbatch",
|
|
260
|
-
"Set the physical batch size for prompt processing (must be >=32 to use BLAS)",
|
|
261
|
-
typeConverter=TypeConverters.toInt)
|
|
262
|
-
nDraft = Param(Params._dummy(), "nDraft", "Set the number of tokens to draft for speculative decoding",
|
|
263
|
-
typeConverter=TypeConverters.toInt)
|
|
264
|
-
nChunks = Param(Params._dummy(), "nChunks", "Set the maximal number of chunks to process",
|
|
265
|
-
typeConverter=TypeConverters.toInt)
|
|
266
|
-
nSequences = Param(Params._dummy(), "nSequences", "Set the number of sequences to decode",
|
|
267
|
-
typeConverter=TypeConverters.toInt)
|
|
268
|
-
pSplit = Param(Params._dummy(), "pSplit", "Set the speculative decoding split probability",
|
|
269
|
-
typeConverter=TypeConverters.toFloat)
|
|
270
|
-
nGpuLayers = Param(Params._dummy(), "nGpuLayers", "Set the number of layers to store in VRAM (-1 - use default)",
|
|
271
|
-
typeConverter=TypeConverters.toInt)
|
|
272
|
-
nGpuLayersDraft = Param(Params._dummy(), "nGpuLayersDraft",
|
|
273
|
-
"Set the number of layers to store in VRAM for the draft model (-1 - use default)",
|
|
274
|
-
typeConverter=TypeConverters.toInt)
|
|
275
|
-
# Set how to split the model across GPUs
|
|
276
|
-
#
|
|
277
|
-
# - NONE: No GPU split
|
|
278
|
-
# - LAYER: Split the model across GPUs by layer
|
|
279
|
-
# - ROW: Split the model across GPUs by rows
|
|
280
|
-
gpuSplitMode = Param(Params._dummy(), "gpuSplitMode", "Set how to split the model across GPUs",
|
|
281
|
-
typeConverter=TypeConverters.toString)
|
|
282
|
-
mainGpu = Param(Params._dummy(), "mainGpu", "Set the main GPU that is used for scratch and small tensors.",
|
|
283
|
-
typeConverter=TypeConverters.toInt)
|
|
284
|
-
tensorSplit = Param(Params._dummy(), "tensorSplit", "Set how split tensors should be distributed across GPUs",
|
|
285
|
-
typeConverter=TypeConverters.toListFloat)
|
|
286
|
-
grpAttnN = Param(Params._dummy(), "grpAttnN", "Set the group-attention factor", typeConverter=TypeConverters.toInt)
|
|
287
|
-
grpAttnW = Param(Params._dummy(), "grpAttnW", "Set the group-attention width", typeConverter=TypeConverters.toInt)
|
|
288
|
-
ropeFreqBase = Param(Params._dummy(), "ropeFreqBase", "Set the RoPE base frequency, used by NTK-aware scaling",
|
|
289
|
-
typeConverter=TypeConverters.toFloat)
|
|
290
|
-
ropeFreqScale = Param(Params._dummy(), "ropeFreqScale",
|
|
291
|
-
"Set the RoPE frequency scaling factor, expands context by a factor of 1/N",
|
|
292
|
-
typeConverter=TypeConverters.toFloat)
|
|
293
|
-
yarnExtFactor = Param(Params._dummy(), "yarnExtFactor", "Set the YaRN extrapolation mix factor",
|
|
294
|
-
typeConverter=TypeConverters.toFloat)
|
|
295
|
-
yarnAttnFactor = Param(Params._dummy(), "yarnAttnFactor", "Set the YaRN scale sqrt(t) or attention magnitude",
|
|
296
|
-
typeConverter=TypeConverters.toFloat)
|
|
297
|
-
yarnBetaFast = Param(Params._dummy(), "yarnBetaFast", "Set the YaRN low correction dim or beta",
|
|
298
|
-
typeConverter=TypeConverters.toFloat)
|
|
299
|
-
yarnBetaSlow = Param(Params._dummy(), "yarnBetaSlow", "Set the YaRN high correction dim or alpha",
|
|
300
|
-
typeConverter=TypeConverters.toFloat)
|
|
301
|
-
yarnOrigCtx = Param(Params._dummy(), "yarnOrigCtx", "Set the YaRN original context size of model",
|
|
302
|
-
typeConverter=TypeConverters.toInt)
|
|
303
|
-
defragmentationThreshold = Param(Params._dummy(), "defragmentationThreshold",
|
|
304
|
-
"Set the KV cache defragmentation threshold", typeConverter=TypeConverters.toFloat)
|
|
305
|
-
# Set optimization strategies that help on some NUMA systems (if available)
|
|
306
|
-
#
|
|
307
|
-
# Available Strategies:
|
|
308
|
-
#
|
|
309
|
-
# - DISABLED: No NUMA optimizations
|
|
310
|
-
# - DISTRIBUTE: Spread execution evenly over all
|
|
311
|
-
# - ISOLATE: Only spawn threads on CPUs on the node that execution started on
|
|
312
|
-
# - NUMA_CTL: Use the CPU map provided by numactl
|
|
313
|
-
# - MIRROR: Mirrors the model across NUMA nodes
|
|
314
|
-
numaStrategy = Param(Params._dummy(), "numaStrategy",
|
|
315
|
-
"Set optimization strategies that help on some NUMA systems (if available)",
|
|
316
|
-
typeConverter=TypeConverters.toString)
|
|
317
|
-
# Set the RoPE frequency scaling method, defaults to linear unless specified by the model.
|
|
318
|
-
#
|
|
319
|
-
# - UNSPECIFIED: Don't use any scaling
|
|
320
|
-
# - LINEAR: Linear scaling
|
|
321
|
-
# - YARN: YaRN RoPE scaling
|
|
322
|
-
ropeScalingType = Param(Params._dummy(), "ropeScalingType",
|
|
323
|
-
"Set the RoPE frequency scaling method, defaults to linear unless specified by the model",
|
|
324
|
-
typeConverter=TypeConverters.toString)
|
|
325
|
-
# Set the pooling type for embeddings, use model default if unspecified
|
|
326
|
-
#
|
|
327
|
-
# - 0 UNSPECIFIED: Don't use any pooling
|
|
328
|
-
# - 1 MEAN: Mean Pooling
|
|
329
|
-
# - 2 CLS: CLS Pooling
|
|
330
|
-
poolingType = Param(Params._dummy(), "poolingType",
|
|
331
|
-
"Set the pooling type for embeddings, use model default if unspecified",
|
|
332
|
-
typeConverter=TypeConverters.toString)
|
|
333
|
-
modelDraft = Param(Params._dummy(), "modelDraft", "Set the draft model for speculative decoding",
|
|
334
|
-
typeConverter=TypeConverters.toString)
|
|
335
|
-
modelAlias = Param(Params._dummy(), "modelAlias", "Set a model alias", typeConverter=TypeConverters.toString)
|
|
336
|
-
lookupCacheStaticFilePath = Param(Params._dummy(), "lookupCacheStaticFilePath",
|
|
337
|
-
"Set path to static lookup cache to use for lookup decoding (not updated by generation)",
|
|
338
|
-
typeConverter=TypeConverters.toString)
|
|
339
|
-
lookupCacheDynamicFilePath = Param(Params._dummy(), "lookupCacheDynamicFilePath",
|
|
340
|
-
"Set path to dynamic lookup cache to use for lookup decoding (updated by generation)",
|
|
341
|
-
typeConverter=TypeConverters.toString)
|
|
342
|
-
# loraAdapters = new StructFeature[Map[String, Float]](this, "loraAdapters")
|
|
343
|
-
embedding = Param(Params._dummy(), "embedding", "Whether to load model with embedding support",
|
|
344
|
-
typeConverter=TypeConverters.toBoolean)
|
|
345
|
-
flashAttention = Param(Params._dummy(), "flashAttention", "Whether to enable Flash Attention",
|
|
346
|
-
typeConverter=TypeConverters.toBoolean)
|
|
347
|
-
inputPrefixBos = Param(Params._dummy(), "inputPrefixBos",
|
|
348
|
-
"Whether to add prefix BOS to user inputs, preceding the `--in-prefix` string",
|
|
349
|
-
typeConverter=TypeConverters.toBoolean)
|
|
350
|
-
useMmap = Param(Params._dummy(), "useMmap",
|
|
351
|
-
"Whether to use memory-map model (faster load but may increase pageouts if not using mlock)",
|
|
352
|
-
typeConverter=TypeConverters.toBoolean)
|
|
353
|
-
useMlock = Param(Params._dummy(), "useMlock",
|
|
354
|
-
"Whether to force the system to keep model in RAM rather than swapping or compressing",
|
|
355
|
-
typeConverter=TypeConverters.toBoolean)
|
|
356
|
-
noKvOffload = Param(Params._dummy(), "noKvOffload", "Whether to disable KV offload",
|
|
357
|
-
typeConverter=TypeConverters.toBoolean)
|
|
358
|
-
systemPrompt = Param(Params._dummy(), "systemPrompt", "Set a system prompt to use",
|
|
359
|
-
typeConverter=TypeConverters.toString)
|
|
360
|
-
chatTemplate = Param(Params._dummy(), "chatTemplate", "The chat template to use",
|
|
361
|
-
typeConverter=TypeConverters.toString)
|
|
362
|
-
|
|
363
|
-
# -------- INFERENCE PARAMETERS --------
|
|
364
|
-
inputPrefix = Param(Params._dummy(), "inputPrefix", "Set the prompt to start generation with",
|
|
365
|
-
typeConverter=TypeConverters.toString)
|
|
366
|
-
inputSuffix = Param(Params._dummy(), "inputSuffix", "Set a suffix for infilling",
|
|
367
|
-
typeConverter=TypeConverters.toString)
|
|
368
|
-
cachePrompt = Param(Params._dummy(), "cachePrompt", "Whether to remember the prompt to avoid reprocessing it",
|
|
369
|
-
typeConverter=TypeConverters.toBoolean)
|
|
370
|
-
nPredict = Param(Params._dummy(), "nPredict", "Set the number of tokens to predict",
|
|
371
|
-
typeConverter=TypeConverters.toInt)
|
|
372
|
-
topK = Param(Params._dummy(), "topK", "Set top-k sampling", typeConverter=TypeConverters.toInt)
|
|
373
|
-
topP = Param(Params._dummy(), "topP", "Set top-p sampling", typeConverter=TypeConverters.toFloat)
|
|
374
|
-
minP = Param(Params._dummy(), "minP", "Set min-p sampling", typeConverter=TypeConverters.toFloat)
|
|
375
|
-
tfsZ = Param(Params._dummy(), "tfsZ", "Set tail free sampling, parameter z", typeConverter=TypeConverters.toFloat)
|
|
376
|
-
typicalP = Param(Params._dummy(), "typicalP", "Set locally typical sampling, parameter p",
|
|
377
|
-
typeConverter=TypeConverters.toFloat)
|
|
378
|
-
temperature = Param(Params._dummy(), "temperature", "Set the temperature", typeConverter=TypeConverters.toFloat)
|
|
379
|
-
dynamicTemperatureRange = Param(Params._dummy(), "dynatempRange", "Set the dynamic temperature range",
|
|
380
|
-
typeConverter=TypeConverters.toFloat)
|
|
381
|
-
dynamicTemperatureExponent = Param(Params._dummy(), "dynatempExponent", "Set the dynamic temperature exponent",
|
|
382
|
-
typeConverter=TypeConverters.toFloat)
|
|
383
|
-
repeatLastN = Param(Params._dummy(), "repeatLastN", "Set the last n tokens to consider for penalties",
|
|
384
|
-
typeConverter=TypeConverters.toInt)
|
|
385
|
-
repeatPenalty = Param(Params._dummy(), "repeatPenalty", "Set the penalty of repeated sequences of tokens",
|
|
386
|
-
typeConverter=TypeConverters.toFloat)
|
|
387
|
-
frequencyPenalty = Param(Params._dummy(), "frequencyPenalty", "Set the repetition alpha frequency penalty",
|
|
388
|
-
typeConverter=TypeConverters.toFloat)
|
|
389
|
-
presencePenalty = Param(Params._dummy(), "presencePenalty", "Set the repetition alpha presence penalty",
|
|
390
|
-
typeConverter=TypeConverters.toFloat)
|
|
391
|
-
miroStat = Param(Params._dummy(), "miroStat", "Set MiroStat sampling strategies.",
|
|
392
|
-
typeConverter=TypeConverters.toString)
|
|
393
|
-
miroStatTau = Param(Params._dummy(), "mirostatTau", "Set the MiroStat target entropy, parameter tau",
|
|
394
|
-
typeConverter=TypeConverters.toFloat)
|
|
395
|
-
miroStatEta = Param(Params._dummy(), "mirostatEta", "Set the MiroStat learning rate, parameter eta",
|
|
396
|
-
typeConverter=TypeConverters.toFloat)
|
|
397
|
-
penalizeNl = Param(Params._dummy(), "penalizeNl", "Whether to penalize newline tokens",
|
|
398
|
-
typeConverter=TypeConverters.toBoolean)
|
|
399
|
-
nKeep = Param(Params._dummy(), "nKeep", "Set the number of tokens to keep from the initial prompt",
|
|
400
|
-
typeConverter=TypeConverters.toInt)
|
|
401
|
-
seed = Param(Params._dummy(), "seed", "Set the RNG seed", typeConverter=TypeConverters.toInt)
|
|
402
|
-
nProbs = Param(Params._dummy(), "nProbs", "Set the amount top tokens probabilities to output if greater than 0.",
|
|
403
|
-
typeConverter=TypeConverters.toInt)
|
|
404
|
-
minKeep = Param(Params._dummy(), "minKeep",
|
|
405
|
-
"Set the amount of tokens the samplers should return at least (0 = disabled)",
|
|
406
|
-
typeConverter=TypeConverters.toInt)
|
|
407
|
-
grammar = Param(Params._dummy(), "grammar", "Set BNF-like grammar to constrain generations",
|
|
408
|
-
typeConverter=TypeConverters.toString)
|
|
409
|
-
penaltyPrompt = Param(Params._dummy(), "penaltyPrompt",
|
|
410
|
-
"Override which part of the prompt is penalized for repetition.",
|
|
411
|
-
typeConverter=TypeConverters.toString)
|
|
412
|
-
ignoreEos = Param(Params._dummy(), "ignoreEos",
|
|
413
|
-
"Set whether to ignore end of stream token and continue generating (implies --logit-bias 2-inf)",
|
|
414
|
-
typeConverter=TypeConverters.toBoolean)
|
|
415
|
-
disableTokenIds = Param(Params._dummy(), "disableTokenIds", "Set the token ids to disable in the completion",
|
|
416
|
-
typeConverter=TypeConverters.toListInt)
|
|
417
|
-
stopStrings = Param(Params._dummy(), "stopStrings", "Set strings upon seeing which token generation is stopped",
|
|
418
|
-
typeConverter=TypeConverters.toListString)
|
|
419
|
-
samplers = Param(Params._dummy(), "samplers", "Set which samplers to use for token generation in the given order",
|
|
420
|
-
typeConverter=TypeConverters.toListString)
|
|
421
|
-
useChatTemplate = Param(Params._dummy(), "useChatTemplate",
|
|
422
|
-
"Set whether or not generate should apply a chat template",
|
|
423
|
-
typeConverter=TypeConverters.toBoolean)
|
|
424
|
-
|
|
425
|
-
# -------- MODEL SETTERS --------
|
|
426
|
-
def setNThreads(self, nThreads: int):
|
|
427
|
-
"""Set the number of threads to use during generation"""
|
|
428
|
-
return self._set(nThreads=nThreads)
|
|
429
|
-
|
|
430
|
-
def setNThreadsDraft(self, nThreadsDraft: int):
|
|
431
|
-
"""Set the number of threads to use during draft generation"""
|
|
432
|
-
return self._set(nThreadsDraft=nThreadsDraft)
|
|
433
|
-
|
|
434
|
-
def setNThreadsBatch(self, nThreadsBatch: int):
|
|
435
|
-
"""Set the number of threads to use during batch and prompt processing"""
|
|
436
|
-
return self._set(nThreadsBatch=nThreadsBatch)
|
|
437
|
-
|
|
438
|
-
def setNThreadsBatchDraft(self, nThreadsBatchDraft: int):
|
|
439
|
-
"""Set the number of threads to use during batch and prompt processing"""
|
|
440
|
-
return self._set(nThreadsBatchDraft=nThreadsBatchDraft)
|
|
441
|
-
|
|
442
|
-
def setNCtx(self, nCtx: int):
|
|
443
|
-
"""Set the size of the prompt context"""
|
|
444
|
-
return self._set(nCtx=nCtx)
|
|
445
|
-
|
|
446
|
-
def setNBatch(self, nBatch: int):
|
|
447
|
-
"""Set the logical batch size for prompt processing (must be >=32 to use BLAS)"""
|
|
448
|
-
return self._set(nBatch=nBatch)
|
|
449
|
-
|
|
450
|
-
def setNUbatch(self, nUbatch: int):
|
|
451
|
-
"""Set the physical batch size for prompt processing (must be >=32 to use BLAS)"""
|
|
452
|
-
return self._set(nUbatch=nUbatch)
|
|
453
|
-
|
|
454
|
-
def setNDraft(self, nDraft: int):
|
|
455
|
-
"""Set the number of tokens to draft for speculative decoding"""
|
|
456
|
-
return self._set(nDraft=nDraft)
|
|
457
|
-
|
|
458
|
-
def setNChunks(self, nChunks: int):
|
|
459
|
-
"""Set the maximal number of chunks to process"""
|
|
460
|
-
return self._set(nChunks=nChunks)
|
|
461
|
-
|
|
462
|
-
def setNSequences(self, nSequences: int):
|
|
463
|
-
"""Set the number of sequences to decode"""
|
|
464
|
-
return self._set(nSequences=nSequences)
|
|
465
|
-
|
|
466
|
-
def setPSplit(self, pSplit: float):
|
|
467
|
-
"""Set the speculative decoding split probability"""
|
|
468
|
-
return self._set(pSplit=pSplit)
|
|
469
|
-
|
|
470
|
-
def setNGpuLayers(self, nGpuLayers: int):
|
|
471
|
-
"""Set the number of layers to store in VRAM (-1 - use default)"""
|
|
472
|
-
return self._set(nGpuLayers=nGpuLayers)
|
|
473
|
-
|
|
474
|
-
def setNGpuLayersDraft(self, nGpuLayersDraft: int):
|
|
475
|
-
"""Set the number of layers to store in VRAM for the draft model (-1 - use default)"""
|
|
476
|
-
return self._set(nGpuLayersDraft=nGpuLayersDraft)
|
|
477
|
-
|
|
478
|
-
def setGpuSplitMode(self, gpuSplitMode: str):
|
|
479
|
-
"""Set how to split the model across GPUs"""
|
|
480
|
-
return self._set(gpuSplitMode=gpuSplitMode)
|
|
481
|
-
|
|
482
|
-
def setMainGpu(self, mainGpu: int):
|
|
483
|
-
"""Set the main GPU that is used for scratch and small tensors."""
|
|
484
|
-
return self._set(mainGpu=mainGpu)
|
|
485
|
-
|
|
486
|
-
def setTensorSplit(self, tensorSplit: List[float]):
|
|
487
|
-
"""Set how split tensors should be distributed across GPUs"""
|
|
488
|
-
return self._set(tensorSplit=tensorSplit)
|
|
489
|
-
|
|
490
|
-
def setGrpAttnN(self, grpAttnN: int):
|
|
491
|
-
"""Set the group-attention factor"""
|
|
492
|
-
return self._set(grpAttnN=grpAttnN)
|
|
493
|
-
|
|
494
|
-
def setGrpAttnW(self, grpAttnW: int):
|
|
495
|
-
"""Set the group-attention width"""
|
|
496
|
-
return self._set(grpAttnW=grpAttnW)
|
|
497
|
-
|
|
498
|
-
def setRopeFreqBase(self, ropeFreqBase: float):
|
|
499
|
-
"""Set the RoPE base frequency, used by NTK-aware scaling"""
|
|
500
|
-
return self._set(ropeFreqBase=ropeFreqBase)
|
|
501
|
-
|
|
502
|
-
def setRopeFreqScale(self, ropeFreqScale: float):
|
|
503
|
-
"""Set the RoPE frequency scaling factor, expands context by a factor of 1/N"""
|
|
504
|
-
return self._set(ropeFreqScale=ropeFreqScale)
|
|
505
|
-
|
|
506
|
-
def setYarnExtFactor(self, yarnExtFactor: float):
|
|
507
|
-
"""Set the YaRN extrapolation mix factor"""
|
|
508
|
-
return self._set(yarnExtFactor=yarnExtFactor)
|
|
509
|
-
|
|
510
|
-
def setYarnAttnFactor(self, yarnAttnFactor: float):
|
|
511
|
-
"""Set the YaRN scale sqrt(t) or attention magnitude"""
|
|
512
|
-
return self._set(yarnAttnFactor=yarnAttnFactor)
|
|
513
|
-
|
|
514
|
-
def setYarnBetaFast(self, yarnBetaFast: float):
|
|
515
|
-
"""Set the YaRN low correction dim or beta"""
|
|
516
|
-
return self._set(yarnBetaFast=yarnBetaFast)
|
|
517
|
-
|
|
518
|
-
def setYarnBetaSlow(self, yarnBetaSlow: float):
|
|
519
|
-
"""Set the YaRN high correction dim or alpha"""
|
|
520
|
-
return self._set(yarnBetaSlow=yarnBetaSlow)
|
|
521
|
-
|
|
522
|
-
def setYarnOrigCtx(self, yarnOrigCtx: int):
|
|
523
|
-
"""Set the YaRN original context size of model"""
|
|
524
|
-
return self._set(yarnOrigCtx=yarnOrigCtx)
|
|
525
|
-
|
|
526
|
-
def setDefragmentationThreshold(self, defragmentationThreshold: float):
|
|
527
|
-
"""Set the KV cache defragmentation threshold"""
|
|
528
|
-
return self._set(defragmentationThreshold=defragmentationThreshold)
|
|
529
|
-
|
|
530
|
-
def setNumaStrategy(self, numaStrategy: str):
|
|
531
|
-
"""Set optimization strategies that help on some NUMA systems (if available)"""
|
|
532
|
-
numaUpper = numaStrategy.upper()
|
|
533
|
-
numaStrategies = ["DISABLED", "DISTRIBUTE", "ISOLATE", "NUMA_CTL", "MIRROR"]
|
|
534
|
-
if numaUpper not in numaStrategies:
|
|
535
|
-
raise ValueError(
|
|
536
|
-
f"Invalid NUMA strategy: {numaUpper}. "
|
|
537
|
-
+ f"Valid values are: {numaStrategies}"
|
|
538
|
-
)
|
|
539
|
-
return self._set(numaStrategy=numaStrategy)
|
|
540
|
-
|
|
541
|
-
def setRopeScalingType(self, ropeScalingType: str):
|
|
542
|
-
"""Set the RoPE frequency scaling method, defaults to linear unless specified by the model"""
|
|
543
|
-
return self._set(ropeScalingType=ropeScalingType)
|
|
544
|
-
|
|
545
|
-
def setPoolingType(self, poolingType: bool):
|
|
546
|
-
"""Set the pooling type for embeddings, use model default if unspecified"""
|
|
547
|
-
poolingTypeUpper = poolingType.upper()
|
|
548
|
-
poolingTypes = ["NONE", "MEAN", "CLS", "LAST"]
|
|
549
|
-
if poolingTypeUpper not in poolingTypes:
|
|
550
|
-
raise ValueError(
|
|
551
|
-
f"Invalid pooling type: {poolingType}. "
|
|
552
|
-
+ f"Valid values are: {poolingTypes}"
|
|
553
|
-
)
|
|
554
|
-
return self._set(poolingType=poolingType)
|
|
555
|
-
|
|
556
|
-
def setModelDraft(self, modelDraft: str):
|
|
557
|
-
"""Set the draft model for speculative decoding"""
|
|
558
|
-
return self._set(modelDraft=modelDraft)
|
|
559
|
-
|
|
560
|
-
def setModelAlias(self, modelAlias: str):
|
|
561
|
-
"""Set a model alias"""
|
|
562
|
-
return self._set(modelAlias=modelAlias)
|
|
563
|
-
|
|
564
|
-
def setLookupCacheStaticFilePath(self, lookupCacheStaticFilePath: str):
|
|
565
|
-
"""Set path to static lookup cache to use for lookup decoding (not updated by generation)"""
|
|
566
|
-
return self._set(lookupCacheStaticFilePath=lookupCacheStaticFilePath)
|
|
567
|
-
|
|
568
|
-
def setLookupCacheDynamicFilePath(self, lookupCacheDynamicFilePath: str):
|
|
569
|
-
"""Set path to dynamic lookup cache to use for lookup decoding (updated by generation)"""
|
|
570
|
-
return self._set(lookupCacheDynamicFilePath=lookupCacheDynamicFilePath)
|
|
571
|
-
|
|
572
|
-
def setEmbedding(self, embedding: bool):
|
|
573
|
-
"""Whether to load model with embedding support"""
|
|
574
|
-
return self._set(embedding=embedding)
|
|
575
|
-
|
|
576
|
-
def setFlashAttention(self, flashAttention: bool):
|
|
577
|
-
"""Whether to enable Flash Attention"""
|
|
578
|
-
return self._set(flashAttention=flashAttention)
|
|
579
|
-
|
|
580
|
-
def setInputPrefixBos(self, inputPrefixBos: bool):
|
|
581
|
-
"""Whether to add prefix BOS to user inputs, preceding the `--in-prefix` bool"""
|
|
582
|
-
return self._set(inputPrefixBos=inputPrefixBos)
|
|
583
|
-
|
|
584
|
-
def setUseMmap(self, useMmap: bool):
|
|
585
|
-
"""Whether to use memory-map model (faster load but may increase pageouts if not using mlock)"""
|
|
586
|
-
return self._set(useMmap=useMmap)
|
|
587
|
-
|
|
588
|
-
def setUseMlock(self, useMlock: bool):
|
|
589
|
-
"""Whether to force the system to keep model in RAM rather than swapping or compressing"""
|
|
590
|
-
return self._set(useMlock=useMlock)
|
|
591
|
-
|
|
592
|
-
def setNoKvOffload(self, noKvOffload: bool):
|
|
593
|
-
"""Whether to disable KV offload"""
|
|
594
|
-
return self._set(noKvOffload=noKvOffload)
|
|
595
|
-
|
|
596
|
-
def setSystemPrompt(self, systemPrompt: bool):
|
|
597
|
-
"""Set a system prompt to use"""
|
|
598
|
-
return self._set(systemPrompt=systemPrompt)
|
|
599
|
-
|
|
600
|
-
def setChatTemplate(self, chatTemplate: str):
|
|
601
|
-
"""The chat template to use"""
|
|
602
|
-
return self._set(chatTemplate=chatTemplate)
|
|
603
|
-
|
|
604
|
-
# -------- INFERENCE SETTERS --------
|
|
605
|
-
def setInputPrefix(self, inputPrefix: str):
|
|
606
|
-
"""Set the prompt to start generation with"""
|
|
607
|
-
return self._set(inputPrefix=inputPrefix)
|
|
608
|
-
|
|
609
|
-
def setInputSuffix(self, inputSuffix: str):
|
|
610
|
-
"""Set a suffix for infilling"""
|
|
611
|
-
return self._set(inputSuffix=inputSuffix)
|
|
612
|
-
|
|
613
|
-
def setCachePrompt(self, cachePrompt: bool):
|
|
614
|
-
"""Whether to remember the prompt to avoid reprocessing it"""
|
|
615
|
-
return self._set(cachePrompt=cachePrompt)
|
|
616
|
-
|
|
617
|
-
def setNPredict(self, nPredict: int):
|
|
618
|
-
"""Set the number of tokens to predict"""
|
|
619
|
-
return self._set(nPredict=nPredict)
|
|
620
|
-
|
|
621
|
-
def setTopK(self, topK: int):
|
|
622
|
-
"""Set top-k sampling"""
|
|
623
|
-
return self._set(topK=topK)
|
|
624
|
-
|
|
625
|
-
def setTopP(self, topP: float):
|
|
626
|
-
"""Set top-p sampling"""
|
|
627
|
-
return self._set(topP=topP)
|
|
628
|
-
|
|
629
|
-
def setMinP(self, minP: float):
|
|
630
|
-
"""Set min-p sampling"""
|
|
631
|
-
return self._set(minP=minP)
|
|
632
|
-
|
|
633
|
-
def setTfsZ(self, tfsZ: float):
|
|
634
|
-
"""Set tail free sampling, parameter z"""
|
|
635
|
-
return self._set(tfsZ=tfsZ)
|
|
636
|
-
|
|
637
|
-
def setTypicalP(self, typicalP: float):
|
|
638
|
-
"""Set locally typical sampling, parameter p"""
|
|
639
|
-
return self._set(typicalP=typicalP)
|
|
640
|
-
|
|
641
|
-
def setTemperature(self, temperature: float):
|
|
642
|
-
"""Set the temperature"""
|
|
643
|
-
return self._set(temperature=temperature)
|
|
644
|
-
|
|
645
|
-
def setDynamicTemperatureRange(self, dynamicTemperatureRange: float):
|
|
646
|
-
"""Set the dynamic temperature range"""
|
|
647
|
-
return self._set(dynamicTemperatureRange=dynamicTemperatureRange)
|
|
648
|
-
|
|
649
|
-
def setDynamicTemperatureExponent(self, dynamicTemperatureExponent: float):
|
|
650
|
-
"""Set the dynamic temperature exponent"""
|
|
651
|
-
return self._set(dynamicTemperatureExponent=dynamicTemperatureExponent)
|
|
652
|
-
|
|
653
|
-
def setRepeatLastN(self, repeatLastN: int):
|
|
654
|
-
"""Set the last n tokens to consider for penalties"""
|
|
655
|
-
return self._set(repeatLastN=repeatLastN)
|
|
656
|
-
|
|
657
|
-
def setRepeatPenalty(self, repeatPenalty: float):
|
|
658
|
-
"""Set the penalty of repeated sequences of tokens"""
|
|
659
|
-
return self._set(repeatPenalty=repeatPenalty)
|
|
660
|
-
|
|
661
|
-
def setFrequencyPenalty(self, frequencyPenalty: float):
|
|
662
|
-
"""Set the repetition alpha frequency penalty"""
|
|
663
|
-
return self._set(frequencyPenalty=frequencyPenalty)
|
|
664
|
-
|
|
665
|
-
def setPresencePenalty(self, presencePenalty: float):
|
|
666
|
-
"""Set the repetition alpha presence penalty"""
|
|
667
|
-
return self._set(presencePenalty=presencePenalty)
|
|
668
|
-
|
|
669
|
-
def setMiroStat(self, miroStat: str):
|
|
670
|
-
"""Set MiroStat sampling strategies."""
|
|
671
|
-
return self._set(miroStat=miroStat)
|
|
672
|
-
|
|
673
|
-
def setMiroStatTau(self, miroStatTau: float):
|
|
674
|
-
"""Set the MiroStat target entropy, parameter tau"""
|
|
675
|
-
return self._set(miroStatTau=miroStatTau)
|
|
676
|
-
|
|
677
|
-
def setMiroStatEta(self, miroStatEta: float):
|
|
678
|
-
"""Set the MiroStat learning rate, parameter eta"""
|
|
679
|
-
return self._set(miroStatEta=miroStatEta)
|
|
680
|
-
|
|
681
|
-
def setPenalizeNl(self, penalizeNl: bool):
|
|
682
|
-
"""Whether to penalize newline tokens"""
|
|
683
|
-
return self._set(penalizeNl=penalizeNl)
|
|
684
|
-
|
|
685
|
-
def setNKeep(self, nKeep: int):
|
|
686
|
-
"""Set the number of tokens to keep from the initial prompt"""
|
|
687
|
-
return self._set(nKeep=nKeep)
|
|
688
|
-
|
|
689
|
-
def setSeed(self, seed: int):
|
|
690
|
-
"""Set the RNG seed"""
|
|
691
|
-
return self._set(seed=seed)
|
|
692
|
-
|
|
693
|
-
def setNProbs(self, nProbs: int):
|
|
694
|
-
"""Set the amount top tokens probabilities to output if greater than 0."""
|
|
695
|
-
return self._set(nProbs=nProbs)
|
|
696
|
-
|
|
697
|
-
def setMinKeep(self, minKeep: int):
|
|
698
|
-
"""Set the amount of tokens the samplers should return at least (0 = disabled)"""
|
|
699
|
-
return self._set(minKeep=minKeep)
|
|
700
|
-
|
|
701
|
-
def setGrammar(self, grammar: bool):
|
|
702
|
-
"""Set BNF-like grammar to constrain generations"""
|
|
703
|
-
return self._set(grammar=grammar)
|
|
704
|
-
|
|
705
|
-
def setPenaltyPrompt(self, penaltyPrompt: str):
|
|
706
|
-
"""Override which part of the prompt is penalized for repetition."""
|
|
707
|
-
return self._set(penaltyPrompt=penaltyPrompt)
|
|
708
|
-
|
|
709
|
-
def setIgnoreEos(self, ignoreEos: bool):
|
|
710
|
-
"""Set whether to ignore end of stream token and continue generating (implies --logit-bias 2-inf)"""
|
|
711
|
-
return self._set(ignoreEos=ignoreEos)
|
|
712
|
-
|
|
713
|
-
def setDisableTokenIds(self, disableTokenIds: List[int]):
|
|
714
|
-
"""Set the token ids to disable in the completion"""
|
|
715
|
-
return self._set(disableTokenIds=disableTokenIds)
|
|
716
|
-
|
|
717
|
-
def setStopStrings(self, stopStrings: List[str]):
|
|
718
|
-
"""Set strings upon seeing which token generation is stopped"""
|
|
719
|
-
return self._set(stopStrings=stopStrings)
|
|
720
|
-
|
|
721
|
-
def setSamplers(self, samplers: List[str]):
|
|
722
|
-
"""Set which samplers to use for token generation in the given order"""
|
|
723
|
-
return self._set(samplers=samplers)
|
|
724
|
-
|
|
725
|
-
def setUseChatTemplate(self, useChatTemplate: bool):
|
|
726
|
-
"""Set whether generate should apply a chat template"""
|
|
727
|
-
return self._set(useChatTemplate=useChatTemplate)
|
|
728
|
-
|
|
729
|
-
# -------- JAVA SETTERS --------
|
|
730
|
-
def setTokenIdBias(self, tokenIdBias: Dict[int, float]):
|
|
731
|
-
"""Set token id bias"""
|
|
732
|
-
return self._call_java("setTokenIdBias", tokenIdBias)
|
|
733
|
-
|
|
734
|
-
def setTokenBias(self, tokenBias: Dict[str, float]):
|
|
735
|
-
"""Set token id bias"""
|
|
736
|
-
return self._call_java("setTokenBias", tokenBias)
|
|
737
|
-
|
|
738
|
-
def setLoraAdapters(self, loraAdapters: Dict[str, float]):
|
|
739
|
-
"""Set token id bias"""
|
|
740
|
-
return self._call_java("setLoraAdapters", loraAdapters)
|
|
741
|
-
|
|
742
|
-
def getMetadata(self):
|
|
743
|
-
"""Gets the metadata of the model"""
|
|
744
|
-
return self._call_java("getMetadata")
|
|
745
244
|
|
|
746
245
|
@keyword_only
|
|
747
246
|
def __init__(self, classname="com.johnsnowlabs.nlp.annotators.seq2seq.AutoGGUFModel", java_model=None):
|
|
@@ -749,7 +248,13 @@ class AutoGGUFModel(AnnotatorModel, HasBatchedAnnotate):
|
|
|
749
248
|
classname=classname,
|
|
750
249
|
java_model=java_model
|
|
751
250
|
)
|
|
752
|
-
|
|
251
|
+
self._setDefault(
|
|
252
|
+
useChatTemplate=True,
|
|
253
|
+
nCtx=4096,
|
|
254
|
+
nBatch=512,
|
|
255
|
+
embedding=False,
|
|
256
|
+
nPredict=100
|
|
257
|
+
)
|
|
753
258
|
|
|
754
259
|
@staticmethod
|
|
755
260
|
def loadSavedModel(folder, spark_session):
|