mlxlm
Integration with the mlx_lm
library.
MLXLM
Bases: Model
Thin wrapper around an mlx_lm
model.
This wrapper is used to convert the input and output types specified by the
users at a higher level to arguments to the mlx_lm
library.
Source code in outlines/models/mlxlm.py
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 |
|
__init__(model, tokenizer)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
An instance of an |
required |
tokenizer
|
PreTrainedTokenizer
|
An instance of an |
required |
Source code in outlines/models/mlxlm.py
generate(model_input, output_type=None, **kwargs)
Generate text using mlx-lm
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
kwargs
|
Additional keyword arguments to pass to the |
{}
|
Returns:
Type | Description |
---|---|
str
|
The text generated by the model. |
Source code in outlines/models/mlxlm.py
generate_stream(model_input, output_type=None, **kwargs)
Stream text using mlx-lm
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
str
|
The prompt based on which the model will generate a response. |
required |
output_type
|
Optional[OutlinesLogitsProcessor]
|
The logits processor the model will use to constrain the format of the generated text. |
None
|
kwargs
|
Additional keyword arguments to pass to the |
{}
|
Returns:
Type | Description |
---|---|
Iterator[str]
|
An iterator that yields the text generated by the model. |
Source code in outlines/models/mlxlm.py
MLXLMTypeAdapter
Bases: ModelTypeAdapter
Type adapter for the MLXLM
model.
Source code in outlines/models/mlxlm.py
format_input(model_input)
Generate the prompt argument to pass to the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_input
|
The input provided by the user. |
required |
Returns:
Type | Description |
---|---|
str
|
The formatted input to be passed to the model. |
Source code in outlines/models/mlxlm.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[list[OutlinesLogitsProcessor]]
|
The logits processor argument to be passed to the model. |
Source code in outlines/models/mlxlm.py
from_mlxlm(model, tokenizer)
Create an Outlines MLXLM
model instance from an mlx_lm
model and a
tokenizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
An instance of an |
required |
tokenizer
|
PreTrainedTokenizer
|
An instance of an |
required |
Returns:
Type | Description |
---|---|
MLXLM
|
An Outlines |