forked from chats-bug/hugging_face_peft_gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
89 lines (66 loc) · 3.09 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from pydantic import BaseModel, Field
from typing import Optional, List, Union
class TextGenerationParameters(BaseModel):
"""
top_k: (Default: None).
Integer to define the top tokens considered within the sample operation to create new text.
top_p: (Default: None).
Float to define the tokens that are within the sample operation of text generation.
Add tokens in the sample for more probable to least probable until the sum of the probabilities is greater than top_p.
temperature: (Default: 1.0). Float (0.0-100.0).
The temperature of the sampling operation.
1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.
repetition_penalty: (Default: None). Float (0.0-100.0).
The more a token is used within generation the more it is penalized to not be picked in successive generation passes.
max_new_tokens: (Default: None). Int (0-250).
The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated.
max_time: (Default: None). Float (0-120.0).
The amount of time in seconds that the query should take maximum.
Network can cause some overhead so it will be a soft limit.
Use that in combination with max_new_tokens for best results.
return_full_text: (Default: True). Bool.
If set to False, the return results will not contain the original query making it easier for prompting.
num_return_sequences: (Default: 1). Integer.
The number of proposition you want to be returned.
do_sample: (Optional: True). Bool.
Whether or not to use sampling, use greedy decoding otherwise.
"""
top_k: Optional[int] = Field(default=None, ge=0)
top_p: Optional[float] = Field(default=None, ge=0.0, le=1.0)
temperature: Optional[float] = Field(default=1.0, ge=0.0, le=100.0)
repetition_penalty: Optional[float] = Field(default=None, ge=0.0, le=100.0)
max_new_tokens: Optional[int] = Field(default=None, ge=0, le=4000)
max_time: Optional[float] = Field(default=None, ge=0.0, le=120.0)
return_full_text: Optional[bool] = Field(default=True)
num_return_sequences: Optional[int] = Field(default=1, ge=1)
do_sample: Optional[bool] = Field(default=True)
class Config:
orm_mode = True
"""
Generate a json payload for the class TextGenerationParameters
{
"parameters": {
"top_p": 0.9,
"temperature": 0,
"max_new_tokens": 500,
}
}
"""
class PayloadOptions(BaseModel):
use_cache: bool = False
wait_for_model: bool = True
class Config:
orm_mode = True
class InputPayload(BaseModel):
inputs: Union[str, List[str]]
parameters: TextGenerationParameters = Field(
default_factory=TextGenerationParameters
)
options: PayloadOptions = Field(default_factory=PayloadOptions)
superagi_task_gen: bool = False
class Config:
orm_mode = True
class Output(BaseModel):
generated_text: str
class Config:
orm_mode = True