Package ai.djl.training.listener
Class MemoryTrainingListener
java.lang.Object
ai.djl.training.listener.TrainingListenerAdapter
ai.djl.training.listener.MemoryTrainingListener
- All Implemented Interfaces:
TrainingListener
TrainingListener that collects the memory usage information.
If an outputDir is provided, the file "$outputDir/memory.log" will be created after training with the memory usage results.
-
Nested Class Summary
Nested classes/interfaces inherited from interface ai.djl.training.listener.TrainingListener
TrainingListener.BatchData, TrainingListener.Defaults -
Constructor Summary
ConstructorsConstructorDescriptionConstructs aMemoryTrainingListenerthat does not output data to a file.MemoryTrainingListener(String outputDir) Constructs aMemoryTrainingListenerthat outputs data in the given directory. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcollectMemoryInfo(Metrics metrics) Collects memory information.static voiddumpMemoryInfo(Metrics metrics, String logDir) Dump memory metrics into log directory.voidonTrainingBatch(Trainer trainer, TrainingListener.BatchData batchData) Listens to the end of training one batch of data during training.voidonTrainingEnd(Trainer trainer) Listens to the end of training.voidonValidationBatch(Trainer trainer, TrainingListener.BatchData batchData) Listens to the end of validating one batch of data during validation.Methods inherited from class ai.djl.training.listener.TrainingListenerAdapter
onEpoch, onTrainingBegin
-
Constructor Details
-
MemoryTrainingListener
public MemoryTrainingListener()Constructs aMemoryTrainingListenerthat does not output data to a file. -
MemoryTrainingListener
Constructs aMemoryTrainingListenerthat outputs data in the given directory.If an output directory is provided, the file "$outputDir/memory.log" will be created after training with the memory usage results. The log file consists of heap bytes, non-heap bytes, cpu percentage and rss bytes consumption along with the timestamps.
- Parameters:
outputDir- the directory to output the tracked memory data in
-
-
Method Details
-
onTrainingBatch
Listens to the end of training one batch of data during training.- Specified by:
onTrainingBatchin interfaceTrainingListener- Overrides:
onTrainingBatchin classTrainingListenerAdapter- Parameters:
trainer- the trainer the listener is attached tobatchData- the data from the batch
-
onValidationBatch
Listens to the end of validating one batch of data during validation.- Specified by:
onValidationBatchin interfaceTrainingListener- Overrides:
onValidationBatchin classTrainingListenerAdapter- Parameters:
trainer- the trainer the listener is attached tobatchData- the data from the batch
-
onTrainingEnd
Listens to the end of training.- Specified by:
onTrainingEndin interfaceTrainingListener- Overrides:
onTrainingEndin classTrainingListenerAdapter- Parameters:
trainer- the trainer the listener is attached to
-
collectMemoryInfo
Collects memory information. In order to collect metrics, theTrainermust set metrics. Monitor the metrics by enabling the following flag in the command line arguments: -Dcollect-memory=true- Parameters:
metrics-Metricsto store memory information
-
dumpMemoryInfo
Dump memory metrics into log directory.- Parameters:
metrics- metrics contains memory informationlogDir- output log directory
-