-
Notifications
You must be signed in to change notification settings - Fork 844
[template] update glm4.5 agent template #5518
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import os | ||
|
||
os.environ['SWIFT_DEBUG'] = '1' | ||
os.environ['CUDA_VISIBLE_DEVICES'] = '0,1,2,3' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding |
||
|
||
system = 'You are a helpful assistant.' | ||
|
||
|
@@ -330,6 +331,28 @@ def test_hunyuan(): | |
assert encoded['input_ids'] == encoded2['input_ids'] | ||
|
||
|
||
def test_glm4_5(): | ||
engine = PtEngine('ZhipuAI/GLM-4.5-Air') | ||
template = engine.default_template | ||
template.template_backend = 'jinja' | ||
_infer(engine, num_tools=2) | ||
|
||
dataset = load_dataset('AI-ModelScope/function-calling-chatml')[0] | ||
data = dataset[6] | ||
data['messages'].insert(1, data['messages'][1]) | ||
data['messages'].insert(3, data['messages'][3]) | ||
template.template_backend = 'swift' | ||
template.set_mode('train') | ||
encoded = template.encode(data) | ||
print(f'input_ids: {template.safe_decode(encoded["input_ids"])}') | ||
print(f'labels: {template.safe_decode(encoded["labels"])}') | ||
template.template_backend = 'jinja' | ||
encoded2 = template.encode(data) | ||
print(f'input_ids: {template.safe_decode(encoded2["input_ids"])}') | ||
print(f'labels: {template.safe_decode(encoded2["labels"])}') | ||
assert encoded['input_ids'] == encoded2['input_ids'] | ||
|
||
|
||
if __name__ == '__main__': | ||
from swift.plugin import agent_templates | ||
from swift.llm import PtEngine, InferRequest, RequestConfig, load_dataset | ||
|
@@ -345,4 +368,5 @@ def test_hunyuan(): | |
# test_glm4_0414() | ||
# test_llama3() | ||
# test_llama4() | ||
test_hunyuan() | ||
# test_hunyuan() | ||
test_glm4_5() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an excellent and critical fix. The previous implementation using
rstrip('</answer>')
was incorrect becausestr.rstrip(chars)
treats its argument as a set of characters to remove from the end, not as a suffix string. For example,'great</answer>'.rstrip('</answer>')
would incorrectly result in'g'
. The new implementation usingendswith
and slicing is robust and correctly removes the suffix. Great catch!