lm-sys / lm-sys/FastChat

[Bug] the bug of generating Llama2 conversation template

Open
#2,217 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
39.5k
Forks
4.8k
PR merge metrics
No merged PRs in 30d

Description

```python
# llama2 template
# reference: https://github.com/facebookresearch/llama/blob/cfc3fc8c1968d390eb830e65c63865e980873a06/llama/generation.py#L212
register_conv_template(
Conversation(
name="llama-2",
system_template="[INST] <>\n{system_message}\n<>\n\n",
roles=("[INST]", "[/INST]"),
messages=(),
offset=0,
sep_style=SeparatorStyle.LLAMA2,
sep=" ",
sep2=" ",
stop_token_ids=[2],
)
)
```
```python
def get_prompt(self) -> str:
#......
elif self.sep_style == SeparatorStyle.LLAMA2:
seps = [self.sep, self.sep2]
ret = ""
for i, (role, message) in enumerate(self.messages):
if message:
if i == 0:
ret += system_prompt + message
else:
ret += role + " " + message + seps[i % 2]
else:
ret += role
return ret
#......
```
when i=0, `ret += system_prompt + message`.However, when using preprocess function:
```python
def preprocess(
sources,
tokenizer: transformers.PreTrainedTokenizer,
) -> Dict:
# ......
sep = conv.sep + conv.roles[1] + ": "
for conversation, target in zip(conversations, targets):
# ......
parts = turn.split(sep)
```
`parts` can't be split by `seq`, because the `seq = " " + seps[i % 2]`.In fact, there is no this " " in `parts`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the LLAMA2 branch of get_prompt with preprocess, especially the generated separators and the string passed to split. Confirm the expected Llama2 conversation format from the linked reference, then make the prompt generation and preprocessing agree so the conversation is parsed successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.