Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion litgpt/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def apply(self, prompt: str, *, sys_prompt: str | None = None, **kwargs: str) ->
sys_prompt
or "You are Phi, a language model trained by Microsoft to help users. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:"
)
return f"<|im_start>system<|im_sep|>{sys_prompt}<|im_end|><|im_start|>user<|im_sep|>{prompt}<|im_end|><|im_start|>assistant<|im_sep|>"
return f"<|im_start|>system<|im_sep|>{sys_prompt}<|im_end|><|im_start|>user<|im_sep|>{prompt}<|im_end|><|im_start|>assistant<|im_sep|>"


class Phi4Mini(PromptStyle):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Default,
Llama3,
Phi3,
Phi4Reasoning,
PromptStyle,
has_prompt_style,
load_prompt_style,
Expand Down Expand Up @@ -202,3 +203,12 @@ def test_multiturn_prompt():
output = style.apply(msgs)
simple_output = style.apply(content)
assert output == simple_output


def test_phi4_reasoning_uses_well_formed_im_start_token():
# Regression test: the first turn previously emitted a malformed "<|im_start>"
# token (missing the closing pipe), unlike every other ChatML/Phi-4 template.
output = Phi4Reasoning().apply("What is 2 + 2?")
assert "<|im_start>" not in output
assert output.startswith("<|im_start|>system<|im_sep|>")
assert output.count("<|im_start|>") == 3