From 6fd83d23ee64280d30fd99f0fe2ca0f52903dca1 Mon Sep 17 00:00:00 2001
From: Marlowe <54339989+ZihanLiao@users.noreply.github.com>
Date: 星期五, 14 六月 2024 10:36:28 +0800
Subject: [PATCH] fix paramter 'quantize' unused issue (#1813)

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

diff --git a/funasr/models/llm_asr/model.py b/funasr/models/llm_asr/model.py
index 5f15309..519918c 100644
--- a/funasr/models/llm_asr/model.py
+++ b/funasr/models/llm_asr/model.py
@@ -684,6 +684,13 @@
         # audio encoder
         speech = batch["speech"]
         speech_lengths = batch["speech_lengths"][:, 0]
+        # fp16
+        if kwargs.get("fp16", False):
+            speech = speech.to(torch.float16)
+            encoder_out_lens = encoder_out_lens.to(torch.float16)
+        elif kwargs.get("bf16", False):
+            speech = speech.to(torch.bfloat16)
+            encoder_out_lens = encoder_out_lens.to(torch.bfloat16)
         encoder_out, encoder_out_lens = self.audio_encoder(speech.permute(0, 2, 1), speech_lengths)
 
         # audio_adaptor
@@ -710,9 +717,9 @@
         dtype_map = {"bf16": torch.bfloat16, "fp16": torch.float16, "fp32": torch.float32}
         with torch.cuda.amp.autocast(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])
+            # self.llm = self.llm.to(dtype_map[llm_dtype])
+            # inputs_embeds = inputs_embeds.to(dtype_map[llm_dtype])
+
             if not kwargs.get("tearchforing", False):
 
                 generated_ids = self.llm.generate(
@@ -732,6 +739,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