Failed to load model file
Hey there,
Thanks again for providing this fantastic atlas. I've been trying to load the core scArches model using the default README steps but am struggling to actually load the model.
ref_path = 'C:/Users/username/Downloads/scarches_SCANVI_core_GBmap.zip' source_adata = sc.read('C:/Users/username/Downloads/scarches_core_GBmap.h5ad')
vae = sca.models.SCANVI.load(ref_path, source_adata) # unzip scarches-SCANVI_GBmap.zip
cell_type_key = 'CellID'
surgery_epochs = 500 early_stopping_kwargs_surgery = { # Suggested values. For more info, please consult: https://scarches.readthedocs.io/en/latest/about.html "early_stopping_metric": "elbo", "save_best_state_metric": "elbo", "on": "full_dataset", "patience": 10, "threshold": 0.001, "reduce_lr_on_plateau": True, "lr_patience": 8, "lr_factor": 0.1, }
INFO No backup URL provided for missing file
C:/Users/username/Downloads/scarches_SCANVI_core_GBmap.zip\model.pt
FileNotFoundError Traceback (most recent call last) File ~\AppData\Local\miniconda3\envs\scarches_env\lib\site-packages\scvi\model\base_save_load.py:77, in _load_saved_files(dir_path, load_adata, prefix, map_location, backup_url) 76 _download(backup_url, dir_path, model_file_name) ---> 77 model = torch.load(model_path, map_location=map_location, weights_only=False) 78 except FileNotFoundError as exc:
File ~\AppData\Local\miniconda3\envs\scarches_env\lib\site-packages\torch\serialization.py:1479, in load(f, map_location, pickle_module, weights_only, mmap, **pickle_load_args) 1477 pickle_load_args["encoding"] = "utf-8" -> 1479 with _open_file_like(f, "rb") as opened_file: 1480 if _is_zipfile(opened_file): 1481 # The zipfile reader is going to advance the current file position. 1482 # If we want to actually tail call to torch.jit.load, we need to 1483 # reset back to the original position.
File ~\AppData\Local\miniconda3\envs\scarches_env\lib\site-packages\torch\serialization.py:759, in _open_file_like(name_or_buffer, mode) 758 if _is_path(name_or_buffer): --> 759 return _open_file(name_or_buffer, mode) 760 else:
File ~\AppData\Local\miniconda3\envs\scarches_env\lib\site-packages\torch\serialization.py:740, in _open_file.init(self, name, mode) 739 def init(self, name: Union[str, os.PathLike[str]], mode: str) -> None: --> 740 super().init(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/marsdenl/Downloads/scarches_SCANVI_core_GBmap.zip\model.pt'
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last) Cell In[8], line 1 ----> 1 vae = sca.models.SCANVI.load(ref_path, source_adata) # unzip scarches-SCANVI_GBmap.zip 3 cell_type_key = 'CellID' 5 surgery_epochs = 500
File ~\AppData\Local\miniconda3\envs\scarches_env\lib\site-packages\scvi\model\base_base_model.py:808, in BaseModelClass.load(cls, dir_path, adata, accelerator, device, prefix, backup_url, datamodule) 795 load_adata = adata is None 796 _, _, device = parse_device_args( 797 accelerator=accelerator, 798 devices=device, 799 return_device="torch", 800 validate_single_device=True, 801 ) 803 ( 804 attr_dict, 805 var_names, 806 model_state_dict, 807 new_adata, --> 808 ) = load_saved_files( 809 dir_path, 810 load_adata, 811 map_location=device, 812 prefix=prefix, 813 backup_url=backup_url, 814 ) 815 adata = new_adata if new_adata is not None else adata 817 registry = attr_dict.pop("registry")
File ~\AppData\Local\miniconda3\envs\scarches_env\lib\site-packages\scvi\model\base_save_load.py:79, in _load_saved_files(dir_path, load_adata, prefix, map_location, backup_url)
77 model = torch.load(model_path, map_location=map_location, weights_only=False)
78 except FileNotFoundError as exc:
---> 79 raise ValueError(
80 f"Failed to load model file at {model_path}. "
81 "If attempting to load a saved model from <v0.15.0, please use the util function "
82 "convert_legacy_save to convert to an updated format."
83 ) from exc
85 model_state_dict = model.get(SAVE_KEYS.MODEL_STATE_DICT_KEY)
86 var_names = model.get(SAVE_KEYS.VAR_NAMES_KEY)
ValueError: Failed to load model file at C:/Users/marsdenl/Downloads/scarches_SCANVI_core_GBmap.zip\model.pt. If attempting to load a saved model from <v0.15.0, please use the util function convert_legacy_save to convert to an updated format.
My Zenodo scarches_SCANVI_core_GBmap.zip contains: dir scarches_SCANVI_core_GBmap 18/05/2025 12:55 PM 12,042 attr.pkl 18/05/2025 12:55 PM 13,364,127 model_params.pt 18/05/2025 12:55 PM 32,246 var_names.csv 18/05/2025 12:55 PM <DIR> __MACOSX
Do you know why this might be happening?
Thanks :)