lm-sys / lm-sys/FastChat

inference truncate causes “output_ids” to be incorrectly sliced

Open Beginner friendly
#1,912 7 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

in inference.py
1. convert `input_ids` to list, assign to `output_ids`
https://github.com/lm-sys/FastChat/blob/34c585ced4c0b30d2264c519f626b4c5cb924216/fastchat/serve/inference.py#L84
2. truncate `input_ids`, and get length assign to `input_echo_len`, but `output_ids` not truncate, `input_echo_len` length is not equal to `len(output_ids)`
https://github.com/lm-sys/FastChat/blob/34c585ced4c0b30d2264c519f626b4c5cb924216/fastchat/serve/inference.py#L91
3. use `input_echo_len` slice `output_ids` causes `output` contain part of the token in question, like`***** ASSISTANT: `。
https://github.com/lm-sys/FastChat/blob/34c585ced4c0b30d2264c519f626b4c5cb924216/fastchat/serve/inference.py#L178
**Example:**

> max_new_tokens = 2048

Q:请介绍清华大学
**truncate `input_ids`**:` an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: 请介绍清华大学 ASSISTANT:`
**`output` after slice**:` 华大学 ASSISTANT: 清华大学是中国著名的综合性研究型大学之一,位于北京市。该校成立于1911年,最初是清政府建立的留美预备学校,后来发展成为国立清华大学。清华大学是中国最早的高等学府之一,也是中国现代教育的重要奠基者之一。\n\n清华大学在多个学科领域都拥有很高的学术水平和知名度,其中工程、计算机、经济、管理等专业尤为著名。该校拥有一流的教学和研究设施,包括国家实验室、国家工程实验室、国家工程研究中心等。此外,清华大学还拥有多个国家级科研机构,如清华大学国家技术创新研究院、清华大学国家金融研究院等。\n\n清华大学的校园占地面积广阔,环境优美,是中国最美丽的大学校园之一。该校拥有多个校区,其中最著名的是清华大学本部,位于北京市海淀区清华路。清华大学的校园文化氛围浓厚,学生生活丰富多彩,学校也非常重视学生的全面发展和社会责任感的培养。\n\n清华大学是中国高等教育的重要标志之一,也是国际知名的高等学府之一。该校的毕业生在中国乃至世界各地都享有很高的声誉,许多毕业生成为了各个领域的领军人物。`

- Should consideration be given to moving `output_ids = list(input_ids)` after `input_ids = input_ids[-max_src_len:] `
- or drop ` - 8`, What does `-8` mean?
https://github.com/lm-sys/FastChat/blob/34c585ced4c0b30d2264c519f626b4c5cb924216/fastchat/serve/inference.py#L89

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

Read fastchat/serve/inference.py around lines 84, 89, 91, and 178, then trace how truncation changes input_echo_len relative to output_ids. Reproduce the provided max_new_tokens example and verify that the generated output no longer includes prompt fragments; also determine what the -8 adjustment represents.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.