domainlab from PyPI under Python 3.11
The newest version of domainlab cannot be installed with pip install domainlab or pip install domainlab==0.1.9 under Python 3.11 due to the following dependency issue:
ERROR: Could not find a version that satisfies the requirement torchvision<0.14.0,>=0.13.0 (from domainlab) (from versions: 0.15.1, 0.15.2, 0.16.0, 0.16.1)
ERROR: No matching distribution found for torchvision<0.14.0,>=0.13.0
It can still be installed when the --no-deps option is used with pip, and torch and torchvision can be installed separately in that case (i.e., pip install --no-deps domainlab==0.1.9 and then pip install torch torchvision). However, the versions of torch and torchvision installed in that way under Python 3.11 (specifically, '2.1.1+cu121' and '0.16.1+cu121') are not compatible with some of the existing domainlab code:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[8], line 1
----> 1 exp.execute(num_epochs=2)
File /storage2T/software/.pyenv/versions/3.11.0/envs/domainlab-pip/lib/python3.11/site-packages/domainlab/exp/exp_main.py:71, in Exp.execute(self, num_epochs)
69 for epoch in range(1, num_epochs):
70 t_before_epoch = t_c
---> 71 flag_stop = self.trainer.tr_epoch(epoch)
72 t_c = datetime.datetime.now()
73 logger.info(f"after epoch: {epoch},"
74 f"now: {str(t_c)},"
75 f"epoch time: {t_c - t_before_epoch},"
76 f"used: {t_c - t_0},"
77 f"model: {self.visitor.model_name}")
File /storage2T/software/.pyenv/versions/3.11.0/envs/domainlab-pip/lib/python3.11/site-packages/domainlab/algos/trainers/train_mldg.py:64, in TrainerMLDG.tr_epoch(self, epoch)
62 self.inner_trainer.model.load_state_dict(self.model.state_dict())
63 # update inner_model
---> 64 self.inner_trainer.before_epoch() # set model to train mode
65 self.inner_trainer.reset() # force optimizer to re-initialize
66 self.inner_trainer.tr_batch(
67 tensor_x_s, vec_y_s, vec_d_s, others_s, ind_batch, epoch)
File /storage2T/software/.pyenv/versions/3.11.0/envs/domainlab-pip/lib/python3.11/site-packages/domainlab/algos/trainers/train_basic.py:31, in TrainerBasic.before_epoch(self)
26 def before_epoch(self):
27 """
28 set model to train mode
29 initialize some member variables
30 """
---> 31 self.model.train()
32 self.counter_batch = 0.0
33 self.epo_loss_tr = 0
File /storage2T/software/.pyenv/versions/3.11.0/envs/domainlab-pip/lib/python3.11/site-packages/torch/nn/modules/module.py:2398, in Module.train(self, mode)
2396 self.training = mode
2397 for module in self.children():
-> 2398 module.train(mode)
2399 return self
File /storage2T/software/.pyenv/versions/3.11.0/envs/domainlab-pip/lib/python3.11/site-packages/torch/nn/modules/module.py:2398, in Module.train(self, mode)
2396 self.training = mode
2397 for module in self.children():
-> 2398 module.train(mode)
2399 return self
File /storage2T/software/.pyenv/versions/3.11.0/envs/domainlab-pip/lib/python3.11/site-packages/torchvision/models/feature_extraction.py:324, in DualGraphModule.train(self, mode)
321 # NOTE: Only set self.graph if the current graph is not the desired
322 # one. This saves us from recompiling the graph where not necessary.
323 if mode and not self.training:
--> 324 self.graph = self.train_graph
325 elif not mode and self.training:
326 self.graph = self.eval_graph
File /storage2T/software/.pyenv/versions/3.11.0/envs/domainlab-pip/lib/python3.11/site-packages/torch/nn/modules/module.py:1695, in Module.__getattr__(self, name)
1693 if name in modules:
1694 return modules[name]
-> 1695 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'GraphModule' object has no attribute 'train_graph'
Not an urgent issue since it's easy to just create a virtual environment under Python 3.10, and then pip install domainlab works just fine.
@agisga , we have to increae the python verion i guess, see here https://github.com/snakemake/snakemake/issues/2607#issuecomment-1890979155
https://github.com/marrlab/DomainLab/pull/741
I have tested before on my cluster, newer version of torch works well with domainlab
https://github.com/marrlab/DomainLab/pull/743 @agisga