webscout 2.2b0__py3-none-any.whl → 2.3__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 webscout might be problematic. Click here for more details.

@@ -0,0 +1,161 @@
1
+
2
+ from ._version import __version__, __llama_cpp_version__
3
+
4
+ """Submodule containing SamplerSettings class and some preset samplers"""
5
+
6
+ from sys import maxsize
7
+
8
+
9
+ MAX_TEMP = float(maxsize)
10
+
11
+ class SamplerSettings:
12
+ """
13
+ A SamplerSettings object specifies the sampling parameters that will be
14
+ used to control text generation
15
+ """
16
+
17
+ ParamTypes: dict[str, type] = {
18
+ 'max_len_tokens': int,
19
+ 'temp': float,
20
+ 'top_p': float,
21
+ 'min_p': float,
22
+ 'frequency_penalty': float,
23
+ 'presence_penalty': float,
24
+ 'repeat_penalty': float,
25
+ 'top_k': int
26
+ }
27
+
28
+ def __init__(
29
+ self,
30
+ max_len_tokens: int = -1,
31
+ temp: float = 0.8,
32
+ top_p: float = 0.95,
33
+ min_p: float = 0.05,
34
+ frequency_penalty: float = 0.0,
35
+ presence_penalty: float = 0.0,
36
+ repeat_penalty: float = 1.0,
37
+ top_k: int = 40
38
+ ):
39
+ """
40
+ Construct a new SamplerSettings instance
41
+ """
42
+
43
+ self.max_len_tokens = max_len_tokens
44
+ self.temp = temp
45
+ self.top_p = top_p
46
+ self.min_p = min_p
47
+ self.frequency_penalty = frequency_penalty
48
+ self.presence_penalty = presence_penalty
49
+ self.repeat_penalty = repeat_penalty
50
+ self.top_k = top_k
51
+
52
+ for sampler_param in SamplerSettings.ParamTypes:
53
+ expected_type = SamplerSettings.ParamTypes[sampler_param]
54
+ actual_type = type(getattr(self, sampler_param))
55
+ if actual_type != expected_type:
56
+ raise TypeError(
57
+ f"wrong type for SamplerSettings parameter '{sampler_param}'"
58
+ f" - expected {expected_type}, got {actual_type}"
59
+ )
60
+
61
+ def __repr__(self) -> str:
62
+ repr_str = 'SamplerSettings('
63
+ repr_str += f'max_len_tokens={self.max_len_tokens}, '
64
+ repr_str += f'temp={self.temp}, '
65
+ repr_str += f'top_p={self.top_p}, '
66
+ repr_str += f'min_p={self.min_p}, '
67
+ repr_str += f'frequency_penalty={self.frequency_penalty}, '
68
+ repr_str += f'presence_penalty={self.presence_penalty}, '
69
+ repr_str += f'repeat_penalty={self.repeat_penalty}, '
70
+ repr_str += f'top_k={self.top_k})'
71
+ return repr_str
72
+
73
+ # most likely token is always chosen
74
+ GreedyDecoding = SamplerSettings(
75
+ temp = 0.0,
76
+ )
77
+
78
+ # reflects llama.cpp
79
+ DefaultSampling = SamplerSettings()
80
+
81
+ # unmodified probability distribution (i.e. what the model actually thinks)
82
+ SimpleSampling = SamplerSettings(
83
+ temp = 1.0,
84
+ top_p = 1.0,
85
+ min_p = 0.0,
86
+ top_k = -1
87
+ )
88
+
89
+ # reflects old llama.cpp defaults
90
+ ClassicSampling = SamplerSettings(
91
+ min_p=0.0,
92
+ repeat_penalty = 1.1
93
+ )
94
+
95
+ # halfway between DefaultSampling and SimpleSampling
96
+ SemiSampling = SamplerSettings(
97
+ temp=0.9,
98
+ top_p=0.975,
99
+ min_p=0.025,
100
+ top_k=80
101
+ )
102
+
103
+ # for models with large vocabulary, which tend to run hot
104
+ TikTokenSampling = SamplerSettings(
105
+ temp=0.6,
106
+ repeat_penalty=1.1
107
+ )
108
+
109
+ # use min_p as the only active sampler (more permissive)
110
+ LowMinPSampling = SamplerSettings(
111
+ temp = 1.0,
112
+ top_p = 1.0,
113
+ min_p = 0.05,
114
+ top_k = -1
115
+ )
116
+
117
+ # use min_p as the only active sampler (moderate)
118
+ MinPSampling = SamplerSettings(
119
+ temp = 1.0,
120
+ top_p = 1.0,
121
+ min_p = 0.1,
122
+ top_k = -1
123
+ )
124
+
125
+ # use min_p as the only active sampler (more restrictive)
126
+ StrictMinPSampling = SamplerSettings(
127
+ temp = 1.0,
128
+ top_p = 1.0,
129
+ min_p = 0.2,
130
+ top_k = -1
131
+ )
132
+
133
+ # https://arxiv.org/abs/2210.14140
134
+ ContrastiveSearch = SamplerSettings(
135
+ temp = 0.0,
136
+ presence_penalty = 0.4
137
+ )
138
+
139
+ # https://arxiv.org/abs/2210.14140
140
+ WarmContrastiveSearch = SamplerSettings(
141
+ temp = 0.0,
142
+ presence_penalty = 0.8
143
+ )
144
+
145
+ # outputs completely random tokens from vocab (useless)
146
+ RandomSampling = SamplerSettings(
147
+ temp = MAX_TEMP,
148
+ top_p = 1.0,
149
+ min_p = 0.0,
150
+ top_k = -1
151
+ )
152
+
153
+ # default sampling with reduced temperature
154
+ LowTempSampling = SamplerSettings(
155
+ temp = 0.4
156
+ )
157
+
158
+ # default sampling with increased temperature
159
+ HighTempSampling = SamplerSettings(
160
+ temp = 1.2
161
+ )