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
Copy file name to clipboardExpand all lines: docs/source/garak.generators.base.rst
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,7 @@ Attributes:
16
16
* context_len - The number of tokens in the model context window, or None
17
17
* modality - A dictionary with two keys, "in" and "out", each holding a set of the modalities supported by the generator. "in" refers to prompt expectations, and "out" refers to output. For example, a text-to-text+image model would have modality: ``dict = {"in": {"text"}, "out": {"text", "image"}}``.
18
18
* supports_multiple_generations - Whether or not the generator can natively return multiple outputs from a prompt in a single function call. When set to False, the ``generate()`` method will make repeated calls, one output at a time, until the requested number of generations (in ``generations``) is reached.
19
+
* skip_seq_start, skip_start_end - If both asserted, content between these two will be pruned before being returned. Useful for removing chain-of-thought, for example
19
20
20
21
Functions:
21
22
@@ -32,12 +33,20 @@ The general flow in ``generate()`` is as follows:
32
33
#. Otherwise, we need to assemble the outputs over multiple calls. There are two options here.
33
34
#. Is garak running with ``parallel_attempts > 1`` configured? In that case, start a multiprocessing pool with as many workers as the value of ``parallel_attempts``, and have each one of these work on building the required number of generations, in any order.
34
35
#. Otherwise, call ``_call_model()`` repeatedly to collect the requested number of generations.
36
+
#. Call the ``_post_generate_hook()`` (a no-op by default)
37
+
#. If skip sequence start and end are both defined, call ``_prune_skip_sequences()``
35
38
#. Return the resulting list of prompt responses.
36
39
40
+
37
41
#. **_call_model()**: This method handles direct interaction with the model. It takes a prompt and an optional number of generations this call, and returns a list of prompt responses (e.g. strings) and ``None``s. Models may return ``None`` in the case the underlying system failed unrecoverably. This is the method to write model interaction code in. If the class' supports_multiple_generations is false, _call_model does not need to accept values of ``generations_this_call`` other than ``1``.
38
42
39
43
#. **_pre_generate_hook()**: An optional hook called before generation, useful if the class needs to do some setup or housekeeping before generation.
40
44
45
+
#. **_verify_model_result**: Validation of model output types, useful in debugging. If this fails, the generator doesn't match the expectations in the rest of garak.
46
+
47
+
#. **_post_generate_hook()**: An optional hook called after generation, useful if the class needs to do some modification of output.
48
+
49
+
#. **_prune_skip_sequences()**: Called if both ``skip_seq_start`` and ``skip_seq_end`` are defined. Strip out any response content between the start and end markers.
0 commit comments