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')
| 361 | return self.agg_train_loss |
| 362 | |
| 363 | def eval_batch(self, data_iter, return_logits=False, compute_loss=True, reduce_output='avg'): |
| 364 | """Evaluate the pipeline on a batch of data from ``data_iter``. The |
| 365 | engine will evaluate ``self.train_batch_size()`` total samples |
| 366 | collectively across all workers. |
| 367 | |
| 368 | This method is equivalent to: |
| 369 | |
| 370 | .. code-block:: python |
| 371 | |
| 372 | module.eval() |
| 373 | with torch.no_grad(): |
| 374 | output = module(batch) |
| 375 | |
| 376 | .. warning:: |
| 377 | A total of ``self.gradient_accumulation_steps()`` entries will be pulled |
| 378 | from ``data_iter`` by each pipeline. There must be sufficient |
| 379 | data left in ``data_iter`` or else a ``StopIteration`` will halt training. |
| 380 | |
| 381 | DeepSpeed provides a convenience class :class:`deepspeed.utils.RepeatingLoader` |
| 382 | that wraps data loaders to automatically restart upon a ``StopIteration``. |
| 383 | |
| 384 | Args: |
| 385 | data_iter (Iterator): Iterator of data to evaluate. |
| 386 | |
| 387 | Returns: |
| 388 | The arithmetic mean of the losses computed this batch. |
| 389 | """ |
| 390 | self.eval_return_logits = return_logits |
| 391 | self.module.eval() |
| 392 | |
| 393 | # Curriculum learning could change activation shape |
| 394 | if self.curriculum_enabled_legacy(): |
| 395 | new_difficulty = self.curriculum_scheduler_legacy.update_difficulty( \ |
| 396 | self.global_steps + 1) |
| 397 | if self.global_steps == 0 or self.curriculum_scheduler_legacy.first_step: |
| 398 | self.reset_activation_shape() |
| 399 | self.curriculum_scheduler_legacy.first_step = False |
| 400 | elif new_difficulty != self.curriculum_scheduler_legacy.get_difficulty( \ |
| 401 | self.global_steps): |
| 402 | self.reset_activation_shape() |
| 403 | |
| 404 | eval_output = None |
| 405 | |
| 406 | self._compute_loss = compute_loss |
| 407 | |
| 408 | # Use the provided data iterator |
| 409 | train_iterator = self.data_iterator |
| 410 | self.set_dataiterator(data_iter) |
| 411 | |
| 412 | # Do the work |
| 413 | sched = schedule.InferenceSchedule(micro_batches=self.micro_batches, |
| 414 | stages=self.num_stages, |
| 415 | stage_id=self.stage_id) |
| 416 | |
| 417 | # prevent dead-lock with multiple evals sequence |
| 418 | dist.barrier() |
| 419 | |
| 420 | with torch.no_grad(): |
nothing calls this directly
no test coverage detected