RuntimeError: Failed to import transformers.models.modernbert.modeling_modernbert
Traceback (most recent call last):
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 1815, in _get_module
return importlib.import_module("." + module_name, self.name)
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in exec_module
File "", line 228, in _call_with_frames_removed
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/site-packages/transformers/models/modernbert/modeling_modernbert.py", line 310, in
) -> Tuple[torch.Tensor, torch.Tensor] | Tuple[torch.Tensor]:
TypeError: unsupported operand type(s) for |: '_GenericAlias' and '_GenericAlias'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/workspace/workspace/scripts/new_nlp_models/model_modernbert.py", line 5, in
model = AutoModelForMaskedLM.from_pretrained(model_id)
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 563, in from_pretrained
model_class = _get_model_class(config, cls._model_mapping)
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 388, in _get_model_class
supported_models = model_mapping[type(config)]
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 763, in getitem
return self._load_attr_from_module(model_type, model_name)
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 777, in _load_attr_from_module
return getattribute_from_module(self._modules[module_name], attr)
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py", line 693, in getattribute_from_module
if hasattr(module, attr):
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 1803, in getattr
module = self._get_module(self._class_to_module[name])
File "/workspace/conda_env/anaconda3/envs/vaiq_onnx/lib/python3.9/site-packages/transformers/utils/import_utils.py", line 1817, in _get_module
raise RuntimeError(
RuntimeError: Failed to import transformers.models.modernbert.modeling_modernbert because of the following error (look up to see its traceback):
unsupported operand type(s) for |: '_GenericAlias' and '_GenericAlias'
I believe this is caused by Python 3.9. It will work from 3.10 onwards.
I tried 3.10 and getting different error
Traceback (most recent call last):
File "/workspace/workspace/scripts/new_nlp_models/model_modernbert.py", line 9, in
outputs = model(**inputs)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
return forward_call(*args, **kwargs)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/transformers/models/modernbert/modeling_modernbert.py", line 1059, in forward
outputs = self.model(
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
return forward_call(*args, **kwargs)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/transformers/models/modernbert/modeling_modernbert.py", line 895, in forward
hidden_states = self.embeddings(input_ids)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1736, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1747, in _call_impl
return forward_call(*args, **kwargs)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/transformers/models/modernbert/modeling_modernbert.py", line 210, in forward
self.compiled_embeddings(input_ids)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 465, in _fn
return fn(*args, **kwargs)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 1269, in call
return self._torchdynamo_orig_callable(
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 1064, in call
result = self._inner_convert(
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 526, in call
return _compile(
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 595, in _compile
from torch.fx.experimental.validator import (
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/site-packages/torch/fx/experimental/validator.py", line 24, in
import z3 # type: ignore[import]
File "/home/sr/.local/lib/python3.10/site-packages/z3/init.py", line 1, in
from .z3 import *
File "/home/sr/.local/lib/python3.10/site-packages/z3/z3.py", line 46, in
from . import z3core
File "/home/sr/.local/lib/python3.10/site-packages/z3/z3core.py", line 119, in
_lib.Z3_solver_register_on_clause.restype = None
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/ctypes/init.py", line 387, in getattr
func = self.getitem(name)
File "/workspace/conda_env/anaconda3/envs/model_source/lib/python3.10/ctypes/init.py", line 392, in getitem
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: /lib/x86_64-linux-gnu/libz3.so: undefined symbol: Z3_solver_register_on_clause