theislab / cpa

The Compositional Perturbation Autoencoder (CPA) is a deep generative framework to learn effects of perturbations at the single-cell level. CPA performs OOD predictions of unseen combinations of drugs, learns interpretable embeddings, estimates dose-response curves, and provides uncertainty estimates.
BSD 3-Clause "New" or "Revised" License
83 stars 17 forks source link

TypeError: __init__() got an unexpected keyword argument 'checkpoint_callback' #11

Closed wershofe closed 1 year ago

wershofe commented 1 year ago

Hi I just tried running the Norman data tutorial and get the following error:

model.train(max_epochs=2000, use_gpu=True, batch_size=1024, early_stopping=True, plan_kwargs=trainer_params, early_stopping_patience=15, check_val_every_n_epoch=5, save_path='/home/mohsen/projects/cpa/lightning_logs/Norman2019_prep_new/', )

TypeError Traceback (most recent call last) Cell In [16], line 1 ----> 1 model.train(max_epochs=2000, 2 use_gpu=True, 3 batch_size=1024, 4 early_stopping=True, 5 plan_kwargs=trainer_params, 6 early_stopping_patience=15, 7 check_val_every_n_epoch=5, 8 save_path='/home/mohsen/projects/cpa/lightning_logs/Norman2019_prep_new/', 9 )

File ~/miniconda3/envs/envCPA/lib/python3.9/site-packages/cpa/_model.py:317, in CPA.train(self, max_epochs, use_gpu, train_size, validation_size, batch_size, early_stopping, plan_kwargs, hyperopt, save_path, trainer_kwargs) 314 checkpoint = SaveBestState(monitor='cpa_metric', mode='max', period=20, verbose=False) 315 trainer_kwargs['callbacks'].append(checkpoint) --> 317 runner = TrainRunner( 318 self, 319 training_plan=self.training_plan, 320 data_splitter=data_splitter, 321 max_epochs=max_epochs, 322 use_gpu=use_gpu, 323 early_stopping_monitor="cpa_metric", 324 early_stopping_mode='max', 325 checkpoint_callback=True, 326 trainer_kwargs, 327 ) 328 runner() 330 self.epoch_history = pd.DataFrame().from_dict(self.training_plan.epoch_history)

File ~/miniconda3/envs/envCPA/lib/python3.9/site-packages/scvi/train/_trainrunner.py:67, in TrainRunner.init(self, model, training_plan, data_splitter, max_epochs, use_gpu, trainer_kwargs) 65 self.lightning_devices = lightning_devices 66 self.device = device ---> 67 self.trainer = Trainer( 68 max_epochs=max_epochs, 69 accelerator=accelerator, 70 devices=lightning_devices, 71 gpus=None, 72 trainer_kwargs, 73 )

File ~/miniconda3/envs/envCPA/lib/python3.9/site-packages/scvi/train/_trainer.py:141, in Trainer.init(self, gpus, benchmark, flush_logs_every_n_steps, check_val_every_n_epoch, max_epochs, default_root_dir, enable_checkpointing, num_sanity_val_steps, enable_model_summary, early_stopping, early_stopping_monitor, early_stopping_min_delta, early_stopping_patience, early_stopping_mode, enable_progress_bar, progress_bar_refresh_rate, simple_progress_bar, logger, log_every_n_steps, replace_sampler_ddp, kwargs) 138 if logger is None: 139 logger = SimpleLogger() --> 141 super().init( 142 gpus=gpus, 143 benchmark=benchmark, 144 check_val_every_n_epoch=check_val_every_n_epoch, 145 max_epochs=max_epochs, 146 default_root_dir=default_root_dir, 147 enable_checkpointing=enable_checkpointing, 148 num_sanity_val_steps=num_sanity_val_steps, 149 enable_model_summary=enable_model_summary, 150 logger=logger, 151 log_every_n_steps=log_every_n_steps, 152 replace_sampler_ddp=replace_sampler_ddp, 153 enable_progress_bar=enable_progress_bar, 154 kwargs, 155 )

File ~/miniconda3/envs/envCPA/lib/python3.9/site-packages/pytorch_lightning/utilities/argparse.py:345, in _defaults_from_env_vars..insert_env_defaults(self, *args, kwargs) 342 kwargs = dict(list(env_variables.items()) + list(kwargs.items())) 344 # all args were already moved to kwargs --> 345 return fn(self, kwargs)

TypeError: init() got an unexpected keyword argument 'checkpoint_callback'

Are you able to advise how to solve?

Thanks Esther

yanwu2014 commented 1 year ago

I'm also seeing this error when I try to run CPA with a CPU, doesn't seem to happen with a GPU

yanwu2014 commented 1 year ago

Ok I think I figured it out: the latest versions of scvi-tools and pytorch-lightning have an updated API which is breaking

I was able to get CPA to run by installing the earliest version of scvi-tools required: pip3 install scvi-tools==0.16.4

PierreBoyeau commented 1 year ago

Another working solution for me was to pin python to be 3.10. It seems like the issue is that the package requires an up-to-date lightning version, which requires python>=3.8