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