From b0f1e0606539335303499cbdc11755204d3140dc Mon Sep 17 00:00:00 2001 From: parap1uie-s Date: Mon, 24 Apr 2023 19:31:30 +0800 Subject: [PATCH 1/4] Enable input_embeds for ChatGLM / ChatGLMForConditionalGeneration Fix typo and minor bugs to enable the input_embeds input rather than input_ids --- paddlenlp/transformers/chatglm/modeling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paddlenlp/transformers/chatglm/modeling.py b/paddlenlp/transformers/chatglm/modeling.py index 88d0a42db93d..07bc887587fc 100644 --- a/paddlenlp/transformers/chatglm/modeling.py +++ b/paddlenlp/transformers/chatglm/modeling.py @@ -501,13 +501,13 @@ def forward( elif input_ids is not None: batch_size, seq_length = input_ids.shape[:2] elif inputs_embeds is not None: - batch_size, seq_length, _ = inputs_embeds.shape[:2] + batch_size, seq_length = inputs_embeds.shape[:2] else: raise ValueError("You have to specify either input_ids or inputs_embeds") if inputs_embeds is None: inputs_embeds = self.word_embeddings(input_ids) - inputs_embeds = inputs_embeds.transpose([1, 0, 2]) + inputs_embeds = inputs_embeds.transpose([1, 0, 2]) if cache is None: if self.config.pre_seq_len is not None: @@ -826,7 +826,7 @@ def update_model_kwargs_for_generation( def forward( self, - input_ids, + input_ids=None, position_ids=None, attention_mask=None, cache=None, From 499f10fb0d8afd89d3fdc941d01010c9ff88656f Mon Sep 17 00:00:00 2001 From: parap1uie-s Date: Tue, 25 Apr 2023 09:24:59 +0800 Subject: [PATCH 2/4] Update modeling.py --- paddlenlp/transformers/chatglm/modeling.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/paddlenlp/transformers/chatglm/modeling.py b/paddlenlp/transformers/chatglm/modeling.py index 07bc887587fc..eb64e010a5cb 100644 --- a/paddlenlp/transformers/chatglm/modeling.py +++ b/paddlenlp/transformers/chatglm/modeling.py @@ -690,6 +690,10 @@ def forward( use_cache: bool = None, return_dict: bool = None, ): + if input_ids is None: + assert position_ids is not None, "`position_ids` must be explicitly specified when input_ids is None." + assert attention_mask is not None, "`attention_mask` must be explicitly specified when input_ids is None." + if attention_mask is None: attention_mask = self.get_masks(input_ids) From 56298df6f062c12cbe464ade755dd221aa9642d1 Mon Sep 17 00:00:00 2001 From: parap1uie-s Date: Thu, 27 Apr 2023 09:22:40 +0800 Subject: [PATCH 3/4] Update modeling.py --- paddlenlp/transformers/chatglm/modeling.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/paddlenlp/transformers/chatglm/modeling.py b/paddlenlp/transformers/chatglm/modeling.py index eb64e010a5cb..1be9b2e52c8b 100644 --- a/paddlenlp/transformers/chatglm/modeling.py +++ b/paddlenlp/transformers/chatglm/modeling.py @@ -691,8 +691,10 @@ def forward( return_dict: bool = None, ): if input_ids is None: - assert position_ids is not None, "`position_ids` must be explicitly specified when input_ids is None." - assert attention_mask is not None, "`attention_mask` must be explicitly specified when input_ids is None." + assert position_ids is not None, \ + "`position_ids` must be explicitly specified when input_ids is None." + assert attention_mask is not None, \ + "`attention_mask` must be explicitly specified when input_ids is None." if attention_mask is None: attention_mask = self.get_masks(input_ids) From e69f0968d2d63990aa4aefe71dceeef353a0d631 Mon Sep 17 00:00:00 2001 From: parap1uie-s Date: Thu, 27 Apr 2023 09:28:58 +0800 Subject: [PATCH 4/4] Update modeling.py --- paddlenlp/transformers/chatglm/modeling.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/paddlenlp/transformers/chatglm/modeling.py b/paddlenlp/transformers/chatglm/modeling.py index 1be9b2e52c8b..eb64e010a5cb 100644 --- a/paddlenlp/transformers/chatglm/modeling.py +++ b/paddlenlp/transformers/chatglm/modeling.py @@ -691,10 +691,8 @@ def forward( return_dict: bool = None, ): if input_ids is None: - assert position_ids is not None, \ - "`position_ids` must be explicitly specified when input_ids is None." - assert attention_mask is not None, \ - "`attention_mask` must be explicitly specified when input_ids is None." + assert position_ids is not None, "`position_ids` must be explicitly specified when input_ids is None." + assert attention_mask is not None, "`attention_mask` must be explicitly specified when input_ids is None." if attention_mask is None: attention_mask = self.get_masks(input_ids)