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)
| 407 | return self.agg_train_loss |
| 408 | |
| 409 | def eval_batch(self, |
| 410 | data_iter, |
| 411 | return_logits=False, |
| 412 | compute_loss=True, |
| 413 | reduce_output='avg', |
| 414 | bcast_loss=True, |
| 415 | num_micro_batches=None): |
| 416 | """Evaluate the pipeline on a batch of data from ``data_iter``. The |
| 417 | engine will evaluate ``self.train_batch_size()`` total samples |
| 418 | collectively across all workers. |
| 419 | |
| 420 | This method is equivalent to: |
| 421 | |
| 422 | .. code-block:: python |
| 423 | |
| 424 | module.eval() |
| 425 | with torch.no_grad(): |
| 426 | output = module(batch) |
| 427 | |
| 428 | .. warning:: |
| 429 | A total of ``self.gradient_accumulation_steps()`` entries will be pulled |
| 430 | from ``data_iter`` by each pipeline. There must be sufficient |
| 431 | data left in ``data_iter`` or else a ``StopIteration`` will halt training. |
| 432 | |
| 433 | DeepSpeed provides a convenience class :class:`deepspeed.utils.RepeatingLoader` |
| 434 | that wraps data loaders to automatically restart upon a ``StopIteration``. |
| 435 | |
| 436 | Args: |
| 437 | data_iter (Iterator): Iterator of data to evaluate. |
| 438 | |
| 439 | Returns: |
| 440 | The arithmetic mean of the losses computed this batch. |
| 441 | """ |
| 442 | self.eval_return_logits = return_logits |
| 443 | self.module.eval() |
| 444 | |
| 445 | eval_output = None |
| 446 | |
| 447 | self._compute_loss = compute_loss |
| 448 | |
| 449 | # Use the provided data iterator |
| 450 | train_iterator = self.data_iterator |
| 451 | self.set_dataiterator(data_iter) |
| 452 | |
| 453 | # set the number micro batches in case the user chose value than training |
| 454 | micro_batches = self.micro_batches if num_micro_batches is None else num_micro_batches |
| 455 | |
| 456 | # Do the work |
| 457 | sched = self._inference_schedule(micro_batches) |
| 458 | |
| 459 | # prevent dead-lock with multiple evals sequence |
| 460 | dist.barrier() |
| 461 | |
| 462 | with torch.no_grad(): |
| 463 | self._exec_schedule(sched) |
| 464 | |
| 465 | if self.is_last_stage(): |
| 466 | eval_output = self._reduce_outputs(self.fwd_outputs, reduce=reduce_output, micro_batches=micro_batches) |