CompletionCondition
dendron.conditions.completion_condition.CompletionConditionConfig
dataclass
Configuration for a CompletionConditionNode.
The options in this object control what Hugging Face model is used and how the node interacts with the blackboard.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name |
`str`
|
The name of the model to use. This should be a valid name corresponding to a Hugging Face model name (including the user name). |
required |
completions_key |
`Optional[str]`
|
The blackboard key to read and write the completions to evaluate
upon a |
'completions_in'
|
logprobs_out_key |
`Optional[str]`
|
The blackboard key to write a dictionary containing the output log probabilities. |
'probs_out'
|
success_fn_key |
`Optional[str]`
|
The blackboard key to read and write the success predicate that
determines the status that is ultimately returned upon a |
'success_fn'
|
auto_load |
`Optional[bool]`
|
An optional boolean indicating whether or not to automatically
load model either from disk or the Hugging Face hub. If |
True
|
input_key |
`Optional[str]`
|
The blackboard key to use for writing and reading the prefix that this node will consume. Defaults to "in". |
'in'
|
device |
`Optional[str]`
|
The device that should be used with the model. Examples include "cpu", "cuda", and "auto". Defaults to "auto". |
'auto'
|
load_in_8bit |
`Optional[bool]`
|
Optional boolean indicating whether or not to use eight-bit quantization
from bitsandbytes. When available, will typically decrease memory usage
and increase inference speed. Defaults to |
False
|
load_in_4bit |
`Optional[bool]`
|
Optional boolean indicating whether or not to use four-bit quantization
from bitsandbytes. When available, will typically decrease memory usage
and increase inference speed. If you observe degraded performance, try
eight-bit quanitization instead. Defaults to |
False
|
torch_dtype |
`torch.dtype`
|
The dtype to use for torch tensors. Defaults to |
float16
|
use_flash_attn_2 |
`Optional[bool]`
|
Optional bool controlling whether or not to use Flash Attention 2. Defaults
to |
False
|
Source code in src/dendron/conditions/completion_condition.py
dendron.conditions.completion_condition.CompletionCondition
Bases: ConditionNode
A completion condition node uses a causal language model to evaluate
the relative likelihood of several different completions of a prompt,
returning SUCCESS
or FAILURE
using a user-provided function that
selects a status based on the most likely completion.
This node tends to run quickly and gives useful answers, but if you use this node you should be aware of the perils of "surface form competition", documented in the paper by Holtzman et al. (see https://arxiv.org/abs/2104.08315).
This node is based on the Hugging Face transformers library, and will download the model that you specify by name. This can take a long time and/or use a lot of storage, depending on the model you name.
There are enough configuration options for this type of node that the options have all been placed in a dataclass config object. See the documentation for that object to learn about the many options available to you.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
`str`
|
The given name of this node. |
required |
cfg |
`CompletionConditionNodeConfig`
|
The configuration object for this model. |
required |
Source code in src/dendron/conditions/completion_condition.py
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
set_model(new_model)
Set a new model to use for generating text.
tick()
Execute a tick, consisting of the following steps:
- Retrieve the input prefix from the blackboard.
- Retrieve the list of completion options from the blackboard.
- Retrieve the success predicate from the blackboard.
- Tokenize all of the possible completions, padding as needed.
- Evaluate the model on the tokenized batch of completions.
- Compute the "log probabilities" of each completion.
- Apply the success predicate to the completion with the highest log probability.
- Return the status computed by the success predicate.
If any of the above fail, the exception text is printed and the node
returns a status of FAILURE
. Otherwise the node returns SUCCESS
.