MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / train_batch

Method train_batch

deepspeed/runtime/pipe/engine.py:337–425  ·  view source on GitHub ↗

Progress the pipeline to train the next batch of data. The engine will ingest ``self.train_batch_size()`` total samples collectively across all workers. An iterator that over training data should be provided as an argument unless ``deepspeed.initialize()`` was provided a tr

(self, data_iter=None)

Source from the content-addressed store, hash-verified

335 self.grad_partition_grad_layer_meta_cache = None
336
337 def train_batch(self, data_iter=None):
338 """Progress the pipeline to train the next batch of data. The engine will ingest
339 ``self.train_batch_size()`` total samples collectively across all workers.
340
341
342 An iterator that over training data should be provided as an argument
343 unless ``deepspeed.initialize()`` was provided a training set. In that event,
344 the training data will automatically be read.
345
346
347 .. warning::
348 A total of ``self.gradient_accumulation_steps()`` entries will be pulled
349 from ``data_iter`` by each pipeline. There must be sufficient
350 data left in ``data_iter`` or else a ``StopIteration`` will halt training.
351
352 DeepSpeed provides a convenience class :class:`deepspeed.utils.RepeatingLoader`
353 that wraps data loaders to automatically restart upon a ``StopIteration``.
354
355 Args:
356 data_iter (Iterator, optional): Iterator of training data.
357
358 Returns:
359 The arithmetic mean of the losses computed this batch.
360 """
361 if not torch._C.is_grad_enabled():
362 raise RuntimeError('train_batch() requires gradients enabled. Use eval_batch() instead.')
363
364 # Curriculum learning could change activation shape
365 if self.curriculum_enabled_legacy():
366 new_difficulty = self.curriculum_scheduler_legacy.update_difficulty( \
367 self.global_steps + 1)
368 if self.global_steps == 0 or self.curriculum_scheduler_legacy.first_step:
369 self.reset_activation_shape()
370 self.curriculum_scheduler_legacy.first_step = False
371 elif new_difficulty != self.curriculum_scheduler_legacy.get_difficulty( \
372 self.global_steps):
373 self.reset_activation_shape()
374
375 if data_iter is not None:
376 self.set_dataiterator(data_iter)
377
378 self.module.train()
379 self.total_loss = None
380 self.total_additional_losses = None
381 self._compute_loss = True
382
383 # Do the work
384 self.timers(TRAIN_BATCH_TIMER).start()
385 sched = schedule.TrainSchedule(micro_batches=self.micro_batches,
386 stages=self.num_stages,
387 stage_id=self.stage_id)
388 self._exec_schedule(sched)
389
390 with torch.no_grad():
391 self.agg_train_loss = self._aggregate_total_loss()
392
393 self.timers(TRAIN_BATCH_TIMER).stop()
394

Callers 4

train_cifarFunction · 0.80
test_pipe_baseMethod · 0.80

Calls 15

set_dataiteratorMethod · 0.95
_exec_scheduleMethod · 0.95
_aggregate_total_lossMethod · 0.95
update_difficultyMethod · 0.80
get_difficultyMethod · 0.80
steps_per_printMethod · 0.80
train_batch_sizeMethod · 0.80
wall_clock_breakdownMethod · 0.80
trainMethod · 0.45
startMethod · 0.45

Tested by 2

test_pipe_baseMethod · 0.64