Skip to content

[loss_scale] support last_round_with_ignore_empty_think for rag #4623

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

Merged
merged 2 commits into from
Jun 17, 2025
Merged
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
19 changes: 19 additions & 0 deletions swift/plugin/loss_scale/loss_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,31 @@ class IgnoreEmptyThink(REACTLossScale):
loss_scale_config = 'ignore_empty_think.json'


class LastRoundWithIgnoreEmptyThink(LossScale):
loss_scale_config = 'ignore_empty_think.json'

def get_loss_scale(self,
context: str,
context_type: ContextType,
is_last_round: bool,
*,
query: Optional[str] = None):
if context_type == ContextType.RESPONSE:
if not is_last_round:
return [context], [float(is_last_round)]
else:
return calculate_loss_scale(query, context, self.loss_scale_map)

return super().get_loss_scale(context, context_type, is_last_round)


# Add your loss scale here, use --loss_scale xxx to train
loss_scale_map = {
'last_round': LastRoundLossScale,
'default': LossScale,
'all': TrainAllLossScale,
'ignore_empty_think': IgnoreEmptyThink,
'last_round_with_ignore_empty_think': LastRoundWithIgnoreEmptyThink,
# agent
'react': REACTLossScale,
'hermes': HermesLossScale,
Expand Down