Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llm/predict/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,9 @@ def predict(self, input_texts: str | list[str], return_tokens=False):
def _preprocess(self, source):
BlockInferencePredictorMixin._preprocess(self, source)
for i, text in enumerate(source):
tokens = self.tokenizer(text, return_tensors="np", padding=False, truncation=True, max_length=(self.config.src_length))
tokens = self.tokenizer(
text, return_tensors="np", padding=False, truncation=True, max_length=(self.config.src_length)
)
input_ids = tokens["input_ids"][0]
length = len(input_ids)
need_block_nums = (
Expand Down Expand Up @@ -1270,7 +1272,7 @@ def create_predictor(

# TODO(wj-Mcat): fix llama tokenzier pad_token bug
if (isinstance(tokenizer, (LlamaTokenizer, Llama3Tokenizer))) and not tokenizer.pad_token:
tokenizer.pad_token = tokenizer.bos_token
tokenizer.pad_token = tokenizer.eos_token
Copy link
Collaborator Author

@yuanlehome yuanlehome Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个解决动态图推理
390d2e730b547908bde5554687b68317


config = AutoConfig.from_pretrained(predictor_args.model_name_or_path)

Expand Down
9 changes: 7 additions & 2 deletions paddlenlp/generation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,13 @@ def _build_fast(self, kwargs):

def set_pad_token_id(self, pad_token_id, eos_token_id):
if pad_token_id is None and eos_token_id is not None:
print("Setting `pad_token_id` to `eos_token_id`:{} for " "open-end generation.".format(eos_token_id))
pad_token_id = eos_token_id
logger.warning(
"Setting `pad_token_id` to `eos_token_id`:{} for " "open-end generation.".format(eos_token_id)
)
if isinstance(eos_token_id, list):
Copy link
Collaborator Author

@yuanlehome yuanlehome Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个解决动转静
52000b7d71117856c208ddb35beb6bd6

pad_token_id = eos_token_id[0]
else:
pad_token_id = eos_token_id
return pad_token_id

@paddle.no_grad()
Expand Down