environment

sentence_transformers.util.environment.check_package_availability(package_name: str, owner: str) bool

Checks if a package is available from the correct owner.

sentence_transformers.util.environment.get_device_name() str

Returns the name of the device where this module is running on.

This function only supports single device or basic distributed training setups. In distributed mode for cuda device, it uses the rank to assign a specific CUDA device.

Returns:

Device name, like ‘cuda:2’, ‘mps’, ‘npu’, ‘xpu’, ‘hpu’, or ‘cpu’

Return type:

str

sentence_transformers.util.environment.is_accelerate_available() bool

Returns True if the Huggingface accelerate library is available.

sentence_transformers.util.environment.is_datasets_available() bool

Returns True if the Huggingface datasets library is available.

sentence_transformers.util.environment.is_dist_initialized() bool

Returns whether torch.distributed is available and has been initialized.

The availability check must come first: some PyTorch builds (e.g. ROCm or CPU-only) report torch.distributed.is_available() == False and do not expose APIs like is_initialized, so calling them directly raises AttributeError.

sentence_transformers.util.environment.is_training_available() bool

Returns True if we have the required dependencies for training Sentence Transformers models, i.e. Huggingface datasets and Huggingface accelerate.

sentence_transformers.util.environment.suggest_extra_on_exception() Generator[None, None, None]

Re-raise ImportError/AttributeError with an install hint when a multimodal dependency is missing.