transformers
Integration with the transformers
library.
TransformerTokenizer
Bases: Tokenizer
Represents a tokenizer for models in the transformers
library.
Source code in outlines/models/transformers.py
Transformers
Bases: Model
Thin wrapper around a transformers
model and a transformers
tokenizer.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the transformers
model and
tokenizer.
Source code in outlines/models/transformers.py
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 |
|
__init__(model, tokenizer)
Parameters:
model
A PreTrainedModel
, or any model that is compatible with the
transformers
API for models.
tokenizer
A PreTrainedTokenizer
, or any tokenizer that is compatible with
the transformers
API for tokenizers.
Source code in outlines/models/transformers.py
generate(model_input, output_type=None, **inference_kwargs)
Generate text using transformers
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
Union[str, List[str], dict]
|
The prompt based on which the model will generate a response. For
multi-modal models, the input should be a dictionary containing the
|
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
inference_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
Type | Description |
---|---|
Union[str, List[str]]
|
The text generated by the model. |
Source code in outlines/models/transformers.py
generate_stream(model_input, output_type, **inference_kwargs)
Not available for transformers
models.
TODO: implement following completion of https://github.com/huggingface/transformers/issues/30810
Source code in outlines/models/transformers.py
TransformersMultiModal
Bases: Transformers
Thin wrapper around a transformers
model and a transformers
processor.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the transformers
model and
processor.
Source code in outlines/models/transformers.py
__init__(model, processor)
Create a TransformersMultiModal model instance
We rely on the __init__
method of the Transformers
class to handle
most of the initialization and then add elements specific to vision
models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
PreTrainedModel
|
A |
required |
processor
|
A |
required |
Source code in outlines/models/transformers.py
TransformersMultiModalTypeAdapter
Bases: ModelTypeAdapter
Type adapter for TransformersMultiModal
model.
Source code in outlines/models/transformers.py
format_input(model_input)
Generate the prompt arguments to pass to the model.
Argument
model_input The input passed by the user.
Returns:
Type | Description |
---|---|
dict
|
The formatted input to be passed to the model. |
Source code in outlines/models/transformers.py
format_output_type(output_type=None)
Generate the logits processor argument to pass to the model.
Argument
output_type The logits processor provided.
Returns:
Type | Description |
---|---|
Optional[LogitsProcessorList]
|
The logits processor to pass to the model. |
Source code in outlines/models/transformers.py
TransformersTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the Transformers
model.
Source code in outlines/models/transformers.py
format_input(model_input)
Generate the prompt argument to pass to the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
The input passed by the user. |
required |
Returns:
Type | Description |
---|---|
str
|
The formatted input to be passed to the model. |
Source code in outlines/models/transformers.py
format_output_type(output_type=None)
Generate the logits processor argument to pass to the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor provided. |
None
|
Returns:
Type | Description |
---|---|
Optional[LogitsProcessorList]
|
The logits processor to pass to the model. |
Source code in outlines/models/transformers.py
from_transformers(model, tokenizer_or_processor)
Create an Outlines Transformers
or TransformersMultiModal
model
instance from a PreTrainedModel
instance and a PreTrainedTokenizer
or
ProcessorMixin
instance.
outlines
supports PreTrainedModelForCausalLM
,
PreTrainedMambaForCausalLM
, PreTrainedModelForSeq2Seq
and any model
that implements the transformers
model API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
PreTrainedModel
|
A |
required |
tokenizer_or_processor
|
Union[PreTrainedTokenizer, ProcessorMixin]
|
A |
required |
Returns:
Type | Description |
---|---|
Union[Transformers, TransformersMultiModal]
|
An Outlines |
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.