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 aMemoryTrainingListener
that does not output data to a file.MemoryTrainingListener
(String outputDir) Constructs aMemoryTrainingListener
that outputs data in the given directory. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
collectMemoryInfo
(Metrics metrics) Collects memory information.static void
dumpMemoryInfo
(Metrics metrics, String logDir) Dump memory metrics into log directory.void
onTrainingBatch
(Trainer trainer, TrainingListener.BatchData batchData) Listens to the end of training one batch of data during training.void
onTrainingEnd
(Trainer trainer) Listens to the end of training.void
onValidationBatch
(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 aMemoryTrainingListener
that does not output data to a file. -
MemoryTrainingListener
Constructs aMemoryTrainingListener
that 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:
onTrainingBatch
in interfaceTrainingListener
- Overrides:
onTrainingBatch
in 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:
onValidationBatch
in interfaceTrainingListener
- Overrides:
onValidationBatch
in classTrainingListenerAdapter
- Parameters:
trainer
- the trainer the listener is attached tobatchData
- the data from the batch
-
onTrainingEnd
Listens to the end of training.- Specified by:
onTrainingEnd
in interfaceTrainingListener
- Overrides:
onTrainingEnd
in classTrainingListenerAdapter
- Parameters:
trainer
- the trainer the listener is attached to
-
collectMemoryInfo
Collects memory information. In order to collect metrics, theTrainer
must set metrics. Monitor the metrics by enabling the following flag in the command line arguments: -Dcollect-memory=true- Parameters:
metrics
-Metrics
to store memory information
-
dumpMemoryInfo
Dump memory metrics into log directory.- Parameters:
metrics
- metrics contains memory informationlogDir
- output log directory
-