environment
- sentence_transformers.util.environment.check_package_availability(package_name: str, owner: str) bool[source]
Checks if a package is available from the correct owner.
- sentence_transformers.util.environment.check_version_requirements(requirements: dict[str, Any] | None, source: str | None = None) None[source]
Verifies that the installed packages satisfy the version requirements declared by a model.
Requirements that can’t be interpreted (e.g. an invalid specifier) are logged as a warning and skipped, so that a typo in a model configuration doesn’t make the model unloadable.
- Parameters:
requirements (dict[str, Any], optional) – Mapping of package name to a PEP 440 version specifier, e.g.
{"transformers": ">=5.15", "peft": ">=0.18,<0.20"}. Instead of a specifier, a value may also be a dictionary with a"specifier"and a"reason"describing what goes wrong if the requirement isn’t met. The special"python"package name is matched against the running Python version.source (str, optional) – The model name or path that declared the requirements, used in the error message. Defaults to None.
- Raises:
ImportError – If one or more requirements aren’t satisfied.
- sentence_transformers.util.environment.get_device_name() str[source]
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.get_installed_version(package_name: str) str | None[source]
Returns the version of an installed package, or None if the package can’t be found.
The
__version__of an already imported module takes precedence over the distribution metadata, as the metadata of editable installs lags behind the code that actually runs.
- sentence_transformers.util.environment.is_accelerate_available() bool[source]
Returns True if the Huggingface accelerate library is available.
- sentence_transformers.util.environment.is_datasets_available() bool[source]
Returns True if the Huggingface datasets library is available.
- sentence_transformers.util.environment.is_dist_initialized() bool[source]
Returns whether
torch.distributedis 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() == Falseand do not expose APIs likeis_initialized, so calling them directly raisesAttributeError.