Generation
Generation
LLM Inference Engine Service
engine
Functions:
-
generate_continual_dataset–Generate a ContinualAlignmentDataset dataset given the AlignmentTask, and model.
generate_continual_dataset
async
generate_continual_dataset(
data_config: Dict[str, Any],
model_name: str,
client: AsyncOpenAI,
async_semaphore: Semaphore,
max_tokens_prompt_response: int = 1024,
max_tokens_chosen_rejected_response: int = 2048,
dry_run: bool = False,
include_preference_axes: bool = False,
temperature: float = 1.0,
) -> Optional[ContinualAlignmentDataset]
Generate a ContinualAlignmentDataset dataset given the AlignmentTask, and model.
Parameters:
-
data_config(Dict[str, Any]) –Configuration file storing tasks specifications and model info.
-
model_name(str) –The vLLM-compatible model alias to use for generation synthetic samples.
-
client(AsyncOpenAI) –Handle to openAI client.
-
async_semaphore(Semaphore) –Semaphore that manages number of concurrent API requests.
-
max_tokens_prompt_response(int, default:1024) –Configurable limit on the max_tokens for the generated prompt response.
-
max_tokens_chosen_rejected_response(int, default:2048) –Configurable limit on the max_tokens for the generated chosen and rejected response.
-
dry_run(bool, default:False) –If True, ignore the config and generate a dummy sample to ensure the model is setup correctly.
-
include_preference_axes(bool, default:False) –If True, include the preference axes in the prompt for response mapper.
-
temperature(float, default:1.0) –Temperature for the model.
Returns:
-
Optional[ContinualAlignmentDataset]–Optional[ContinualAlignmentDataset]: The synthetically generated dataset.
Source code in aif_gen/generate/engine.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 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 | |
Prompt Mapper
PromptMapperBase
Bases: ABC
Methods:
-
generate_prompt–Generate a prompt that, when given to a language model, produces a prompt for a given AlignmentTask.
generate_prompt
abstractmethod
generate_prompt(task: AlignmentTask) -> str
Generate a prompt that, when given to a language model, produces a prompt for a given AlignmentTask.
Parameters:
-
task(AlignmentTask) –The alignment task containing the domain, objective, and preferences.
Returns:
-
str(str) –A structured prompt string for the LLM.
Source code in aif_gen/generate/mappers/base.py
9 10 11 12 13 14 15 16 17 18 | |
PromptMapper
Bases: PromptMapperBase
Generate a prompt that, when given to a language model, produces a prompt for a given AlignmentTask.
Samples domain component seed words (without replacement) from the AlignmentTask to contextualize the prompt. The sampling is parameterized by the weight of each component of the domain.
Parameters:
-
max_seed_word_samples(int, default:2) –Maximum number of seed words to sample across all domain components (default=2)
-
suffix_context(Optional[str]=None, default:None) –Optional suffix text to add at the end of the generated prompt.
Attributes:
-
max_seed_word_samples(int) –Maximum number of seed words to sample across all domain components.
Source code in aif_gen/generate/mappers/prompt_mapper.py
22 23 24 25 26 27 28 | |
max_seed_word_samples
property
max_seed_word_samples: int
Maximum number of seed words to sample across all domain components.
Response Mapper
ResponseMapperBase
Bases: ABC
Methods:
-
generate_prompt–Generate a prompt that, when given to a language model, produces a (chosen, rejected)
generate_prompt
abstractmethod
generate_prompt(
task: AlignmentTask, task_prompt: str
) -> str
Generate a prompt that, when given to a language model, produces a (chosen, rejected) response pair for the task_prompt and AlignmentTask.
Parameters:
-
task(AlignmentTask) –The alignment task containing the domain, objective, and preferences.
-
task_prompt(str) –The task prompt to generated responses for.
Returns:
-
str(str) –A structured prompt string for the LLM.
Source code in aif_gen/generate/mappers/base.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
ResponseMapper
Bases: ResponseMapperBase
Generate a prompt that, when given to a language model, produces a winning and losing response to the task_prompt.
Parameters:
-
suffix_context(Optional[str]=None, default:None) –Optional suffix text to add at the end of the generated prompt.
Source code in aif_gen/generate/mappers/response_mapper.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Caching
AsyncElasticsearchCache
AsyncElasticsearchCache(
es: AsyncElasticsearch, index_name: str
)
Methods:
-
close–Close Elasticsearch connection.
-
get–Try reading response from cache.
-
maybe_from_env_var–Initialize from env var. Returns None if any of the required env vars are missing.
-
set–Set/Update cache.
Source code in aif_gen/generate/caching.py
12 13 14 15 16 17 18 19 | |
close
async
close() -> None
Close Elasticsearch connection.
Source code in aif_gen/generate/caching.py
82 83 84 | |
get
async
Try reading response from cache.
Parameters:
-
query(str) –The query to fetch from cache.
-
nonce(str, default:None) –An optional nonce to differentiate cache entries.
Returns:
-
str | None–str | None: Cached result if available.
Source code in aif_gen/generate/caching.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
maybe_from_env_var
async
staticmethod
maybe_from_env_var(
index_name: str,
) -> AsyncElasticsearchCache | None
Initialize from env var. Returns None if any of the required env vars are missing.
Source code in aif_gen/generate/caching.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
set
async
Set/Update cache.
Parameters:
-
query(str) –The query whose result is to be cached.
-
value(str) –The value to store in cache.
-
nonce(str, default:None) –An optional nonce to differentiate cache entries.
Source code in aif_gen/generate/caching.py
70 71 72 73 74 75 76 77 78 79 80 | |