Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tueri/output_scanners/factual_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def __init__(
use_onnx=use_onnx,
)
if not use_onnx:
self._model = self._model.to(device())
# Handle meta device properly - use to_empty() when moving from meta device
if hasattr(self._model, 'device') and str(self._model.device) == 'meta':
self._model = self._model.to_empty(device=device())
else:
self._model = self._model.to(device())
self._model.eval()

def scan(self, prompt: str, output: str) -> tuple[str, bool, float]:
Expand Down
7 changes: 6 additions & 1 deletion tueri/output_scanners/relevance.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ def __init__(
subfolder=model.subfolder,
revision=model.revision,
**model.kwargs,
).to(device())
)
# Handle meta device properly - use to_empty() when moving from meta device
if hasattr(self._model, 'device') and str(self._model.device) == 'meta':
self._model = self._model.to_empty(device=device())
else:
self._model = self._model.to(device())
LOGGER.debug("Initialized model", model=model, device=device())
self._model.eval()

Expand Down
12 changes: 10 additions & 2 deletions tueri/transformers_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def get_tokenizer_and_model_for_classification(
low_cpu_mem_usage=False,
**model.kwargs,
)
tf_model = tf_model.to(device())
# Handle meta device properly - use to_empty() when moving from meta device
if hasattr(tf_model, 'device') and str(tf_model.device) == 'meta':
tf_model = tf_model.to_empty(device=device())
else:
tf_model = tf_model.to(device())
LOGGER.debug("Initialized classification model", model=model, device=device())

return tf_tokenizer, tf_model
Expand Down Expand Up @@ -131,7 +135,11 @@ def get_tokenizer_and_model_for_ner(
low_cpu_mem_usage=False,
**model.kwargs,
)
tf_model = tf_model.to(device())
# Handle meta device properly - use to_empty() when moving from meta device
if hasattr(tf_model, 'device') and str(tf_model.device) == 'meta':
tf_model = tf_model.to_empty(device=device())
else:
tf_model = tf_model.to(device())
LOGGER.debug("Initialized NER model", model=model, device=device())

return tf_tokenizer, tf_model
Expand Down