I am trying to load a PyTorch model:
import torch
import io
blob_service_client_instance = BlobServiceClient(account_url=STORAGEACCOUNTURL, credential=STORAGEACCOUNTKEY)
container_client = blob_service_client_instance.get_container_client(container=CONTAINERNAME)
blob_url = f"{account_url}/{CONTAINERNAME}/{BLOBNAME}/model.pt"
blob_client = BlobClient.from_blob_url(blob_url=blob_url, credential=STORAGEACCOUNTKEY)
with io.BytesIO() as model_file:
print("Writing Model")
model_file.write(blob_client.download_blob().readall())
print(model_file)
model_file.seek(0)
print(model_file)
print("loading pytorch model")
adv_model = torch.load(model_file, map_location=torch.device('cpu'))
The error is as follows:
<_io.BytesIO object at 0x0000020132C29D60>
<_io.BytesIO object at 0x0000020132C29D60>
loading pytorch model
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In [12], line 22
20 print(model_file)
21 print("loading pytorch model")
---> 22 adv_model = torch.load(model_file, map_location=torch.device('cpu'))
File ~\Anaconda3\envs\modelmesh\lib\site-packages\torch\serialization.py:607, in load(f, map_location, pickle_module, **pickle_load_args)
605 opened_file.seek(orig_position)
606 return torch.jit.load(opened_file)
--> 607 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
608 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File ~\Anaconda3\envs\modelmesh\lib\site-packages\torch\serialization.py:882, in _load(zip_file, map_location, pickle_module, pickle_file, **pickle_load_args)
880 unpickler = UnpicklerWrapper(data_file, **pickle_load_args)
881 unpickler.persistent_load = persistent_load
--> 882 result = unpickler.load()
884 torch._utils._validate_loaded_sparse_tensors()
886 return result
File ~\Anaconda3\envs\modelmesh\lib\site-packages\torch\serialization.py:875, in _load.<locals>.UnpicklerWrapper.find_class(self, mod_name, name)
873 def find_class(self, mod_name, name):
874 mod_name = load_module_mapping.get(mod_name, mod_name)
--> 875 return super().find_class(mod_name, name)
ModuleNotFoundError: No module named 'modeling'
Why am I getting this ModuleNotFoundError? and What is the solution?