From 9e13f028bc4c0442b41801cfc346b4465f10d578 Mon Sep 17 00:00:00 2001
From: 游雁 <zhifu.gzf@alibaba-inc.com>
Date: 星期二, 11 六月 2024 15:11:58 +0800
Subject: [PATCH] fixbug

---
 funasr/models/llm_asr/model.py |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/funasr/models/llm_asr/model.py b/funasr/models/llm_asr/model.py
index f72b2c8..66c416b 100644
--- a/funasr/models/llm_asr/model.py
+++ b/funasr/models/llm_asr/model.py
@@ -714,12 +714,18 @@
             ]
 
         llm_dtype = kwargs.get("llm_dtype", "fp32")
+        if llm_dtype == "fp32":
+            llm_dtype = "fp16" if kwargs.get("fp16", False) else llm_dtype
+            llm_dtype = "bf16" if kwargs.get("bf16", False) else llm_dtype
+
         dtype_map = {"bf16": torch.bfloat16, "fp16": torch.float16, "fp32": torch.float32}
-        with torch.cuda.amp.autocast(dtype=dtype_map[llm_dtype]):
+        with torch.cuda.amp.autocast(
+            enabled=True if llm_dtype != "fp32" else False, dtype=dtype_map[llm_dtype]
+        ):
             label = contents["assistant"][0]
             self.llm = self.llm.to(dtype_map[llm_dtype])
             inputs_embeds = inputs_embeds.to(dtype_map[llm_dtype])
-            attention_mask = attention_mask.to(dtype_map[llm_dtype])
+
             if not kwargs.get("tearchforing", False):
 
                 generated_ids = self.llm.generate(
@@ -739,6 +745,7 @@
                 labels_ids = batch["labels_ids"]
                 labels_ids[labels_ids == -1] = -100
                 attention_mask = batch.get("attention_mask", None)
+                # attention_mask = attention_mask.to(dtype_map[llm_dtype])
                 model_outputs = self.llm(
                     inputs_embeds=inputs_embeds, attention_mask=attention_mask, labels=labels_ids
                 )

--
Gitblit v1.9.1