suinleelab / contrastiveVI

BSD 3-Clause "New" or "Revised" License
49 stars 1 forks source link

Problem loading model #16

Open jmchan88 opened 1 year ago

jmchan88 commented 1 year ago

Hey ContrastiveVI team!

I'm super excited to try out your method! I ran ContrastiveVI and saved the model, presuming that the model would have similar scVI saving and loading capabilities, as below:

model.save(out_dir + "my_model/")

without any error. But now that I try to load it using:

model = scvi.model.SCVI.load(out_dir + 'n_latent.10/my_model', adata_cv)

I get the following error:

INFO     File                                                                                                      
         /data/peer/chanj3/HTA.fresh_plasticity.SCLC.120122/out.SCLC.ContrastiveVI.120122/n_latent.10/my_model/mode
         l.pt already downloaded                                                                                   
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[28], line 1
----> 1 model = scvi.model.SCVI.load(out_dir + 'n_latent.10/my_model', adata_cv)

File ~/anaconda3/envs/multiome_py_r/lib/python3.10/site-packages/scvi/model/base/_base_model.py:598, in BaseModelClass.load(cls, dir_path, adata, use_gpu, prefix, backup_url)
    596 registry = attr_dict.pop("registry_")
    597 if _MODEL_NAME_KEY in registry and registry[_MODEL_NAME_KEY] != cls.__name__:
--> 598     raise ValueError(
    599         "It appears you are loading a model from a different class."
    600     )
    602 if _SETUP_ARGS_KEY not in registry:
    603     raise ValueError(
    604         "Saved model does not contain original setup inputs. "
    605         "Cannot load the original setup."
    606     )

ValueError: It appears you are loading a model from a different class.

Is there any way to save and load the ContrastiveVI model? Thanks so much!

ethanweinberger commented 1 year ago

Hey @jmchan88! Sorry for the late reply here. During our experiments we saved/loaded contrastiveVI models using the standard torch.save and torch.load interface, and didn't end up testing out the scvi save/load interface.

We're currently working on moving contrastiveVI over to the scvi-tools codebase (see https://github.com/scverse/scvi-tools/issues/2242), and should have the scvi save/load interface implemented as part of that PR. Please let us know if you have further questions.