recommenders-team / recommenders

Best Practices on Recommendation Systems
https://recommenders-team.github.io/recommenders/intro.html
MIT License
19.32k stars 3.11k forks source link

[BUG] Cornac BiVAE test failing due to csc_matrix attribute error #2126

Open miguelgfierro opened 4 months ago

miguelgfierro commented 4 months ago

Description

E           bivae = cornac.models.BiVAECF(
E               k=LATENT_DIM,
E               encoder_structure=ENCODER_DIMS,
E               act_fn=ACT_FUNC,
E               likelihood=LIKELIHOOD,
E               n_epochs=NUM_EPOCHS,
E               batch_size=BATCH_SIZE,
E               learning_rate=LEARNING_RATE,
E               seed=SEED,
E               use_gpu=torch.cuda.is_available(),
E               verbose=True
E           )
E           
E           with Timer() as t:
E               bivae.fit(train_set)
E           print("Took *** seconds for training.".format(t))
E           ------------------
E           
E           ----- stderr -----
E           
  0%|          | 0/500 [00:00<?, ?it/s]
E           ----- stderr -----
E           
  0%|          | 0/500 [00:00<?, ?it/s]
E           ----- stderr -----
E           
E           ------------------
E           
E           ---------------------------------------------------------------------------
E           AttributeError                            Traceback (most recent call last)
E           Cell In[6], line 15
E                 1 bivae = cornac.models.BiVAECF(
E                 2     k=LATENT_DIM,
E                 3     encoder_structure=ENCODER_DIMS,
E              (...)
E                11     verbose=True
E                12 )
E                14 with Timer() as t:
E           ---> 15     bivae.fit(train_set)
E                16 print("Took *** seconds for training.".format(t))
E           
E           File /azureml-envs/azureml_adf614c86c43311fb41235e[662](https://github.com/recommenders-team/recommenders/actions/runs/9745905406/job/26897451776#step:3:669)27b9b3/lib/python3.10/site-packages/cornac/models/bivaecf/recom_bivaecf.py:178, in BiVAECF.fit(self, train_set, val_set)
E               166         num_users = train_set.matrix.shape[0]
E               167         self.bivae = BiVAE(
E               168             k=self.k,
E               169             user_encoder_structure=[num_items] + self.encoder_structure,
E              (...)
E               175             batch_size=self.batch_size,
E               176         ).to(self.device)
E           --> 178     learn(
E               179 self.bivae,
E               180 train_set,
E               181 n_epochs=self.n_epochs,
E               182 batch_size=self.batch_size,
E               183 learn_rate=self.learning_rate,
E               184 beta_kl=self.beta_kl,
E               185 verbose=self.verbose,
E               186 device=self.device,
E               187 )
E               188 elif self.verbose:
E               189     print("%s is trained already (trainable = False)" % (self.name))
E           
E           File /azureml-envs/azureml_adf614c86c43311fb41235e66227b9b3/lib/python3.10/site-packages/cornac/models/bivaecf/bivae.py:201, in learn(bivae, train_set, n_epochs, batch_size, learn_rate, beta_kl, verbose, device, dtype)
E               199 for i_ids in train_set.item_iter(batch_size, shuffle=False):
E               200     i_batch = tx[i_ids, :]
E           --> 201     i_batch = i_batch.A
E               202     i_batch = torch.tensor(i_batch, dtype=dtype, device=device)
E               204     # Reconstructed batch
E           
E           AttributeError: 'csc_matrix' object has no attribute 'A'

In which platform does it happen?

VM

How do we replicate the issue?

https://github.com/recommenders-team/recommenders/actions/runs/9745905406/job/26897451776

Expected behavior (i.e. solution)

Other Comments

miguelgfierro commented 4 months ago

It might be related to the newest version of scipy https://pypi.org/project/scipy/#history 1.14.0

SimonYansenZhao commented 4 months ago

@miguelgfierro @anargyri This issue is actually from cornac, and I found cornac fixed the issue by setting numpy<2.0.0 and scipy<=1.13.1 (Jun 29, 2024) in the master branch of cornac which is supposed to be in the next version of it. So I think we can do the same thing and wait until they solve the issue. Please let me know if you have other suggestions.

As of Jul 9, 2024 Python package latest version (release date) previous version (release date)
cornac 2.2.1 (May 24, 2024)
scipy 1.14.0 (Jun 25, 2024) 1.13.1 (May 23, 2024)
numpy 2.0..0 (Jun 16, 2024) 1.26.4 (Feb 6, 2024)
SimonYansenZhao commented 4 months ago

And I just found the issue had been resolved in https://github.com/PreferredAI/cornac/pull/631. We just need to wait for the next release of cornac.