Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: only one element tensors can be converted to Python scalars #41

Open
sonu-gupta opened this issue Jun 22, 2022 · 0 comments

Comments

@sonu-gupta
Copy link

Hi, I'm trying to run the example code for sentiment classification but it gives me this error. It looks like the issue arises due to the way tensor size is calculated.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-2a229acd2f86> in <module>
    171         valid_dataset=valid_dataset,
    172         callbacks=[es],
--> 173         config=config,
    174     )

~/anaconda3/envs/bertopic/lib/python3.7/site-packages/tez/model/tez.py in fit(self, train_dataset, valid_dataset, config, **kwargs)
    455         for _ in range(self.config.epochs):
    456             self.train_state = enums.TrainingState.EPOCH_START
--> 457             self.train(self.train_loader, losses)
    458             if self.valid_loader and self.config.val_strategy == "epoch":
    459                 self.validate(self.valid_loader)

~/anaconda3/envs/bertopic/lib/python3.7/site-packages/tez/model/tez.py in train(self, data_loader, losses)
    399             self.train_state = enums.TrainingState.TRAIN_STEP_START
    400             loss, metrics = self.train_step(data)
--> 401             losses, monitor = self._update_loss_metrics(losses, loss, metrics, data_loader)
    402             self.train_state = enums.TrainingState.TRAIN_STEP_END
    403             if self.valid_loader and self.config.val_strategy == "batch":

~/anaconda3/envs/bertopic/lib/python3.7/site-packages/tez/model/tez.py in _update_loss_metrics(self, losses, loss, metrics, data_loader)
    366     def _update_loss_metrics(self, losses, loss, metrics, data_loader):
    367         if self.model_state == enums.ModelState.TRAIN:
--> 368             losses.update(loss.item() * self.config.gradient_accumulation_steps, data_loader.batch_size)
    369         else:
    370             losses.update(loss.item(), data_loader.batch_size)

ValueError: only one element tensors can be converted to Python scalars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant