huggingface / huggingface/sentence-transformers
Getting error while loading "distiluse-base-multilingual-cased"
- Dominant language
- Python
- Stars
- 19.1k
- Forks
- 2.9k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 61
Description
When trying to load "distiluse-base-multilingual-cased" getting below error:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
in ()
1 from sentence_transformers import SentenceTransformer
----> 2 embedder2 = SentenceTransformer('distiluse-base-multilingual-cased')
~/anaconda3/lib/python3.6/site-packages/sentence_transformers/SentenceTransformer.py in __init__(self, model_name_or_path, modules, device)
86 #print(module_config['path'])
87 #print(module_class)
---> 88 module = module_class.load(os.path.join(model_path, module_config['path']))
89 modules[module_config['name']] = module
90
~/anaconda3/lib/python3.6/site-packages/sentence_transformers/models/Dense.py in load(input_path)
43 model = Dense(**config)
44 #model.load_state_dict(torch.load(os.path.join(input_path, 'pytorch_model.bin')))
---> 45 model.load_state_dict(torch.load(os.path.join(input_path, 'pytorch_model.bin')),map_location=torch.device('cpu'))
46 return model
~/anaconda3/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
530 with _open_zipfile_reader(f) as opened_zipfile:
531 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
--> 532 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
533
534
~/anaconda3/lib/python3.6/site-packages/torch/serialization.py in _legacy_load(f, map_location, pickle_module, **pickle_load_args)
703 unpickler = pickle_module.Unpickler(f, **pickle_load_args)
704 unpickler.persistent_load = persistent_load
--> 705 result = unpickler.load()
706
707 deserialized_storage_keys = pickle_module.load(f, **pickle_load_args)
~/anaconda3/lib/python3.6/site-packages/torch/serialization.py in persistent_load(saved_id)
666 obj = data_type(size)
667 obj._torch_load_uninitialized = True
--> 668 deserialized_objects[root_key] = restore_location(obj, location)
669 storage = deserialized_objects[root_key]
670 if view_metadata is not None:
~/anaconda3/lib/python3.6/site-packages/torch/serialization.py in default_restore_location(storage, location)
157 def default_restore_location(storage, location):
158 for _, _, fn in _package_registry:
--> 159 result = fn(storage, location)
160 if result is not None:
161 return result
~/anaconda3/lib/python3.6/site-packages/torch/serialization.py in _cuda_deserialize(obj, location)
133 def _cuda_deserialize(obj, location):
134 if location.startswith('cuda'):
--> 135 device = validate_cuda_device(location)
136 if getattr(obj, "_torch_load_uninitialized", False):
137 storage_type = getattr(torch.cuda, type(obj).__name__)
~/anaconda3/lib/python3.6/site-packages/torch/serialization.py in validate_cuda_device(location)
116 if not torch.cuda.is_available():
117 #device = "cpu"
--> 118 raise RuntimeError('Attempting to deserialize object on a CUDA '
119 'device but torch.cuda.is_available() is False. '
120 'If you are running on a CPU-only machine, '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with SentenceTransformer.__init__ and models/Dense.py load, the entry points shown in the traceback. Reproduce loading distiluse-base-multilingual-cased on a CPU-only environment and trace why the weights still target CUDA. Done means the model loads successfully without CUDA and the relevant loading behavior is verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100