MCPcopy Create free account

hub / github.com/ContextualAI/HALOs / functions

Functions162 in github.com/ContextualAI/HALOs

↓ 14 callersFunctionmasked_mean
Compute mean of tensor with a masked values.
train/utils.py:140
↓ 13 callersFunctiondelete_dicts
Delete all items inside the given dictionaries.
train/utils.py:206
↓ 13 callersMethodget_sequence_rewards
If regular alignment, return the HALO-defined reward for the sequence (log [policy(y|x)/reference(y|x)]). Args:
train/trainers.py:163
↓ 13 callersFunctionrank0_print
Print, but only on rank 0.
train/utils.py:112
↓ 12 callersMethodnum_generations
(self)
train/data.py:88
↓ 11 callersMethodfrom_pretrained
r""" Instantiates a new model from a pretrained model from `transformers`. The pretrained model is loaded using the `from_pretrained`
train/models.py:48
↓ 11 callersFunctionon_rank0
()
train/utils.py:118
↓ 11 callersMethodstate_dict
r""" Return the state_dict of the pretrained model.
train/models.py:186
↓ 10 callersMethodcollate
Takes a list of examples and returns a batch of examples with consistent padding across all processes. Uses a fixed maximum length fo
train/dataloader.py:110
↓ 9 callersMethodremove_extra_spaces
Remove double spaces in the prompt and generations to standardize spacing.
train/data.py:91
↓ 9 callersMethodtokenize_batch_element
Tokenize a single batch element and truncate if prompt + generation is too long. Batch element is turned into Pytorch tensors in sel
train/dataloader.py:157
↓ 7 callersMethodeval
Run evaluation on all the examples in the test data and return the metrics from get_batch_metrics. This is close-ended evaluation and
train/trainers.py:1314
↓ 7 callersMethodget_batch_logps
Compute the token-level log probabilities of the given labels under the given logits.
train/trainers.py:119
↓ 6 callersMethodsample
Sample from the given model. NOTE: If the policy is being trained with FSDP, then sampling from it directly will produce gibberish.
train/trainers.py:460
↓ 5 callersMethodfree_memory
(self)
train/trainers.py:546
↓ 5 callersMethodsave
Save tokenizer, policy model, optimizer, scheduler state to disk.
train/trainers.py:1486
↓ 5 callersMethodsave_pretrained
r""" Save the pretrained model to a directory. This method is a wrapper around `transformers.PreTrainedModel.save_pretrained`. Please
train/models.py:165
↓ 4 callersMethodclose
Close the JSON array and the file.
train/utils.py:64
↓ 4 callersFunctionformatted_dict
Format a dictionary for printing.
train/utils.py:188
↓ 4 callersMethodget_process_data
Return the subset of data to be processed in the current process.
train/dataloader.py:259
↓ 4 callersMethodloss
Compute the DPO loss for a batch of policy and reference model token-level log probabilities.
train/trainers.py:747
↓ 3 callersMethod__init__
(self, config, **kwargs)
train/models.py:207
↓ 3 callersFunctioncreate_pairwise_feedback_item
Create feedback item with 50% chance of swapping pairs
train/label.py:159
↓ 3 callersMethodforward
Run the given model on the given batch of inputs. Returns: chosen_logps: log probabilities of chosen examples
train/trainers.py:588
↓ 3 callersMethodforward
Run the given model on the given batch of inputs, concatenating the chosen and rejected inputs together. Return two tensors of shape (batch
train/trainers.py:687
↓ 3 callersMethodforward
Run the given model on the given batch of inputs. Args: model: model to run forward pass on batch: input batch (forwa
train/trainers.py:1123
↓ 3 callersFunctionmasked_var
Compute variance of tensor with masked values.
train/utils.py:148
↓ 2 callersMethod__init__
(self, dataset_names: List[str], tokenizer, process_index:
train/dataloader.py:37
↓ 2 callersMethod_remove_padding
(self, token_ids)
train/models.py:466
↓ 2 callersMethod_split_kwargs
Separate the kwargs from the arguments that we support inside `supported_args` and the ones that we don't.
train/models.py:133
↓ 2 callersMethodconcatenated_inputs
Concatenate the chosen and rejected inputs into a single tensor. The first half is chosen outputs, the second half is rejected. Args:
train/trainers.py:658
↓ 2 callersMethodeval
(self)
train/models.py:549
↓ 2 callersMethodforward
Run the given model on the given batch of inputs. Args: - model: the model to use for the forward pass - batc
train/trainers.py:919
↓ 2 callersMethodforward
Run the given model on the given batch of inputs. Args: - model: the model to use for the forward pass - batc
train/trainers.py:1036
↓ 2 callersMethodgenerate
r""" A simple wrapper around the `generate` method of the wrapped model. Please refer to the [`generate`](https://huggingface.co/docs/
train/models.py:361
↓ 2 callersFunctionget_base_model_state_dict_from_peft
Return the state dict for the base model given the state dict for a lora-wrapped AutoModelForCausalLM, merging the lora weights as needed.
train/utils.py:70
↓ 2 callersMethodget_batch_metrics
Compute the loss and other metrics for the given batch of inputs. Arg: batch: dictionary of inputs for the batch (what is
train/trainers.py:212
↓ 2 callersMethodget_batch_metrics
Given a batch that has been processed in the outer loop of PPO, return the batch statistics and the loss.
train/trainers.py:1450
↓ 2 callersMethodget_flat_data
Return the flattened data for the given prompts across all processes as a list of tuples. The first element of this tuple should alwa
train/dataloader.py:252
↓ 2 callersMethodget_global_batch_dict
Get the processed dict for the entire batch. Args: batch: dictionary containing batch data (shoud have keys 'values', 'r
train/trainers.py:1272
↓ 2 callersFunctionget_hh
Load the Anthropic Helpful-Harmless dataset from Huggingface and convert it into to a Dataset. For this dataset, the SFT text is the preferre
train/data.py:332
↓ 2 callersMethodget_ratios
Return the probability ratio under the policy vs the reference [policy(y|x)/reference(y|x)]. Apply humanline if specified. A
train/trainers.py:136
↓ 2 callersMethodgradient_checkpointing_enable
Enable gradient chekpointing.
train/models.py:409
↓ 2 callersFunctionpad_to_length
(tensor: torch.Tensor, length: int, pad_value: Union[int, float], dim: int = -1)
train/utils.py:122
↓ 2 callersFunctionprocess_log_file
Process a single log file and extract top-level model metrics.
evals/scripts/summarize_metrics.py:116
↓ 2 callersMethodresize_token_embeddings
Resize the vocabulary size of the language model.
train/models.py:403
↓ 2 callersMethodsync_reference_with_policy
Update the reference model to have the policy weights.
train/trainers.py:452
↓ 2 callersMethodtrain
Train with PPO.
train/trainers.py:1361
↓ 2 callersMethodwrite_item
Write a single item to the JSON array.
train/utils.py:55
↓ 1 callersMethod_compute_log_probs
Compute the token-level log probabilities of the given labels under the given logits.
train/models.py:516
↓ 1 callersMethod_free_memory
(self)
train/models.py:533
↓ 1 callersMethod_init_weights
r""" Initializes the weights of the value head. The default initialization strategy is random. Users can pass a different initializati
train/models.py:290
↓ 1 callersMethod_precompute_log_probs
Calculate the log probabilities of every input-output sequence in every iterator in self.iterators. Save these in self.logprobs as th
train/models.py:469
↓ 1 callersFunctionbuild_conversation
(path: List[pd.Series])
train/data.py:428
↓ 1 callersMethodcompute_advantages
Estimate the advantages and rewards for every token taken. Args: values: the estimated values of the tokens. Should alre
train/trainers.py:1189
↓ 1 callersFunctionconvert_to_binary_feedback
Convert samples to binary feedback format.
train/label.py:133
↓ 1 callersFunctionconvert_to_pairwise_feedback
Convert samples to pairwise feedback format.
train/label.py:177
↓ 1 callersFunctionentropy_from_logits
Calculate entropy from logits. Args: logits: tensor of shape (batch_size, sequence length, vocab) mask: tensor of shape (batc
train/utils.py:173
↓ 1 callersMethodeval
Run evaluation on all the examples in the test data and return the metrics from get_batch_metrics. This is close-ended evaluation and
train/trainers.py:262
↓ 1 callersFunctionextract_alpaca_eval_metrics
Extract AlpacaEval metrics from the log text.
evals/scripts/summarize_metrics.py:8
↓ 1 callersFunctionextract_log_values
Extract only top-level metric values from the log text.
evals/scripts/summarize_metrics.py:43
↓ 1 callersMethodforward
Get logits for both chosen and rejected examples. Args: model: The Bradley-Terry model batch: Dictionary cont
train/trainers.py:1545
↓ 1 callersMethodforward
Return the cached log probabilities for the given input ids.
train/models.py:538
↓ 1 callersFunctionget_api_completion
Get completion from API with retry logic.
train/utils.py:19
↓ 1 callersFunctionget_available_datasets
Get list of available datasets by finding all get_* functions in dataloader.py
train/sample.py:39
↓ 1 callersMethodget_num_training_steps
Get the number of training steps (needed for learning rate scheduler).
train/dataloader.py:248
↓ 1 callersFunctionget_path_to_root
(node: pd.Series)
train/data.py:421
↓ 1 callersMethodget_reward_scores
Get reward scores either from reward model or binary labels. Args: batch: Dictionary containing batch data
train/trainers.py:1157
↓ 1 callersFunctionhydra_main
(config: DictConfig)
launch.py:333
↓ 1 callersMethodloss
Compute the Kahneman-Tversky loss for a batch of policy and reference model log probabilities. If generation y ~ p_desirable, we have the 'de
train/trainers.py:855
↓ 1 callersMethodloss
Compute the GRPO loss. Args: policy_logps: log probability of the output under the policy (microbatch_size, sequence_len
train/trainers.py:1010
↓ 1 callersMethodloss
Given the batch statistics and the current episode's values, calculate the loss and return some loss statistics. Args: b
train/trainers.py:1235
↓ 1 callersMethodloss
Compute Bradley-Terry loss given the logits for chosen and rejected examples. The Bradley-Terry model predicts P(A > B) = sigmoid(sco
train/trainers.py:1573
↓ 1 callersFunctionmain
Main entry point for training. Validates config, creates/initializes model(s), and starts training.
launch.py:42
↓ 1 callersFunctionmain
(args)
train/label.py:231
↓ 1 callersFunctionmain
(args)
train/sample.py:59
↓ 1 callersMethodpost_init
r""" Post initialization method. This method is called after the model is instantiated and loaded from a checkpoint. It can be used to
train/models.py:192
↓ 1 callersMethodprepare_accelerator
Prepare the Accelerator.
train/trainers.py:107
↓ 1 callersFunctionprocess_batch_with_reward_model
Process a batch through the reward model using the already tokenized sequences.
train/label.py:40
↓ 1 callersFunctionprocess_directory
Process all log files in a directory.
evals/scripts/summarize_metrics.py:133
↓ 1 callersFunctionprocess_samples_with_api
Process all samples through the API.
train/label.py:77
↓ 1 callersMethodpush_to_hub
r""" Push the pretrained model to the hub. This method is a wrapper around `transformers.PreTrainedModel.push_to_hub`. Please refer to
train/models.py:149
↓ 1 callersFunctionrowwise_product
Calculate the row-wise product over all the elements that have not been masked out. Args: mat: tensor of shape (batch_size, sequence
train/utils.py:156
↓ 1 callersMethodsave
Save tokenizer, policy model, optimizer, scheduler state to disk.
train/trainers.py:400
↓ 1 callersFunctionset_offline_if_needed
()
train/utils.py:98
↓ 1 callersFunctionsplit_prompt_and_responses
(ex)
train/data.py:359
↓ 1 callersFunctionvalidate_datasets
Validate that all requested datasets have corresponding get_* functions
train/sample.py:45
Method__call__
(self, *args, **kwargs)
train/models.py:546
Method__getitem__
Get an attribute of the Example by its key. Args: key: The attribute name to retrieve Retur
train/data.py:70
Method__getitem__
(self, key)
train/data.py:122
Method__init__
A trainer for a language model, supporting either SFT, HALO, or offline PPO training.
train/trainers.py:64
Method__init__
(self, *args, **kwargs)
train/trainers.py:852
Method__init__
(self, file: TextIO)
train/utils.py:50
Method__init__
(self, *args, **kwargs)
train/dataloader.py:354
Method__init__
(self, *args, **kwargs)
train/dataloader.py:462
Method__init__
(self, pretrained_model=None, **kwargs)
train/models.py:43
Method__init__
r""" Initializes the model. Args: pretrained_model (`transformers.PreTrainedModel`): The model to wrap. I
train/models.py:270
Method__init__
Args: - reference_accelerator: accelerator that should be used for caching (different from main accelerator) - refere
train/models.py:433
Method__init__
(self, name)
train/data.py:112
Method__iter__
Create a flat version of the data and yield batches.
train/dataloader.py:244
next →1–100 of 162, ranked by callers