[deps] upgrade transformers (#8159)
This commit is contained in:
@@ -129,23 +129,24 @@ def test_encode_multiturn(use_fast: bool):
|
||||
@pytest.mark.parametrize("cot_messages", [True, False])
|
||||
@pytest.mark.parametrize("enable_thinking", [True, False, None])
|
||||
def test_reasoning_encode_oneturn(use_fast: bool, cot_messages: bool, enable_thinking: bool):
|
||||
input_messages = MESSAGES_WITH_THOUGHT if cot_messages else MESSAGES
|
||||
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B", use_fast=use_fast)
|
||||
data_args = DataArguments(template="qwen3", enable_thinking=enable_thinking)
|
||||
template = get_template_and_fix_tokenizer(tokenizer, data_args)
|
||||
prompt_ids, answer_ids = template.encode_oneturn(tokenizer, input_messages)
|
||||
output_messages = MESSAGES if enable_thinking is False else input_messages
|
||||
prompt_ids, answer_ids = template.encode_oneturn(tokenizer, MESSAGES_WITH_THOUGHT if cot_messages else MESSAGES)
|
||||
|
||||
prompt_str = (
|
||||
f"<|im_start|>user\n{output_messages[0]['content']}<|im_end|>\n<|im_start|>assistant\n"
|
||||
f"<|im_start|>user\n{MESSAGES[0]['content']}<|im_end|>\n<|im_start|>assistant\n"
|
||||
f"{MESSAGES[1]['content']}<|im_end|>\n"
|
||||
f"<|im_start|>user\n{output_messages[2]['content']}<|im_end|>\n<|im_start|>assistant\n"
|
||||
f"<|im_start|>user\n{MESSAGES[2]['content']}<|im_end|>\n<|im_start|>assistant\n"
|
||||
)
|
||||
answer_str = f"{output_messages[3]['content']}<|im_end|>\n"
|
||||
if not cot_messages or enable_thinking is False:
|
||||
answer_str = f"{MESSAGES[3]['content']}<|im_end|>\n"
|
||||
if enable_thinking:
|
||||
answer_str = "<think>\n\n</think>\n\n" + answer_str
|
||||
else:
|
||||
prompt_str = prompt_str + "<think>\n\n</think>\n\n"
|
||||
else:
|
||||
answer_str = f"{MESSAGES_WITH_THOUGHT[3]['content']}<|im_end|>\n"
|
||||
|
||||
_check_tokenization(tokenizer, (prompt_ids, answer_ids), (prompt_str, answer_str))
|
||||
|
||||
@@ -154,16 +155,16 @@ def test_reasoning_encode_oneturn(use_fast: bool, cot_messages: bool, enable_thi
|
||||
@pytest.mark.parametrize("cot_messages", [True, False])
|
||||
@pytest.mark.parametrize("enable_thinking", [True, False, None])
|
||||
def test_reasoning_encode_multiturn(use_fast: bool, cot_messages: bool, enable_thinking: bool):
|
||||
input_messages = MESSAGES_WITH_THOUGHT if cot_messages else MESSAGES
|
||||
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B", use_fast=use_fast)
|
||||
data_args = DataArguments(template="qwen3", enable_thinking=enable_thinking)
|
||||
template = get_template_and_fix_tokenizer(tokenizer, data_args)
|
||||
encoded_pairs = template.encode_multiturn(tokenizer, input_messages)
|
||||
output_messages = MESSAGES if enable_thinking is False else input_messages
|
||||
prompt_str_1 = f"<|im_start|>user\n{output_messages[0]['content']}<|im_end|>\n<|im_start|>assistant\n"
|
||||
answer_str_1 = f"{output_messages[1]['content']}<|im_end|>\n"
|
||||
prompt_str_2 = f"<|im_start|>user\n{output_messages[2]['content']}<|im_end|>\n<|im_start|>assistant\n"
|
||||
answer_str_2 = f"{output_messages[3]['content']}<|im_end|>\n"
|
||||
encoded_pairs = template.encode_multiturn(tokenizer, MESSAGES_WITH_THOUGHT if cot_messages else MESSAGES)
|
||||
|
||||
messages = MESSAGES if not cot_messages or enable_thinking is False else MESSAGES_WITH_THOUGHT
|
||||
prompt_str_1 = f"<|im_start|>user\n{MESSAGES[0]['content']}<|im_end|>\n<|im_start|>assistant\n"
|
||||
answer_str_1 = f"{messages[1]['content']}<|im_end|>\n"
|
||||
prompt_str_2 = f"<|im_start|>user\n{MESSAGES[2]['content']}<|im_end|>\n<|im_start|>assistant\n"
|
||||
answer_str_2 = f"{messages[3]['content']}<|im_end|>\n"
|
||||
if not cot_messages or enable_thinking is False:
|
||||
if enable_thinking:
|
||||
answer_str_1 = "<think>\n\n</think>\n\n" + answer_str_1
|
||||
@@ -253,7 +254,11 @@ def test_llama4_template(use_fast: bool):
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"use_fast", [True, pytest.param(False, marks=pytest.mark.xfail(reason="Phi-4 slow tokenizer is broken."))]
|
||||
"use_fast",
|
||||
[
|
||||
pytest.param(True, marks=pytest.mark.xfail(not HF_TOKEN, reason="Authorization.")),
|
||||
pytest.param(False, marks=pytest.mark.xfail(reason="Phi-4 slow tokenizer is broken.")),
|
||||
],
|
||||
)
|
||||
def test_phi4_template(use_fast: bool):
|
||||
prompt_str = (
|
||||
@@ -266,6 +271,7 @@ def test_phi4_template(use_fast: bool):
|
||||
_check_template("microsoft/phi-4", "phi4", prompt_str, answer_str, use_fast)
|
||||
|
||||
|
||||
@pytest.mark.xfail(not HF_TOKEN, reason="Authorization.")
|
||||
@pytest.mark.parametrize("use_fast", [True, False])
|
||||
def test_qwen2_5_template(use_fast: bool):
|
||||
prompt_str = (
|
||||
@@ -282,16 +288,18 @@ def test_qwen2_5_template(use_fast: bool):
|
||||
@pytest.mark.parametrize("use_fast", [True, False])
|
||||
@pytest.mark.parametrize("cot_messages", [True, False])
|
||||
def test_qwen3_template(use_fast: bool, cot_messages: bool):
|
||||
messages = MESSAGES_WITH_THOUGHT if cot_messages else MESSAGES
|
||||
prompt_str = (
|
||||
f"<|im_start|>user\n{messages[0]['content']}<|im_end|>\n"
|
||||
f"<|im_start|>user\n{MESSAGES[0]['content']}<|im_end|>\n"
|
||||
f"<|im_start|>assistant\n{MESSAGES[1]['content']}<|im_end|>\n"
|
||||
f"<|im_start|>user\n{messages[2]['content']}<|im_end|>\n"
|
||||
f"<|im_start|>user\n{MESSAGES[2]['content']}<|im_end|>\n"
|
||||
"<|im_start|>assistant\n"
|
||||
)
|
||||
answer_str = f"{messages[3]['content']}<|im_end|>\n"
|
||||
if not cot_messages:
|
||||
answer_str = "<think>\n\n</think>\n\n" + answer_str
|
||||
answer_str = f"<think>\n\n</think>\n\n{MESSAGES[3]['content']}<|im_end|>\n"
|
||||
messages = MESSAGES
|
||||
else:
|
||||
answer_str = f"{MESSAGES_WITH_THOUGHT[3]['content']}<|im_end|>\n"
|
||||
messages = MESSAGES_WITH_THOUGHT
|
||||
|
||||
_check_template("Qwen/Qwen3-8B", "qwen3", prompt_str, answer_str, use_fast, messages=messages)
|
||||
|
||||
@@ -309,6 +317,7 @@ def test_parse_llama3_template():
|
||||
assert template.default_system == ""
|
||||
|
||||
|
||||
@pytest.mark.xfail(not HF_TOKEN, reason="Authorization.")
|
||||
def test_parse_qwen_template():
|
||||
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct", token=HF_TOKEN)
|
||||
template = parse_template(tokenizer)
|
||||
@@ -320,6 +329,7 @@ def test_parse_qwen_template():
|
||||
assert template.default_system == "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."
|
||||
|
||||
|
||||
@pytest.mark.xfail(not HF_TOKEN, reason="Authorization.")
|
||||
def test_parse_qwen3_template():
|
||||
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B", token=HF_TOKEN)
|
||||
template = parse_template(tokenizer)
|
||||
|
||||
Reference in New Issue
Block a user