model_base
This module contains the base Model class
Model
Parent model class.
Source code in happy_vllm/model/model_base.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
__init__(**kwargs)
Init. model class
Source code in happy_vllm/model/model_base.py
extract_text_outside_truncation(text, truncation_side=None, max_length=None)
Extracts the part of the prompt not kept after truncation, which will not be infered by the model. First, we tokenize the prompt while applying truncation. We obtain a list of sequences of token ids padded, which are outside the truncation. Then we decode this list of tensors of token IDs containing special tokens to a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str)
|
The text we want to parse |
required |
truncation_side
|
str)
|
The side of the truncation |
None
|
max_length
|
int)
|
The length above which the text will be truncated |
None
|
Returns:
Type | Description |
---|---|
str
|
The part of the text which will be dropped by the truncation (str) |
Source code in happy_vllm/model/model_base.py
is_model_loaded()
loading(async_engine_client, args, **kwargs)
async
load the model
Source code in happy_vllm/model/model_base.py
split_text(text, num_tokens_in_chunk=200, separators=None)
Splits a text in small texts containing at least num_tokens_in_chunk tokens and ending by a separator. note that the separators
used are the tokenization of the strings and not the strings themselves (which explains why we must for example
specify ' .' and '.' as two separate separators)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str)
|
The text to split |
required |
Kwargs
num_tokens_in_chunk (int) : The minimal number of tokens in the chunk separators (list) : The separators marking the end of a sentence
Returns:
Type | Description |
---|---|
List[str]
|
A list of strings each string containing at least num_tokens_in_chunk tokens and ending by a separator |
Source code in happy_vllm/model/model_base.py
tokenize(text)
Tokenizes a text
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str)
|
The text to tokenize |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
List[int]
|
The list of token ids |
find_indices_sub_list_in_list(big_list, sub_list)
Find the indices of the presence of a sub list in a bigger list. For example if big_list = [3, 4, 1, 2, 3, 4, 5, 6, 3, 4] and sub_list = [3, 4], the result will be [1, 5, 9]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
big_list
|
list)
|
The list in which we want to find the sub_list |
required |
sub_list
|
list
|
The list we want the indices of in the big_list |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
The list of indices of where the sub_list is in the big_list |