You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
xgrammar == 0.1.6
CUDA == 12.4
torch == 2.4.0
transformers==4.46.1
Issue
Hitting a infinite loop using the specific grammar provided in the code. (WIP: Trying to debug and understand the error)
Context
We (@antferdom) are researching different gramar-based decoding techniques for code generation. In this specific setting we're trying to generate a DSL called UVL. A reiterative problem is that is indent-sensitive so context-dependent, if It can be fixed I believe it could unlock Python codegen as well.
Errors
When leaving generation, no error is triggered rather than an infinite execution. When the processs is stopped with SIGINT (CTRL + C) the error output is:
File "/root/ebnf_xgrammar.py", line 110, in<module>
generated_ids = model.generate(
File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/dist-packages/transformers/generation/utils.py", line 2215, in generate
result = self._sample(
File "/usr/local/lib/python3.10/dist-packages/transformers/generation/utils.py", line 3223, in _sample
next_token_scores = logits_processor(input_ids, next_token_logits)
File "/usr/local/lib/python3.10/dist-packages/transformers/generation/logits_process.py", line 104, in __call__
scores = processor(input_ids, scores)
File "/usr/local/lib/python3.10/dist-packages/xgrammar/contrib/hf.py", line 90, in __call__
self.matchers[i].fill_next_token_bitmask(self.token_bitmask, i)
File "/usr/local/lib/python3.10/dist-packages/xgrammar/matcher.py", line 211, in fill_next_token_bitmask
self._handle.fill_next_token_bitmask(bitmask.data_ptr(), list(bitmask.shape), index)
Hi @roG0d, thanks for the bug report. Sorry for the late response as I just finished my travel.
After digging into your script I think that is mainly because there is too much non-determinism in the grammar (that means, for the same input string, there can be multiple interpretations according to the grammar). To much nondeterminism means multiple (maybe exponential) parsing stacks, which increases overhead at runtime. (Check out the "Why is it hard to accelerate general CFGs?" section in our blog.
Env
Issue
Hitting a infinite loop using the specific grammar provided in the code. (WIP: Trying to debug and understand the error)
Context
We (@antferdom) are researching different gramar-based decoding techniques for code generation. In this specific setting we're trying to generate a DSL called UVL. A reiterative problem is that is indent-sensitive so context-dependent, if It can be fixed I believe it could unlock Python codegen as well.
Errors
When leaving generation, no error is triggered rather than an infinite execution. When the processs is stopped with SIGINT (CTRL + C) the error output is:
Code snippet for reproducibility
The text was updated successfully, but these errors were encountered: