* Add model * Update loader * Fix llama config usage * Docs * Fix config no_rope_layers * Fix tie_word_embeddings default * Add chat template * Embed the chat templates * Fix embedding template * enable_thinking default true * Update examples * XML tools for smollm3 * Add smollm3 docs * Fix openai examples * Clippy --------- Co-authored-by: Eric Buehler <[email protected]>
3.0 KiB
mistral.rs PyO3 Bindings: mistralrs
mistralrs is a Python package which provides an easy to use API for mistral.rs.
Example
More examples can be found here!
from mistralrs import Runner, Which, ChatCompletionRequest
runner = Runner(
which=Which.Plain(
model_id="microsoft/Phi-3.5-mini-instruct",
),
in_situ_quant="4",
)
res = runner.send_chat_completion_request(
ChatCompletionRequest(
model="default",
messages=[
{"role": "user", "content": "Tell me a story about the Rust type system."}
],
max_tokens=256,
presence_penalty=1.0,
top_p=0.1,
temperature=0.1,
)
)
print(res.choices[0].message.content)
print(res.usage)
Installation from PyPi
With the PyPi installation method, you can take advantage of prebuild wheels to easily install.
-
CUDA
pip install mistralrs-cuda -v -
Metal
pip install mistralrs-metal -v -
Apple Accelerate
pip install mistralrs-accelerate -v -
Intel MKL
pip install mistralrs-mkl -v -
Without accelerators
pip install mistralrs -v
All installations will install the mistralrs package. The suffix on the package installed by pip only controls the feature activation.
Installation from source
-
Install required packages
openssl(Example on Ubuntu:sudo apt install libssl-dev)pkg-config(Example on Ubuntu:sudo apt install pkg-config)
-
Install Rust: https://rustup.rs/
Example on Ubuntu:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env -
Set HF token correctly (skip if already set or your model is not gated, or if you want to use the
token_sourceparameters in Python or the command line.)Example on Ubuntu:
mkdir ~/.cache/huggingface touch ~/.cache/huggingface/token echo <HF_TOKEN_HERE> > ~/.cache/huggingface/token -
Download the code
git clone https://github.com/EricLBuehler/mistral.rs.git cd mistral.rs -
cdinto the correct directory for buildingmistralrs:cd mistralrs-pyo3 -
Install
maturin, our Rust + Python build system: Maturin requires a Python virtual environment such asvenvorcondato be active. Themistralrspackage will be installed into that environment.pip install maturin[patchelf] -
Install
mistralrsInstallmistralrsby executing the following in this directory where features such ascudaorflash-attnmay be specified with the--featuresargument just like they would be forcargo run.maturin develop -r --features <specify feature(s) here>
Please find API docs here and the type stubs here, which are another great form of documentation.
We also provide a cookbook here!