Evaluate the pipeline on a batch of data from ``data_iter``. The engine will evaluate ``self.train_batch_size()`` total samples collectively across all workers. This method is equivalent to: .. code-block:: python module.eval() with torch.no
(self,
data_iter,
return_logits=False,
compute_loss=True,
reduce_output='avg',
bcast_loss=True,
num_micro_batches=None)
| 429 | return self.agg_train_loss |
| 430 | |
| 431 | def eval_batch(self, |
| 432 | data_iter, |
| 433 | return_logits=False, |
| 434 | compute_loss=True, |
| 435 | reduce_output='avg', |
| 436 | bcast_loss=True, |
| 437 | num_micro_batches=None): |
| 438 | """Evaluate the pipeline on a batch of data from ``data_iter``. The |
| 439 | engine will evaluate ``self.train_batch_size()`` total samples |
| 440 | collectively across all workers. |
| 441 | |
| 442 | This method is equivalent to: |
| 443 | |
| 444 | .. code-block:: python |
| 445 | |
| 446 | module.eval() |
| 447 | with torch.no_grad(): |
| 448 | output = module(batch) |
| 449 | |
| 450 | .. warning:: |
| 451 | A total of ``self.gradient_accumulation_steps()`` entries will be pulled |
| 452 | from ``data_iter`` by each pipeline. There must be sufficient |
| 453 | data left in ``data_iter`` or else a ``StopIteration`` will halt training. |
| 454 | |
| 455 | DeepSpeed provides a convenience class :class:`deepspeed.utils.RepeatingLoader` |
| 456 | that wraps data loaders to automatically restart upon a ``StopIteration``. |
| 457 | |
| 458 | Args: |
| 459 | data_iter (Iterator): Iterator of data to evaluate. |
| 460 | |
| 461 | Returns: |
| 462 | The arithmetic mean of the losses computed this batch. |
| 463 | """ |
| 464 | self.eval_return_logits = return_logits |
| 465 | self.module.eval() |
| 466 | |
| 467 | # Curriculum learning could change activation shape |
| 468 | if self.curriculum_enabled_legacy(): |
| 469 | new_difficulty = self.curriculum_scheduler_legacy.update_difficulty( \ |
| 470 | self.global_steps + 1) |
| 471 | if self.global_steps == 0 or self.curriculum_scheduler_legacy.first_step: |
| 472 | self.reset_activation_shape() |
| 473 | self.curriculum_scheduler_legacy.first_step = False |
| 474 | elif new_difficulty != self.curriculum_scheduler_legacy.get_difficulty( \ |
| 475 | self.global_steps): |
| 476 | self.reset_activation_shape() |
| 477 | |
| 478 | eval_output = None |
| 479 | |
| 480 | self._compute_loss = compute_loss |
| 481 | |
| 482 | # Use the provided data iterator |
| 483 | train_iterator = self.data_iterator |
| 484 | self.set_dataiterator(data_iter) |
| 485 | |
| 486 | # set the number micro batches in case the user chose value than training |
| 487 | micro_batches = self.micro_batches if num_micro_batches is None else num_micro_batches |
| 488 |