Add compatibility with skip_memory_metrics for mps device #29264
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do
This PR makes mps device compatible with memory profiling integrated in Trainer (
skip_memory_metrics
=False). However, we can't get the information on the peak memory sincetorch.mps.max_memory_allocated()
doesn't exist yet.Fixes #27181
Tested on mac and I get the following output for a simple Trainer example:
{'train_runtime': 7.8136, 'train_samples_per_second': 24.572, 'train_steps_per_second': 3.072, 'train_loss': 5.870065689086914, 'init_mem_cpu_alloc_delta': 950272, 'init_mem_gpu_alloc_delta': 512, 'init_mem_cpu_peaked_delta': 16384, 'init_mem_gpu_peaked_delta': 'Not available', 'train_mem_cpu_alloc_delta': 38354944, 'train_mem_gpu_alloc_delta': 2304, 'train_mem_cpu_peaked_delta': 16384, 'train_mem_gpu_peaked_delta': 'Not available', 'before_init_mem_cpu': 351813632, 'before_init_mem_gpu': 0, 'epoch': 3.0}