Models
TransformerTokenizer
Bases: Tokenizer
Represents a tokenizer for models in the transformers
library.
Source code in outlines/models/transformers.py
Transformers
Represents a transformers
model.
Source code in outlines/models/transformers.py
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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
forward(input_ids, attention_mask, past_key_values=None)
Compute a forward pass through the transformer model.
Parameters
input_ids The input token ids. Must be one or two dimensional. attention_mask The attention mask. Must be one or two dimensional. past_key_values A tuple of tuples containing the cached key and value tensors for each attention head.
Returns
The computed logits and the new cached key and value tensors.
Source code in outlines/models/transformers.py
generate(prompts, generation_parameters, logits_processor, sampling_parameters)
Generate text using transformers
.
Arguments
prompts
A prompt or list of prompts.
generation_parameters
An instance of GenerationParameters
that contains the prompt,
the maximum number of tokens, stop sequences and seed. All the
arguments to SequenceGeneratorAdapter
's __cal__
method.
logits_processor
The logits processor to use when generating text.
sampling_parameters
An instance of SamplingParameters
, a dataclass that contains
the name of the sampler to use and related parameters as available
in Outlines.
Returns
The generated text
Source code in outlines/models/transformers.py
stream(prompts, generation_parameters, logits_processor, sampling_parameters)
Temporary stream stand-in which implements stream() signature and equivalent behaviour but isn't yielded until generation completes.
TODO: implement following completion of https://github.com/huggingface/transformers/issues/30810
Source code in outlines/models/transformers.py
get_llama_tokenizer_types()
Get all the Llama tokenizer types/classes that need work-arounds.
When they can't be imported, a dummy class is created.
Source code in outlines/models/transformers.py
transformers(model_name, device=None, model_kwargs={}, tokenizer_kwargs={}, model_class=None, tokenizer_class=None)
Instantiate a model from the transformers
library and its tokenizer.
Parameters
model_name
The name of the model as listed on Hugging Face's model page.
device
The device(s) on which the model should be loaded. This overrides
the device_map
entry in model_kwargs
when provided.
model_kwargs
A dictionary that contains the keyword arguments to pass to the
from_pretrained
method when loading the model.
tokenizer_kwargs
A dictionary that contains the keyword arguments to pass to the
from_pretrained
method when loading the tokenizer.
Returns
A TransformersModel
model instance.
Source code in outlines/models/transformers.py
Integration with OpenAI's API.
OpenAI
An object that represents the OpenAI API.
Source code in outlines/models/openai.py
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 |
|
__call__(prompt, max_tokens=None, stop_at=None, *, system_prompt=None, temperature=None, samples=None)
Call the OpenAI API to generate text.
Parameters
prompt A string or list of strings that will be used to prompt the model max_tokens The maximum number of tokens to generate stop_at A string or array of strings which, such that the generation stops when they are generated. system_prompt The content of the system message that precedes the user's prompt. temperature The value of the temperature used to sample tokens samples The number of completions to generate for each prompt stop_at Up to 4 words where the API will stop the completion.
Source code in outlines/models/openai.py
__init__(client, config, system_prompt=None)
Create an OpenAI
instance.
This class supports the standard OpenAI API, the Azure OpeanAI API as well as compatible APIs that rely on the OpenAI client.
Parameters
client
An instance of the API's async client.
config
An instance of OpenAIConfig
. Can be useful to specify some
parameters that cannot be set by calling this class' methods.
Source code in outlines/models/openai.py
OpenAIConfig
dataclass
Represents the parameters of the OpenAI API.
The information was last fetched on 2023/11/20. We document below the properties that are specific to the OpenAI API. Not all these properties are supported by Outlines.
Properties
model
The name of the model. Available models can be found on OpenAI's website.
frequence_penalty
Number between 2.0 and -2.0. Positive values penalize new tokens based on
their existing frequency in the text,
logit_bias
Modifies the likelihood of specified tokens to appear in the completion.
Number between -100 (forbid) and +100 (only allows).
n
The number of completions to return for each prompt.
presence_penalty
Similar to frequency penalty.
response_format
Specifies the format the model must output. {"type": "json_object"}
enables JSON mode.
seed
Two completions with the same seed
value should return the same
completion. This is however not guaranteed.
stop
Up to 4 words where the API will stop the completion.
temperature
Number between 0 and 2. Higher values make the output more random, while
lower values make it more deterministic.
top_p
Number between 0 and 1. Parameter for nucleus sampling.
user
A unique identifier for the end-user.
Source code in outlines/models/openai.py
error_handler(api_call_fn)
Handle OpenAI API errors and missing API key.
Source code in outlines/models/openai.py
generate_chat(prompt, system_prompt, client, config)
async
Call OpenAI's Chat Completion API.
Parameters
prompt
The prompt we use to start the generation. Passed to the model
with the "user" role.
system_prompt
The system prompt, passed to the model with the "system" role
before the prompt.
client
The API client
config
An OpenAIConfig
instance.
Returns
A tuple that contains the model's response(s) and usage statistics.