trainer.orpo.fwd_bwd_functions
concatenated_inputs(batch, is_encoder_decoder=False, label_pad_token_id=-100, padding_value=0, truncation_mode='keep_end', fixed_max_length=None)
The concatenated_inputs function takes a batch of chosen and rejected examples, and concatenates them together. This is useful for training the model to predict whether an example was chosen by the human annotator. The function also pads all inputs to the same length as the longest input in that batch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
Dict[str, Union[List, Array]]
|
Dict[str,Union[List,chex.Array]]: Pass the batch of data into the function, Allow for the batch to be a list of arrays or just an array, Specify the type of data that is being passed in |
required |
is_encoder_decoder |
bool
|
bool: Determine whether the model is an encoder-decoder model |
False
|
label_pad_token_id |
int
|
int: Pad the labels with a value of -100 |
-100
|
padding_value |
int
|
int: Pad the input_ids and attention_mask arrays to the same length |
0
|
truncation_mode |
Literal['keep_end', 'keep_start']
|
typing.Literal["keep_end", "keep_start"]: is left padded or not should it keep start of the array or the end of the array?. |
'keep_end'
|
|
fixed_max_length
|
int|None: by providing fixed_max_length the func will always return a fixed sequence length and won't use dynamic methods. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Array]
|
A dictionary of the concatenated inputs |
Source code in src/python/easydel/trainer/orpo/fwd_bwd_functions.py
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 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
create_concatenated_forward(is_encoder_decoder, label_pad_token_id, padding_value, truncation_mode='keep_end', fixed_max_length=None)
The create_concatenated_forward function is a helper function that creates a forward pass function for the model. The forward pass function takes in an apply_fn, which is the model's apply_fn, and runs it on concatenated inputs. It returns chosen log probs, rejected log probs, chosen logits and rejected logits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_encoder_decoder |
Determine whether the model is an encoder-decoder model or not |
required | |
label_pad_token_id |
Pad the labels to the same length |
required | |
padding_value |
Pad the inputs to the same length |
required | |
truncation_mode |
Literal['keep_end', 'keep_start']
|
typing.Literal["keep_end","keep_start"]: where to pad and where to keep. |
'keep_end'
|
|
fixed_max_length
|
int|None: by providing fixed_max_length the func will always return a fixed sequence length and won't use dynamic methods. |
required |
Returns:
Type | Description |
---|---|
A function that takes in a apply_fn, params and a batch of inputs, |
Source code in src/python/easydel/trainer/orpo/fwd_bwd_functions.py
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 |
|
create_orpo_step_function(concatenated_forward, beta=0.1, mode='train', batch_partition_spec=PartitionSpec(('fsdp', 'dp'), 'sp'))
The create_orpo_step_function function is a helper function that creates the ORPO training step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
concatenated_forward |
Callable
|
Callable: Define the forward pass of the model |
required |
beta |
float
|
float: Scale the logits |
0.1
|
mode |
Literal['train', 'eval']
|
Literal["train", "eval"] : "train", "eval" function modes |
'train'
|
batch_partition_spec |
PartitionSpec
|
PartitionSpec: Batch PartitionSpec |
PartitionSpec(('fsdp', 'dp'), 'sp')
|
Returns:
Type | Description |
---|---|
A function that takes in a state and a batch |
Source code in src/python/easydel/trainer/orpo/fwd_bwd_functions.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
get_batch_log_probs(logits, labels, average_log_prob=False, label_pad_token_id=-100, is_encoder_decoder=False)
The get_batch_log_probs function computes the log probability of a batch of sequences.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logits |
Array
|
chex.Array: Compute the log_softmax of the input |
required |
labels |
Array
|
chex.Array: Mask the logits |
required |
average_log_prob |
bool
|
bool: Determine whether to average the log prob over the sequence length |
False
|
label_pad_token_id |
int
|
int: Mask out the padding tokens in the labels |
-100
|
is_encoder_decoder |
bool
|
bool: Indicate whether the model is an encoder-decoder model |
False
|
|
Determine whether to average the log probability over all tokens or not |
required |
Returns:
Type | Description |
---|---|
Array
|
The log probability of the labels given the logits |
Source code in src/python/easydel/trainer/orpo/fwd_bwd_functions.py
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 |
|