new: add warnings when device_ids are passed without cuda set to True

This commit is contained in:
George Panchuk
2025-02-20 19:00:54 +01:00
parent 8d04b81782
commit df2cc11590
6 changed files with 42 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
import warnings
from typing import Any, Iterable, Optional, Sequence, Type, Union
from dataclasses import asdict
@@ -57,6 +58,12 @@ class ImageEmbedding(ImageEmbeddingBase):
**kwargs: Any,
):
super().__init__(model_name, cache_dir, threads, **kwargs)
if not cuda and device_ids:
warnings.warn(
"`device_ids` are only used when `cuda` is set to True. Device ids will be ignored.",
UserWarning,
stacklevel=2,
)
for EMBEDDING_MODEL_TYPE in self.EMBEDDINGS_REGISTRY:
supported_models = EMBEDDING_MODEL_TYPE._list_supported_models()
if any(model_name.lower() == model.model.lower() for model in supported_models):

View File

@@ -1,3 +1,4 @@
import warnings
from typing import Any, Iterable, Optional, Sequence, Type, Union
from dataclasses import asdict
@@ -60,6 +61,13 @@ class LateInteractionTextEmbedding(LateInteractionTextEmbeddingBase):
**kwargs: Any,
):
super().__init__(model_name, cache_dir, threads, **kwargs)
if not cuda and device_ids:
warnings.warn(
"`device_ids` are only used when `cuda` is set to True. Device ids will be ignored.",
UserWarning,
stacklevel=2,
)
for EMBEDDING_MODEL_TYPE in self.EMBEDDINGS_REGISTRY:
supported_models = EMBEDDING_MODEL_TYPE._list_supported_models()
if any(model_name.lower() == model.model.lower() for model in supported_models):

View File

@@ -1,3 +1,4 @@
import warnings
from typing import Any, Iterable, Optional, Sequence, Type, Union
from dataclasses import asdict
@@ -63,6 +64,12 @@ class LateInteractionMultimodalEmbedding(LateInteractionMultimodalEmbeddingBase)
**kwargs: Any,
):
super().__init__(model_name, cache_dir, threads, **kwargs)
if not cuda and device_ids:
warnings.warn(
"`device_ids` are only used when `cuda` is set to True. Device ids will be ignored.",
UserWarning,
stacklevel=2,
)
for EMBEDDING_MODEL_TYPE in self.EMBEDDINGS_REGISTRY:
supported_models = EMBEDDING_MODEL_TYPE._list_supported_models()
if any(model_name.lower() == model.model.lower() for model in supported_models):

View File

@@ -1,3 +1,4 @@
import warnings
from typing import Any, Iterable, Optional, Sequence, Type
from dataclasses import asdict
@@ -56,6 +57,12 @@ class TextCrossEncoder(TextCrossEncoderBase):
**kwargs: Any,
):
super().__init__(model_name, cache_dir, threads, **kwargs)
if not cuda and device_ids:
warnings.warn(
"`device_ids` are only used when `cuda` is set to True. Device ids will be ignored.",
UserWarning,
stacklevel=2,
)
for CROSS_ENCODER_TYPE in self.CROSS_ENCODER_REGISTRY:
supported_models = CROSS_ENCODER_TYPE._list_supported_models()

View File

@@ -61,6 +61,13 @@ class SparseTextEmbedding(SparseTextEmbeddingBase):
**kwargs: Any,
):
super().__init__(model_name, cache_dir, threads, **kwargs)
if not cuda and device_ids:
warnings.warn(
"`device_ids` are only used when `cuda` is set to True. Device ids will be ignored.",
UserWarning,
stacklevel=2,
)
if model_name == "prithvida/Splade_PP_en_v1":
warnings.warn(
"The right spelling is prithivida/Splade_PP_en_v1. "

View File

@@ -49,6 +49,12 @@ class TextEmbedding(TextEmbeddingBase):
**kwargs: Any,
):
super().__init__(model_name, cache_dir, threads, **kwargs)
if not cuda and device_ids:
warnings.warn(
"`device_ids` are only used when `cuda` is set to True. Device ids will be ignored.",
UserWarning,
stacklevel=2,
)
if model_name == "nomic-ai/nomic-embed-text-v1.5-Q":
warnings.warn(
"The model 'nomic-ai/nomic-embed-text-v1.5-Q' has been updated on HuggingFace. "