From 1448e021accfdb03a381651cb5a8be6d1a6e8adf Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期一, 19 二月 2024 14:59:26 +0800
Subject: [PATCH] aishell example

---
 funasr/train_utils/trainer.py |   41 +++++++++++++++++++++++++----------------
 1 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/funasr/train_utils/trainer.py b/funasr/train_utils/trainer.py
index d144019..3cd61a1 100644
--- a/funasr/train_utils/trainer.py
+++ b/funasr/train_utils/trainer.py
@@ -204,25 +204,25 @@
             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,
-                                     ))
+                # print("before, GPU, memory: {:.3f} GB, "
+                #       "{:.3f} GB, "
+                #       "{:.3f} GB, "
+                #       "{:.3f} GB".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,
-                                     ))
+                # print("after, GPU, memory: {:.3f} GB, "
+                #       "{:.3f} GB, "
+                #       "{:.3f} GB, "
+                #       "{:.3f} GB".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
@@ -275,12 +275,21 @@
 
             pbar.update(1)
             if self.local_rank == 0:
+                gpu_info = "GPU, memory: {:.3f} GB, " \
+                           "{:.3f} GB, "\
+                           "{:.3f} GB, "\
+                           "{:.3f} GB".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,
+                                             )
                 description = (
                     f"Train epoch: {epoch}/{self.max_epoch}, "
                     f"step {batch_idx}/{len(self.dataloader_train)}, "
                     f"{speed_stats}, "
                     f"(loss: {loss.detach().cpu().item():.3f}), "
                     f"{[(k, round(v.cpu().item(), 3)) for k, v in stats.items()]}"
+                    f"{gpu_info}"
                 )
                 pbar.set_description(description)
                 if self.writer:

--
Gitblit v1.9.1