Skip to content
Open
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 swift/trainers/rlhf_trainer/grpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2513,7 +2513,7 @@ def _process_image_data(image_data: Union[dict, str]) -> str:
return []

# Define core metadata fields required for all requests
REQUEST_METADATA_FIELDS = ['messages', 'images', 'audios', 'videos', 'objects', 'uuid']
REQUEST_METADATA_FIELDS = ['messages', 'images', 'audios', 'videos', 'tools', 'objects', 'uuid']
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While this change correctly adds the tools field, hardcoding the list of fields is brittle and likely led to this bug. To improve maintainability and prevent future omissions if RolloutInferRequest or InferRequest are modified, I suggest generating this list dynamically from the dataclass definitions.

This makes the code more robust against future changes to the dataclasses.

Suggested change
REQUEST_METADATA_FIELDS = ['messages', 'images', 'audios', 'videos', 'tools', 'objects', 'uuid']
request_fields = set(RolloutInferRequest.__annotations__.keys()) | set(InferRequest.__annotations__.keys())
REQUEST_METADATA_FIELDS = list(request_fields - {'data_dict'})

requests_dicts = []

for data in inputs:
Expand Down
Loading