Skip to content

fix: handle tool messages in last round loss scaling - #9923

Merged
tastelikefeet merged 3 commits into
modelscope:mainfrom
Bakuma-sea:fix/loss-scale-last-round-tool
Aug 16, 2026
Merged

fix: handle tool messages in last round loss scaling#9923
tastelikefeet merged 3 commits into
modelscope:mainfrom
Bakuma-sea:fix/loss-scale-last-round-tool

Conversation

@Bakuma-sea

Copy link
Copy Markdown
Contributor

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Fix incorrect last_round loss scaling for agent conversations containing tool responses.

Previously, get_last_user_round only recognized messages with the user role. In tool-call conversations, a tool message starts the final query-response round, so the last round could be identified incorrectly and loss scaling could be applied to earlier assistant responses.

This change treats both user and tool messages as valid round-start messages. It also adds a regression test for a conversation ending with a tool response followed by the final assistant response.

Experiment results

  • Added regression test: tests/loss_scale/test_last_user_round.py
  • git diff --check passed.

@tastelikefeet

Copy link
Copy Markdown
Collaborator

Hi, can you lint the code via 'pre-commit run --all-files' please?

@Bakuma-sea

Copy link
Copy Markdown
Contributor Author

Hi, can you lint the code via 'pre-commit run --all-files' please?

Thanks for the reminder. I ran pre-commit run --all-files, applied the yapf formatting changes, and all hooks pass now.

@tastelikefeet
tastelikefeet merged commit cf6316c into modelscope:main Aug 16, 2026
2 of 3 checks passed
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.

2 participants