Skip to content
Closed
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: 2 additions & 0 deletions trinity/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class FormatConfig:
# for unpaired preference dataset
label_key: str = ""

use_base_format: bool = False
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using a new workflow type can do the same thing. Don't add a new field here.



@dataclass
class GenerationConfig:
Expand Down
19 changes: 17 additions & 2 deletions trinity/common/workflows/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,27 @@ def format_messages(self):
messages.append({"role": "assistant", "content": self.reply_prefix})
return messages

def format_prompt(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a new workflow named BaseModelWorkflow may be better.

prompt_text = ""
if self.system_prompt:
prompt_text += self.system_prompt
prompt_text += "\nTask:\n" + self.task_desc + "\nResponse:\n"
else:
prompt_text += "\nTask:\n" + self.task_desc + "\nResponse:\n"
return prompt_text

def run(self) -> List[Experience]:
# TODO: Optimize the generate function
messages = self.format_messages()
if self.format_args.use_base_format:
prompt_text = self.format_prompt()
else:
messages = self.format_messages()

logger.debug("start chat")
responses = self.model.chat(messages, **self.rollout_args)
if self.format_args.use_base_format:
responses = self.model.generate([prompt_text], **self.rollout_args)
else:
responses = self.model.chat(messages, **self.rollout_args)
for response in responses:
reward = self.reward_fn( # type: ignore [misc]
response=response.response_text, # type: ignore [arg-type]
Expand Down