This repository contains implementations for constrained-aligned decoding.
This repository also contains the implementation of GreatGramma, a tool implementing algorithm of the paper 'Flexible and Efficient Grammar-Constrained Decoding' GreatGramma can be installed by running pip install -e ..
GreatGramma requires specific version of the transformers package. Run pip install -r requirements.txt for setup.
The CFG monitor is implemented in alignment/monitor/grammar.
cfg_monitor.pyis frontend of the monitorpartial_lexer.pyxis lexer preprocessing modulepartial_parser.pyxhandles parser preprocessing and runtime parser check
partial_lexer.pyx and partial_parser.pyx need to compiled by running cythonize -i alignment/monitor/grammar/partial_lexer.pyx and cythonize -i alignment/monitor/grammar/partial_parser.pyx
This implementation of GreatGramma is prototype and has memory leak issue. It is recommended to disable GC when grammar is huge.