-
-
Notifications
You must be signed in to change notification settings - Fork 19.8k
[Bugfix][Frontend] Normalize constrained Harmony recipients #45657
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,7 @@ def _poll_completed_message(self) -> Message | None: | |
| if len(messages) <= self._num_processed_messages: | ||
| return None | ||
| msg = messages[self._num_processed_messages] | ||
| msg.recipient = self._normalize_recipient(msg.recipient) | ||
| self._num_processed_messages += 1 | ||
| return msg | ||
|
|
||
|
|
@@ -192,7 +193,9 @@ def parse_delta( | |
| *, | ||
| finished: bool, | ||
| ) -> DeltaMessage | None: | ||
| prev_recipient = self._harmony_parser.current_recipient | ||
| prev_recipient = self._normalize_recipient( | ||
| self._harmony_parser.current_recipient | ||
| ) | ||
| result = self.process_chunk(delta_token_ids) | ||
| if finished: | ||
| flushed_segment = self.flush() | ||
|
|
@@ -274,7 +277,9 @@ def process_chunk(self, token_ids: Sequence[int]) -> ChunkResult: | |
| for token_id in token_ids: | ||
| self._harmony_parser.process(token_id) | ||
| channel = self._harmony_parser.current_channel | ||
| recipient = self._harmony_parser.current_recipient | ||
| recipient = self._normalize_recipient( | ||
| self._harmony_parser.current_recipient | ||
| ) | ||
| delta = self._harmony_parser.last_content_delta or "" | ||
| completed_message = self._poll_completed_message() | ||
|
|
||
|
|
@@ -298,3 +303,14 @@ def process_chunk(self, token_ids: Sequence[int]) -> ChunkResult: | |
| segments=segments, | ||
| reasoning_token_count=reasoning_token_count, | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def _normalize_recipient(recipient: str | None) -> str | None: | ||
| """Remove constrained formats misparsed into recipients by older Harmony.""" | ||
| if recipient is None: | ||
| return None | ||
|
|
||
| constrain_index = recipient.find("<|constrain|>") | ||
| if constrain_index == -1: | ||
| return recipient | ||
| return recipient[:constrain_index].rstrip() or None | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work in the real world? Here's a prior example I happened to have written down of how the constrain often leaks into the wrong place:
I'm worried about the find and rstrip here in cases like this. It would potentially catch some cases, but I'm unsure how much it will hold up in the typical long context real-world failure scenarios we frequently see with these models. Do we have evidence this helps those broadly?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hi @bbrowning , Thanks for confirming, this works for the specific case addressed here. This PR is only a narrow fix for #45570. I’ll continue looking into the broader |
||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.