Installation — Sentence Transformers documentation (original) (raw)

We recommend Python 3.10+, PyTorch 1.11.0+, and transformers v4.41.0+. There are several extra options to install Sentence Transformers:

Note that you can mix and match the various extras, e.g. pip install -U "sentence-transformers[train,image,video,onnx-gpu]".

Install with uv

Default

uv pip install -U sentence-transformers

Image

uv pip install -U "sentence-transformers[image]"

Audio

uv pip install -U "sentence-transformers[audio]"

Video

uv pip install -U "sentence-transformers[video]"

Training

uv pip install -U "sentence-transformers[train]"

To use Weights and Biases or Trackio to track your training logs, you should also install wandb or trackio (recommended):

And to track your carbon emissions while training and have this information automatically included in your model cards, also install codecarbon (recommended):

uv pip install codecarbon

Don’t forget to add the module names to report_to in the Training Arguments when training, or they will not be used.

ONNX

For GPU and CPU:

uv pip install -U "sentence-transformers[onnx-gpu]"

For CPU only:

uv pip install -U "sentence-transformers[onnx]"

OpenVINO

uv pip install -U "sentence-transformers[openvino]"

Development

uv pip install -U "sentence-transformers[dev]"

Install with pip

Default

pip install -U sentence-transformers

Image

pip install -U "sentence-transformers[image]"

Audio

pip install -U "sentence-transformers[audio]"

Video

pip install -U "sentence-transformers[video]"

Training

pip install -U "sentence-transformers[train]"

To use Weights and Biases or Trackio to track your training logs, you should also install wandb or trackio (recommended):

And to track your carbon emissions while training and have this information automatically included in your model cards, also install codecarbon (recommended):

Don’t forget to add the module names to report_to in the Training Arguments when training, or they will not be used.

ONNX

For GPU and CPU:

pip install -U "sentence-transformers[onnx-gpu]"

For CPU only:

pip install -U "sentence-transformers[onnx]"

OpenVINO

pip install -U "sentence-transformers[openvino]"

Development

pip install -U "sentence-transformers[dev]"

Install with Conda

The base package is available on conda-forge. Extras (e.g. [image], [train]) are a pip concept and not available via conda, so they are installed with pip.

Default

conda install -c conda-forge sentence-transformers

Image

pip install -U "sentence-transformers[image]"

Audio

pip install -U "sentence-transformers[audio]"

Video

pip install -U "sentence-transformers[video]"

Training

conda install -c conda-forge sentence-transformers accelerate datasets

To use Weights and Biases or Trackio to track your training logs, you should also install wandb or trackio (recommended):

And to track your carbon emissions while training and have this information automatically included in your model cards, also install codecarbon (recommended):

Don’t forget to add the module names to report_to in the Training Arguments when training, or they will not be used.

ONNX

For GPU and CPU:

pip install -U "sentence-transformers[onnx-gpu]"

For CPU only:

pip install -U "sentence-transformers[onnx]"

OpenVINO

pip install -U "sentence-transformers[openvino]"

Development

conda install -c conda-forge sentence-transformers accelerate datasets pre-commit pytest ruff

Install from Source

You can install sentence-transformers directly from source to take advantage of the bleeding edge main branch rather than the latest stable release:

Default

pip install git+https://github.com/huggingface/sentence-transformers.git

Image

pip install -U "sentence-transformers[image] @ git+https://github.com/huggingface/sentence-transformers.git"

Audio

pip install -U "sentence-transformers[audio] @ git+https://github.com/huggingface/sentence-transformers.git"

Video

pip install -U "sentence-transformers[video] @ git+https://github.com/huggingface/sentence-transformers.git"

Training

pip install -U "sentence-transformers[train] @ git+https://github.com/huggingface/sentence-transformers.git"

To use Weights and Biases or Trackio to track your training logs, you should also install wandb or trackio (recommended):

And to track your carbon emissions while training and have this information automatically included in your model cards, also install codecarbon (recommended):

Don’t forget to add the module names to report_to in the Training Arguments when training, or they will not be used.

ONNX

For GPU and CPU:

pip install -U "sentence-transformers[onnx-gpu] @ git+https://github.com/huggingface/sentence-transformers.git"

For CPU only:

pip install -U "sentence-transformers[onnx] @ git+https://github.com/huggingface/sentence-transformers.git"

OpenVINO

pip install -U "sentence-transformers[openvino] @ git+https://github.com/huggingface/sentence-transformers.git"

Development

pip install -U "sentence-transformers[dev] @ git+https://github.com/huggingface/sentence-transformers.git"

Editable Install

If you want to make changes to sentence-transformers, you will need an editable install. Clone the repository and install it with these commands:

git clone https://github.com/huggingface/sentence-transformers cd sentence-transformers pip install -e ".[train,dev]"

These commands will link the new sentence-transformers folder and your Python library paths, such that this folder will be used when importing sentence-transformers.

Install PyTorch with CUDA support

To use a GPU/CUDA, you must install PyTorch with CUDA support. Follow PyTorch - Get Started for installation steps.