abhishekkrthakur/tez

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

sonu-gupta opened this issue · 0 comments

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