-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-round conversation failure when enabled 'return_past_key_values' #8859
Comments
Verified in below environment. |
It only happens when |
Hi @fiorezhangintel , this issue should have been fixed by #8867 and should be available on tomorrow's bigdl-llm nightly version. Feel free to reopen if it does not work. |
Crash issue is fixed. But with past key values on, the output messages are weird. Please have a look at the messages. 请输入问题: 你好 |
CHATGLM2-6B fp16 (Original) 你好👋!我是人工智能助手 ChatGLM2-6B,很高兴见到你,欢迎问我任何问题。 你是谁? 我是一个人工智能助手 ChatGLM2-6B,是清华大学 KEG 实验室和智谱 AI 公司于 2023 年共同训练的语言模型。我的任务是针对用户的问题和要求提供适当的答复和支持。 世界第一高峰? 世界第一高峰是珠穆朗玛峰,位于喜马拉雅山脉,海拔高度 8,848.86 米。 第二呢? 第二高峰是乔戈里峰,位于喀喇昆仑山脉,海拔高度 8,813.下调。 第三呢? 第三高峰是干城章嘉峰,位于尼泊尔,海拔高度 8,586.04 米。 ChatGLM2-6B int4 (opt for Intel) 你好👋!我是人工智能助手 ChatGLM2-6B,很高兴见到你,欢迎问我谋取帮助。 你是谁? 你好,我是人工智能助手 ChatGLM2-6B。 世界第一高峰? 你好,我是人工智能助手 ChatGLM2-6B。很高兴见到你,欢迎问我谋取帮助。 第二呢? 你好,欢迎问我谋取帮助。 第三呢? 你好,欢迎问我谋取帮助。 |
CHATGLM2-6B fp16 (Original) 世界上人口最多的国家是中国,根据2021年联合国的估计,中国的人口为14.9亿人。 第二呢? 世界上人口第二多的国家是印度,根据2021年联合国的估计,印度的人口为13.3亿人。 第三呢? 世界上人口第三多的国家是巴西,根据2021年联合国的估计,巴西的人口为2.1亿人。 第四呢? 世界上人口第四多的国家是美国,根据2021年联合国的估计,美国的人口为3.3亿人。 ChatGLM2-6B int4 (opt for Intel) 世界上人口最多的国家是中国,根据2021年联合国的估计,中国的人口为14.96亿人。 第二呢? 抱歉,我无法回答有关人口的国家数量问题,因为我的知识截止于 2023年,而且我无法确定世界上目前的人口数量,因为我的数据源只包括训练时间前的信息。 第三呢? 目前世界上人口最多的国家是中国,根据2021年联合国的估计,中国的人口为14.96亿人。 第四呢? 目前世界上人口最多的国家是中国,根据2021年联合国的估计,中国的人口为14.96亿人。 |
Attached the same questions under original FP16 and quantized int4 (2.4.0b20230906 version). |
@yangw1234 It seems the output of bigdl-llm is still strange, please take a look |
@fiorezhangintel this should be fixed, could you try it again? |
I have tried it this weekend. I think it's improved a lot, but still a little bit strange. I'll post 4 serials logs below: FP16-PastKV-On, INT4-PastKV-On, FP16-PastKV-Off, INT4-PastKV-Off. Please subjectively compare the logs and feedback your thoughts. |
============================================================================================================================================================================================================== 世界第一高峰是珠穆朗玛峰(Mount Everest),位于喜马拉雅山脉,海拔高度8,848.86米(29,031.7英尺)。珠穆朗玛峰是世界上最著名和最具挑战性的登山目标之一,吸引了许多登山者前来挑战。 第二呢? 第二高峰是乔戈里峰(K2),也位于喜马拉雅山脉,位于珠穆朗玛峰的东北方向,海拔高度8,611米(28,251英尺)。乔戈里峰因其陡峭的山腰和严峻的登山路线而闻名,被登山家们誉为世界上最难攀登的山峰之一。 第三呢? 第三高峰是干城章嘉峰(Kangchengjunga),位于喜马拉雅山脉,是世界上最著名的登山目标之一。干城章嘉峰海拔高度8,586米(28,621英尺),由于其独特的三角形状而闻名于世。由于其陡峭的山腰和严酷的登山路线,它被登山家们誉为世界上最难攀登的山峰之一。 世界第一大河? 世界上第一大的河流是尼罗河(Nile River),全长约6,650千米(4,130英里),流经11个国家,包括坦桑尼亚、布隆迪、卢旺达、刚果民主共和国、肯尼亚、乌干达、埃塞俄比亚、南苏丹、苏丹、埃及和利比亚。尼罗河流域是非洲最重要的农业地区之一,也是世界上最著名的河流之一,为当地人民提供了重要的水资源和文化遗产。 第二呢? 世界上第二大的河流是亚马逊河(Amazon River),全长约6,437千米(4,069英里),流经巴西,是世界上最长的河流之一。亚马逊河以其独特的生态系统和丰富的生物多样性而闻名于世,是地球上最重要的生态系统之一。它也是世界上最重要的氧气供应者之一,被认为是地球的“肺”。 第三呢? 世界上第三大的河流是密西西比河(Mississippi River),全长约3,840千米(2,437英里),是美国最长的河流,也是北美洲最重要的河流之一。密西西比河流经美国中西部和南部,在路易斯安那州的新奥良注入墨西哥湾。它是美国政治、经济和文化中心的重要运输和贸易通道之一,也是世界上最重要的鱼类和鸟类栖息地之一。 ============================================================================================================================================================================================================== 世界第一高峰是珠穆朗玛峰(Mount Everest),位于尼泊尔和中国的边界上,海拔高度8,848.86米(29,029.69英尺)。珠穆朗玛峰是世界上最著名和最具挑战性的登山目标之一,吸引了许多登山者前来挑战。 第二呢? 錫羊卓雍措湖(Lake羊卓雍措)位于中国西藏自治区的南部,海拔高度7,848.8米(25,036.0英尺),是中国的第二大淡水湖。它是世界上最高和最美的湖泊之一,被誉为“天上湖泊”,也是许多登山者和游客的目标之一。 第三呢? 加查鲁塔峰(K2)也称为乔·乔·峰,位于巴基斯坦和中国边境之间的喜马拉雅山脉,海拔高度7,682米(25,186英尺),是第三高峰。由于其独特的形状和地理位置,加查鲁塔峰被誉为“山间宝石”,吸引了很多登山者前来挑战。 世界第一大河? 世界第一长河是尼罗河(Nile River),全长约6,650千米(4,130英里),流经11个国家,包括坦桑尼亚、布隆 enemy、肯尼亚、乌干达、埃塞俄比亚、南苏丹、乌干达、埃塞俄比亚、埃及和利比亚。它被认为是世界上最长的河流,也是非洲最重要的水源之一。 第二呢? 亚马逊河(Amazon River)是世界上最长的河流,全长约6,437千米(4,250英里),流经7个国家,包括巴西。它是世界上最大的河流之一,具有重要的生态和经济发展作用。 第三呢? 密西西比河(Mississippi River)是美国的第二长河流,全长约3,767千米(2,340英里),流经10个州,包括密苏里州、伊利诺伊州、肯塔基州、阿肯色州、密西西比州、路易斯安那州、威斯康星州、明尼苏达州和爱荷华州。它是一个重要的农业和工业中心,也是一个重要的旅游胜地电流。 ============================================================================================================================================================================================================== 世界第一高峰是珠穆朗玛峰,海拔高度8,848.86米(29,031.69英尺),位于喜马拉雅山脉的尼泊尔和中国边界。 第二呢? 第二高峰是乔戈里峰,海拔高度8,611米(28,251英尺),位于喀喇昆仑山脉的巴基斯坦和中国边界。 第三呢? 第三高峰是干城章嘉峰,Kangchengjunga,又叫“金城章嘉峰”、“康章忠格峰”,海拔高度8,586米(28,611英尺),位于喜玛拉雅山脉的印度和尼泊尔边界处。 世界第一大河? 世界上最长的河流是尼罗河,全长约6,650千米(4,130英里),流经11个国家,包括坦桑尼亚、布隆迪、卢旺达、刚果(金)、肯尼亚、乌干达、埃塞俄比亚、南苏丹、苏丹、埃及和利比亚。 第二呢? 世界上第二长河流是亚马逊河,全长约6,437千米(4,069英里),流经南美洲国家,包括巴西、秘鲁、哥伦比亚、委内瑞拉、厄瓜多尔、玻利维亚、圭亚那、苏里南和法属圭亚那。 第三呢? 世界第三长河流是长江,全长约6,300千米(4,040英里),流经中国,包括青海、西藏、四川、云南、贵州和重庆等省市。 ============================================================================================================================================================================================================== 世界第一高峰是珠穆朗玛峰,海拔高度8,848.86米(29,031.69英尺),位于喜马拉雅山脉的尼泊尔和中国边境。 第二呢? 第二高峰是乔戈里峰,也称为乔戈里峰,海拔高度8,188米(26,056.64英尺),位于喀喇崑崙山脉的巴基斯坦和中国边境。 第三呢? 第三高峰是干城章嘉峰,也称为金城章嘉峰,海拔高度8,091米(26,555.00英尺),位于印度洋中的马达加斯加岛。 世界第一大河? 世界上最长的河流是尼罗河,全长约6,650千米(4,130英里),流经11个国家,包括坦桑尼亚、布隆迪、卢旺达、刚果(金)、肯尼亚、乌干达、埃塞俄比亚、南苏丹、苏丹、埃及和利比亚。 第二呢? 世界上第二长河流是亚马逊河,全长约6,437千米(4,061英里),流经7个国家,包括巴西、哥伦比亚、秘鲁、委内瑞拉、厄瓜多尔、玻利维亚、圭亚那和苏里南。 第三呢? 世界上第三长河流是长江。 |
@fiorezhangintel Does the output looks fine if using @hkvision it seems |
It's a different API; need to document it in |
Looks normal when set optimze_model to False, regardless the perf.
Best Regards
Fiore
On Sep 11, 2023, at 16:15, Jason Dai ***@***.***> wrote:
@fiorezhangintel<https://github.com/fiorezhangintel> Does the output looks fine if using from_pretrained(..., optimize_model=False)?
@hkvision<https://github.com/hkvision> it seems optimize_model is not documented in API Doc<https://bigdl.readthedocs.io/en/latest/doc/PythonAPI/LLM/transformers.html#llm-transformers-model>
—
Reply to this email directly, view it on GitHub<#8859 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AZ446BMGVFNG6GCTK5Y3PWLXZ3CBTANCNFSM6AAAAAA4FNRPAA>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Oh, right. Since from_pretrained only has args and kwargs in the implementation, we will add it manually in the doc. |
Here is the experiments I did with bigdl-llm=2.4.0b20230911 All examples look normal to me. @fiorezhangintel would you mind sharing what specifics do you think is strange. bigdl int4
|
Difference between pask_kv on and pask_kvThe reason why pask_kv on is different than pask_kv off is that the model sometimes output a token that print as "", and this token will be omitted in the encoding of the next round when past_kv is off while preserved when past_kv is on. This also happens for fp32 version. There are often no difference for the first a few rounds and only diverge later in the conversation (both fp32 and int4). Difference between optimize_model on vs offThere some differences in the first output. I print the output probabilities of the first a few output tokens. The first 8 tokens are exactly the same and only when the 9th token the probability of "(" and "," flipped. I think this can be explained by the floating point error accumulated from all the layers for 8 passes of the model. @fiorezhangintel @jason-dai @hkvision what do you think? Any suggestions on how to objectively measure the correctness of the implementation? |
Load pre-trained model ChatGLM2-6B to support multi-round conversation. If the return_past_key_values is enabled in stream_chat() then it reports error like below. Attached code to reproduce.
Traceback (most recent call last):
File "C:\Users\szhan45\OneDrive - Intel Corporation\Documents!WorkFolder!AI-LLM\llm-demo\streamchat_loop_with_history.py", line 67, in
for response, history, past_key_values in model.stream_chat(tokenizer, args.question, history=history, past_key_values=past_key_values, return_past_key_values=True):
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\torch\utils_contextlib.py", line 35, in generator_context
response = gen.send(None)
File "C:\Users\szhan45/.cache\huggingface\modules\transformers_modules\chatglm2-6b\modeling_chatglm.py", line 976, in stream_chat
for outputs in self.stream_generate(**inputs, past_key_values=past_key_values,
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\torch\utils_contextlib.py", line 35, in generator_context
response = gen.send(None)
File "C:\Users\szhan45/.cache\huggingface\modules\transformers_modules\chatglm2-6b\modeling_chatglm.py", line 1061, in stream_generate
outputs = self(
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\szhan45/.cache\huggingface\modules\transformers_modules\chatglm2-6b\modeling_chatglm.py", line 848, in forward
transformer_outputs = self.transformer(
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\szhan45/.cache\huggingface\modules\transformers_modules\chatglm2-6b\modeling_chatglm.py", line 744, in forward
hidden_states, presents, all_hidden_states, all_self_attentions = self.encoder(
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\szhan45/.cache\huggingface\modules\transformers_modules\chatglm2-6b\modeling_chatglm.py", line 588, in forward
hidden_states, kv_cache = layer(
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\szhan45/.cache\huggingface\modules\transformers_modules\chatglm2-6b\modeling_chatglm.py", line 510, in forward
attention_output, kv_cache = self.self_attention(
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\bigdl\llm\transformers\models\chatglm2.py", line 186, in chatglm2_attention_forward_8eb45c
context_layer = self.core_attention(query_layer, key_layer, value_layer, attention_mask)
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "C:\Users\szhan45\Anaconda3\envs\bigdl\lib\site-packages\bigdl\llm\transformers\models\chatglm2.py", line 232, in core_attn_forward_8eb45c
context_layer = torch.nn.functional.scaled_dot_product_attention(query_layer,
RuntimeError: The size of tensor a (63) must match the size of tensor b (20) at non-singleton dimension 3
streamchat_loop_with_history.zip
The text was updated successfully, but these errors were encountered: