Skip to content

Commit

Permalink
update probe base docs for _execute_all()
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Martin <[email protected]>
  • Loading branch information
jmartin-tech committed May 1, 2024
1 parent 0f291d1 commit c5eaf39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions docs/source/garak.probes.base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The general flow in ``probe()`` is:
* Create a list of ``attempt`` objects corresponding to the prompts in the probe, using ``_mint_attempt()``. Prompts are iterated through and passed to ``_mint_attempt()``. The ``_mint_attempt()`` function works by converting a prompt to a full ``attempt`` object, and then passing that ``attempt`` object through ``_attempt_prestore_hook()``. The result is added to a list in ``probe()`` called ``attempts_todo``.
* If any buffs are loaded, the list of attempts is passed to ``_buff_hook()`` for transformation. ``_buff_hook()`` checks the config and then creates a new attempt list, ``buffed_attempts``, which contains the results of passing each original attempt through each instantiated buff in turn. Instantiated buffs are tracked in ``_config.buffmanager.buffs``. Once ``buffed_attempts`` is populated, it's returned, and overwrites ``probe()``'s ``attempts_todo``.
* At this point, ``probe()`` is ready to start interacting with the generator. An empty list ``attempts_completed`` is set up to hold completed results.
* If configured, parallelisation of attempt processing is set up using ``multiprocessing``. The relevant config variable is ``_config.system.parallel_attempts`` and the value should be greater than 1 (1 in parallel is just serial).
* The set of attempts is then passed to ``_execute_all``.
* Attempts are iterated through (ether in parallel or serial) and individually posed to the generator using ``_execute_attempt()``.
* The process of putting one ``attempt`` through the generator is orchestrated by ``_execute_attempt()``, and runs as follows:

Expand All @@ -33,15 +33,20 @@ The general flow in ``probe()`` is:

4. **_buff_hook()**. Called from ``probe()`` to buff attempts after the list in ``attempts_todo`` is populated.

5. **_execute_attempt()**. Called from ``probe()`` to orchestrate processing of one attempt by the generator.
5. **_execute_attempt()**. Called from ``_execute_all()`` to orchestrate processing of one attempt by the generator.

6. **_execute_all()**. Called from ``probe()`` to orchestrate processing of the set of attempts by the generator.

* If configured, parallelisation of attempt processing is set up using ``multiprocessing``. The relevant config variable is ``_config.system.parallel_attempts`` and the value should be greater than 1 (1 in parallel is just serial).
* Attempts are iterated through (ether in parallel or serial) and individually posed to the generator using ``_execute_attempt()``.

6. **_generator_precall_hook()**. Called at the start of ``_execute_attempt()`` with attempt and generator. Can be used to e.g. adjust generator parameters.
7. **_generator_precall_hook()**. Called at the start of ``_execute_attempt()`` with attempt and generator. Can be used to e.g. adjust generator parameters.

7. **_mint_attempt()**. Converts a prompt to a new attempt object, managing metadata like attempt status and probe classname.
8. **_mint_attempt()**. Converts a prompt to a new attempt object, managing metadata like attempt status and probe classname.

8. **_postprocess_buff()**. Called in ``_execute_attempt()`` after results come back from the generator, if a buff specifies it. Used to e.g. translate results back if already translated to another language.
9. **_postprocess_buff()**. Called in ``_execute_attempt()`` after results come back from the generator, if a buff specifies it. Used to e.g. translate results back if already translated to another language.

9. **_postprocess_hook()**. Called near the end of ``_execute_attempt()`` to apply final postprocessing to attempts after generation. Can be used to restore state, e.g. if generator parameters were adjusted, or to clean up generator output.
10. **_postprocess_hook()**. Called near the end of ``_execute_attempt()`` to apply final postprocessing to attempts after generation. Can be used to restore state, e.g. if generator parameters were adjusted, or to clean up generator output.


.. automodule:: garak.probes.base
Expand Down
2 changes: 1 addition & 1 deletion garak/generators/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(self, name, generations=10):
if self.api_key is None:
raise ValueError(
f'Put the {self.generator_family_name} API key in the {self.ENV_VAR} environment variable (this was empty)\n \
e.g.: export {self.ENV_VAR}="sk-123Xgenerators/openai.pyXXXXXXXXXXX"'
e.g.: export {self.ENV_VAR}="sk-123XXXXXXXXXXXX"'
)

self._load_client()
Expand Down

0 comments on commit c5eaf39

Please sign in to comment.