| | |
| | | my_context = self.model.no_sync if batch_idx % accum_grad != 0 else nullcontext |
| | | with my_context(): |
| | | time2 = time.perf_counter() |
| | | print("before, GPU, memory: {:.1} MB, " |
| | | "{:.1} MB, " |
| | | "{:.1} MB, " |
| | | "{:.1} MB".format(torch.cuda.memory_allocated()/1024/1024/1024, |
| | | torch.cuda.max_memory_allocated()/1024/1024/1024, |
| | | torch.cuda.memory_reserved()/1024/1024/1024, |
| | | torch.cuda.max_memory_reserved()/1024/1024/1024, |
| | | )) |
| | | |
| | | retval = self.model(**batch) |
| | | torch.cuda.empty_cache() |
| | | print("after, GPU, memory: {:.1} MB, " |
| | | "{:.1} MB, " |
| | | "{:.1} MB, " |
| | | "{:.1} MB".format(torch.cuda.memory_allocated()/1024/1024/1024, |
| | | torch.cuda.max_memory_allocated()/1024/1024/1024, |
| | | torch.cuda.memory_reserved()/1024/1024/1024, |
| | | torch.cuda.max_memory_reserved()/1024/1024/1024, |
| | | )) |
| | | time3 = time.perf_counter() |
| | | speed_stats["forward_time"] = f"{time3 - time2:0.3f}" |
| | | loss, stats, weight = retval |