-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[Bugfix] fix the default reasoning mode in Reasoner Grammar. #10831
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
Open
jeremyzhang866
wants to merge
22
commits into
sgl-project:main
Choose a base branch
from
jeremyzhang866:jeremy_reasoner_grammer_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d3aac35
[Bugfix] fix the issue with the default reasoning mode in reasoner_gr…
jeremyzhang866 4145c9d
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 216fca6
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 ae78dff
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 c12d7c0
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 62dd271
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 0d9277a
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 943fffc
Merge branch 'main' into jeremy_reasoner_grammer_fix
JustinTong0323 1dae6b5
[Bugfix] fix the issue with the default reasoning mode in reasoner_gr…
jeremyzhang866 599bc21
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 c8ccadd
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 244ec0c
Merge branch 'main' into jeremy_reasoner_grammer_fix
JustinTong0323 286f35d
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 50d4d22
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 1694aee
Merge branch 'main' into jeremy_reasoner_grammer_fix
JustinTong0323 3e70338
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 93daf97
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 fbab761
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 cdb8c6c
Merge branch 'main' into jeremy_reasoner_grammer_fix
JustinTong0323 e5b89ff
Merge branch 'main' into jeremy_reasoner_grammer_fix
JustinTong0323 aead1b5
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 881f12d
Merge branch 'main' into jeremy_reasoner_grammer_fix
jeremyzhang866 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,11 +25,11 @@ | |
|
|
||
|
|
||
| class ReasonerGrammarObject(BaseGrammarObject): | ||
| def __init__(self, grammar: BaseGrammarObject, think_end_id): | ||
| def __init__(self, grammar: BaseGrammarObject, think_end_id, may_can_reasoning): | ||
| super().__init__() | ||
| self.grammar = grammar | ||
| self.think_end_id = think_end_id | ||
| self.is_in_reasoning = True | ||
|
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. Why don't we simpily set this field to |
||
| self.is_in_reasoning = may_can_reasoning | ||
|
|
||
| def accept_token(self, token: int): | ||
| if token == self.think_end_id: | ||
|
|
@@ -38,11 +38,17 @@ def accept_token(self, token: int): | |
| if not self.is_in_reasoning and token != self.think_end_id: | ||
| self.grammar.accept_token(token) | ||
|
|
||
| def rollback(self, k: int): | ||
| self.grammar.rollback(k) | ||
|
|
||
| def allocate_vocab_mask( | ||
| self, vocab_size: int, batch_size: int, device | ||
| ) -> torch.Tensor: | ||
| return self.grammar.allocate_vocab_mask(vocab_size, batch_size, device) | ||
|
|
||
| def is_terminated(self): | ||
| return self.grammar.is_terminated() | ||
|
|
||
| def fill_vocab_mask(self, vocab_mask: torch.Tensor, idx: int) -> None: | ||
| if not self.is_in_reasoning: | ||
| self.grammar.fill_vocab_mask(vocab_mask, idx) | ||
|
|
@@ -55,7 +61,9 @@ def apply_vocab_mask(self): | |
| return self.grammar.apply_vocab_mask | ||
|
|
||
| def copy(self) -> BaseGrammarObject: | ||
| return ReasonerGrammarObject(self.grammar.copy(), self.think_end_id) | ||
| return ReasonerGrammarObject( | ||
| self.grammar.copy(), self.think_end_id, self.is_in_reasoning | ||
| ) | ||
|
|
||
| @property | ||
| def finished(self): | ||
|
|
@@ -90,4 +98,5 @@ def _init_value_dispatch(self, key: Tuple[str, str]) -> Optional[BaseGrammarObje | |
| # avoid wrapping invalid grammar, so that the scheduler can detect it | ||
| if ret is None or ret is INVALID_GRAMMAR_OBJ: | ||
| return ret | ||
| return ReasonerGrammarObject(ret, self.think_end_id) | ||
| may_can_reasoning = key[2] | ||
| return ReasonerGrammarObject(ret, self.think_end_id, may_can_reasoning) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.