When running MOFA with muon an error can occur where the model cannot find the training stats when it goes to save the results. This is outlined in this issue in the R repository (linking it here because it seems more relevant here).
Output
Loaded view='rna' group='group1' with N=5412 samples and D=23519 features...
Loaded view='atac' group='group1' with N=5412 samples and D=135866 features...
Warning: 1 features(s) in view 0 have zero variance, consider removing them before training the model...
Model options:
- Automatic Relevance Determination prior on the factors: True
- Automatic Relevance Determination prior on the weights: True
- Spike-and-slab prior on the factors: False
- Spike-and-slab prior on the weights: True
Likelihoods:
- View 0 (rna): poisson
- View 1 (atac): bernoulli
GPU mode is activated
######################################
## Training the model with seed 1 ##
######################################
Attempting to save the model at the current iteration...
Saving model in /tmp/mofa_20240522-102240_interrupted.hdf5...
Note: the model to be saved is not trained.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File ~/.local/lib/python3.8/site-packages/mofapy2/run/entry_point.py:26, in keyboardinterrupt_saver.<locals>.saver(self, *args, **kwargs)
25 try:
---> 26 func(self, *args, **kwargs)
27 # Internal methods will raise TypeError when interrupted
File ~/.local/lib/python3.8/site-packages/mofapy2/run/entry_point.py:1400, in entry_point.run(self)
1399 # Train the model
-> 1400 train_model(self.model)
File ~/.local/lib/python3.8/site-packages/mofapy2/build_model/train_model.py:26, in train_model(model)
24 print("\n")
---> 26 model.iterate()
28 print("\n")
File ~/.local/lib/python3.8/site-packages/mofapy2/core/BayesNet.py:267, in BayesNet.iterate(self)
266 convergence_token = 1
--> 267 elbo.iloc[0] = self.precompute()
268 number_factors[0] = self.dim["K"]
File ~/.local/lib/python3.8/site-packages/mofapy2/core/BayesNet.py:225, in BayesNet.precompute(self)
224 for n in self.nodes:
--> 225 self.nodes[n].precompute(self.options)
227 # Precompute ELBO
File ~/.local/lib/python3.8/site-packages/mofapy2/core/nodes/multiview_nodes.py:115, in Multiview_Node.precompute(self, options)
114 for m in self.activeM:
--> 115 self.nodes[m].precompute(options)
File ~/.local/lib/python3.8/site-packages/mofapy2/core/nodes/nongaussian_nodes.py:206, in Poisson_PseudoY.precompute(self, options)
205 self.updateParameters()
--> 206 self.updateExpectations()
File ~/.local/lib/python3.8/site-packages/mofapy2/core/nodes/nongaussian_nodes.py:222, in Poisson_PseudoY.updateExpectations(self)
218 tau = self.markov_blanket["Tau"].getValue()
219 self.E = (
220 self.params["zeta"]
221 - sigmoid(self.params["zeta"])
--> 222 * (1 - self.obs / self.ratefn(self.params["zeta"]))
223 / tau
224 )
225 self.E[self.mask] = 0.0
File cupy/_core/core.pyx:1697, in cupy._core.core._ndarray_base.__array_ufunc__()
File cupy/_core/_kernel.pyx:1283, in cupy._core._kernel.ufunc.__call__()
File cupy/_core/_kernel.pyx:159, in cupy._core._kernel._preprocess_args()
File cupy/_core/_kernel.pyx:145, in cupy._core._kernel._preprocess_arg()
TypeError: Unsupported type <class 'numpy.ndarray'>
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
Cell In [4], line 1
----> 1 mu.tl.mofa(mdata, use_layer = "raw", gpu_mode=True)
File ~/.local/lib/python3.8/site-packages/muon/_core/tools.py:586, in mofa(data, groups_label, use_raw, use_layer, use_var, use_obs, likelihoods, n_factors, scale_views, scale_groups, center_groups, ard_weights, ard_factors, spikeslab_weights, spikeslab_factors, n_iterations, convergence_mode, use_float32, gpu_mode, gpu_device, svi_mode, svi_batch_size, svi_learning_rate, svi_forgetting_rate, svi_start_stochastic, smooth_covariate, smooth_warping, smooth_kwargs, save_parameters, save_data, save_metadata, seed, outfile, expectations, save_interrupted, verbose, quiet, copy)
584 ent.build()
585 logging.info(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] Running the model...")
--> 586 ent.run()
588 if (
589 smooth_kwargs is not None
590 and "new_values" in smooth_kwargs
591 and smooth_kwargs["new_values"]
592 and smooth_covariate
593 ):
594 logging.info(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] Interpolating factors...")
File ~/.local/lib/python3.8/site-packages/mofapy2/run/entry_point.py:39, in keyboardinterrupt_saver.<locals>.saver(self, *args, **kwargs)
34 else:
35 tmp_file = os.path.join(
36 "/tmp",
37 "mofa_{}_interrupted.hdf5".format(strftime("%Y%m%d-%H%M%S")),
38 )
---> 39 self.save(outfile=tmp_file)
40 print(
41 "Saved partially trained model in {}. Exiting now.".format(tmp_file)
42 )
43 else:
File ~/.local/lib/python3.8/site-packages/mofapy2/run/entry_point.py:1743, in entry_point.save(self, outfile, save_data, save_parameters, expectations)
1740 tmp.saveSmoothOptions(self.smooth_opts)
1742 # Save training statistics
-> 1743 tmp.saveTrainingStats()
1745 # Save variance explained values
1746 tmp.saveVarianceExplained()
File ~/.local/lib/python3.8/site-packages/mofapy2/build_model/save_model.py:741, in saveModel.saveTrainingStats(self)
738 """Method to save the training statistics"""
740 # Get training statistics
--> 741 stats = self.model.getTrainingStats()
743 # Create HDF5 group
744 stats_grp = self.hdf5.create_group("training_stats")
File ~/.local/lib/python3.8/site-packages/mofapy2/core/BayesNet.py:502, in BayesNet.getTrainingStats(self)
500 def getTrainingStats(self):
501 """Method to return training statistics"""
--> 502 return self.train_stats
AttributeError: 'BayesNet' object has no attribute 'train_stats'
When running MOFA with muon an error can occur where the model cannot find the training stats when it goes to save the results. This is outlined in this issue in the R repository (linking it here because it seems more relevant here).
Output
Pip freeze: