xgrammar.CompiledGrammar

class xgrammar.CompiledGrammar[source]

Bases: XGRObject

This is the primary object to store compiled grammar.

A CompiledGrammar can be used to construct GrammarMatcher to generate token masks efficiently.

Note

Do not construct this class directly, instead use GrammarCompiler to construct the object.

__init__()

Methods

__init__()

Attributes

grammar

The original grammar.

memory_size_bytes

The approximate memory usage of the compiled grammar in bytes.

tokenizer_info

The tokenizer info associated with the compiled grammar.

property grammar: Grammar

The original grammar.

property memory_size_bytes: int

The approximate memory usage of the compiled grammar in bytes.

property tokenizer_info: TokenizerInfo

The tokenizer info associated with the compiled grammar.