Skip to content

fix: merge ShareGPT tool observations#10578

Open
he-yufeng wants to merge 1 commit into
hiyouga:mainfrom
he-yufeng:fix/sharegpt-merge-observations
Open

fix: merge ShareGPT tool observations#10578
he-yufeng wants to merge 1 commit into
hiyouga:mainfrom
he-yufeng:fix/sharegpt-merge-observations

Conversation

@he-yufeng

Copy link
Copy Markdown

Summary

  • merge consecutive ShareGPT observation messages before role alignment
  • keep the existing alternating role validation after normalization
  • add a converter regression test for parallel tool responses

This addresses Issue B in #10530. The other template mismatches from that issue are intentionally left out of this PR.

To verify

  • PYTHONPATH=src python -m pytest tests/data/test_converter.py -q
  • python -m py_compile src/llamafactory/data/converter.py tests/data/test_converter.py
  • python -m ruff check src/llamafactory/data/converter.py tests/data/test_converter.py
  • git diff --check

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the dataset converter to merge consecutive tool observation messages into a single observation message separated by tool response tags, and adds a corresponding unit test. A review comment identifies a critical issue where pending tool responses are not flushed if the conversation history ends with an observation message, and provides a code suggestion to resolve this bug.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

"content": content,
}
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If the conversation history ends with an observation message (which is common in pairwise/ranking datasets where the final assistant response is stored in chosen/rejected instead of the conversations list), any pending tool_responses will not be flushed because the loop terminates before encountering a non-observation message. We should flush any remaining tool_responses after the loop finishes.

        if len(tool_responses) > 0:
            observation_content = "\n</tool_response>\n<tool_response>\n".join(tool_responses)
            aligned_messages.append(
                {
                    "role": Role.OBSERVATION.value,
                    "content": observation_content,
                }
            )

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