Skip to content
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

模型的编程基础知识有错误 #746

Open
YAETHeryk opened this issue Jul 4, 2024 · 1 comment
Open

模型的编程基础知识有错误 #746

YAETHeryk opened this issue Jul 4, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@YAETHeryk
Copy link

编程时偶然发现的,就多测试了几次,似乎即便模型能正确列出优先级顺序表,它依然会固执地认为^运算符应该先于+运算。

捕获
捕获1
捕获2

捕获3
捕获4
1720058436820
1720058468275

Qwen2-7B-Instruct-GPTQ-Int4在这个问题也出现类似错误。

client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)

chat_response = client.chat.completions.create(
    model="Qwen2-7B-Instruct-GPTQ-Int4",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "python中,^运算符和+运算符优先级是什么样的,5^3+2在python中如何计算,这里^是位运算不是幂?"},
    ]
)
print("Chat response:", chat_response.choices[0].message.content)

输出:

Chat response: 在 Python 中,运算符的优先级是固定的。对比 ^+ 运算符的优先级:

  • + 运算符属于算术运算符。在 Python 中,它的优先级高于位运算符,因此 a + b 表示加法。
  • ^ 运算符是位运算符,表示按位异或操作。在算术运算符的优先级中,它位于乘法和除法之后,但优先级高于赋值运算符(如 =)。

因此,表达式 5^3+2 应该首先执行位运算 5^3,然后执行加法运算。具体计算步骤如下:

  1. 首先计算 5^3

    • 二进制表示:5010130011
    • 按位异或:0101 ^ 0011 = 0110
    • 结果是 6
  2. 接着执行加法运算 6+2

    • 结果是 8

因此,5^3+2 的计算结果是 8

实际结果应该是先计算+,最终得到0。

@jklj077 jklj077 added the enhancement New feature or request label Jul 4, 2024
@jklj077
Copy link
Collaborator

jklj077 commented Dec 4, 2024

can reproduce with Qwen2.5-7B-Instruct and Qwen2.5-Coder-7B-Instruct, partially with Qwen2.5-Coder-32B-Instruct.

image

image

image

cc: @huybery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants