Skip to content

Update bos_token bug #1

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

Merged
merged 1 commit into from
Jul 3, 2025
Merged

Update bos_token bug #1

merged 1 commit into from
Jul 3, 2025

Conversation

aacedar
Copy link
Owner

@aacedar aacedar commented Jul 2, 2025

PR type

PR information

使用deepseek-ai/deepseek-coder-6.7b-base模型做grpo
问题表现同https://github.com/modelscope/ms-swift/issues/4785,但错误不一样
当前错误代码错误在swift/llm/template/base.py的_swift_encode函数,涉及的代码行如下:
`

if self.template_meta.is_post_system or not system:

    prefix = template_meta.prefix

else:
    prefix = template_meta.system_prefix
self._concat_context_list(prefix, res_context_list, res_context_types, system=system)

`
debug发现prefix是 [[32013]], 对应的token是‘<|begin▁of▁sentence|>’,导致这个问题的原因在swift/llm/template/template_meta.py的init()函数的执行,将prefix这类值转成tokenid后替换该属性的值。
为了适配完整而正确的prompt,需要将token_id=32013,decode回‘<|begin▁of▁sentence|>’,这样行程的prompt为:‘<|begin▁of▁sentence|>User:xx\nAssitant:xx’

代码是最新的main分支的代码:swift.version: 3.6.0.dev0

解决方法:
将prefix=[[32013]],返回成token拼接到prompt中,注意这是一个简单的方法。
要彻底采用通用方案解决的话应该在swift/llm/template/template_meta.py文件中保存prefix的token值,如有必要也保存prefix的token_id值,其他如suffix类似,为了防止直接修改带来不可预知的问题,这里采用最小修改的办法先解决该问题。

@aacedar aacedar merged commit d7e81cf into main Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant