You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
inference truncate causes “output_ids” to be incorrectly sliced #1912
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清华大学是中国高等教育的重要标志之一,也是国际知名的高等学府之一。该校的毕业生在中国乃至世界各地都享有很高的声誉,许多毕业生成为了各个领域的领军人物。</s>
Should consideration be given to moving output_ids = list(input_ids) after input_ids = input_ids[-max_src_len:]
when context_len=max_new_tokens,max_src_len = 0 not -1, so input_ids = input_ids[-max_src_len:] is input_ids[-0:] not input_ids[1:]
Consider max_new_tokens > context_len, is input_ids = input_ids[(max_new_token - context_len):] instead of input_ids = input_ids[(max_new_token - context_len + 1):], like 2K model max_new_tokens=2049, exceeds only 1 token, so truncated slice should be input_ids[-(-1):] instead of input_ids[-(-2):]
Please check if this understanding is correct, thank you
Activity
merrymercy commentedon Jul 13, 2023
Could you contribute a PR?
I think "-8" was a mistake.
merrymercy commentedon Jul 13, 2023
Please check whether #1935 works for you
lyy-zz commentedon Jul 25, 2023
Thank you for your reply,is works for me。
But when
context_len=max_new_tokens,-1still drop the first token, for example:<s>merrymercy commentedon Jul 25, 2023
@lyy-zz please send a pull request to help us fix it
lyy-zz commentedon Aug 28, 2023
just remove
-1, likewhen context_len=max_new_tokens,
max_src_len = 0not-1, soinput_ids = input_ids[-max_src_len:]isinput_ids[-0:]notinput_ids[1:]Consider max_new_tokens > context_len, is
input_ids = input_ids[(max_new_token - context_len):]instead ofinput_ids = input_ids[(max_new_token - context_len + 1):], like 2K model max_new_tokens=2049, exceeds only 1 token, so truncated slice should beinput_ids[-(-1):]instead ofinput_ids[-(-2):]Please check if this understanding is correct, thank you
surak commentedon Nov 3, 2023
Hey @lyy-zz is this still an issue?
chessing234 commentedon Jun 24, 2026
Opened a PR — dropped the stray
- 1inmax_src_lenso truncation no longer eats an extra prompt token when the context budget is tight.