xgrammar
Backend class for XGrammar.
XGrammarBackend
Bases: BaseBackend
Backend for XGRammar.
Source code in outlines/backends/xgrammar.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
__init__(model)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
SteerableModel
|
The Outlines model of the user. |
required |
Source code in outlines/backends/xgrammar.py
get_cfg_logits_processor(grammar)
Create a logits processor from a context-free grammar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grammar
|
str
|
The context-free grammar to create a logits processor from. |
required |
Returns:
Type | Description |
---|---|
LogitsProcessor
|
The logits processor to use to constrain the generation. |
Source code in outlines/backends/xgrammar.py
get_json_schema_logits_processor(json_schema)
Create a logits processor from a JSON schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_schema
|
str
|
The JSON schema to create a logits processor from. |
required |
Returns:
Type | Description |
---|---|
LogitsProcessor
|
The logits processor to use to constrain the generation. |
Source code in outlines/backends/xgrammar.py
get_regex_logits_processor(regex)
Create a logits processor from a regex.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
regex
|
str
|
The regex to create a logits processor from. |
required |
Returns:
Type | Description |
---|---|
LogitsProcessor
|
The logits processor to use to constrain the generation. |
Source code in outlines/backends/xgrammar.py
XGrammarLogitsProcessor
Bases: OutlinesLogitsProcessor
Logits processor for XGrammar.
This class wraps the xgr.contrib.hf.LogitsProcessor
class and adds
a reset
method to reset the logits processor for a new generation.
Source code in outlines/backends/xgrammar.py
__init__(compiled_grammar)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compiled_grammar
|
str
|
The compiled grammar to use to create the logits processor. |
required |
Source code in outlines/backends/xgrammar.py
process_logits(input_ids, logits)
Bias the logits.