Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/ContextualAI/HALOs
/ functions
Functions
162 in github.com/ContextualAI/HALOs
⨍
Functions
162
◇
Types & classes
29
↓ 14 callers
Function
masked_mean
Compute mean of tensor with a masked values.
train/utils.py:140
↓ 13 callers
Function
delete_dicts
Delete all items inside the given dictionaries.
train/utils.py:206
↓ 13 callers
Method
get_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 callers
Function
rank0_print
Print, but only on rank 0.
train/utils.py:112
↓ 12 callers
Method
num_generations
(self)
train/data.py:88
↓ 11 callers
Method
from_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 callers
Function
on_rank0
()
train/utils.py:118
↓ 11 callers
Method
state_dict
r""" Return the state_dict of the pretrained model.
train/models.py:186
↓ 10 callers
Method
collate
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 callers
Method
remove_extra_spaces
Remove double spaces in the prompt and generations to standardize spacing.
train/data.py:91
↓ 9 callers
Method
tokenize_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 callers
Method
eval
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 callers
Method
get_batch_logps
Compute the token-level log probabilities of the given labels under the given logits.
train/trainers.py:119
↓ 6 callers
Method
sample
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 callers
Method
free_memory
(self)
train/trainers.py:546
↓ 5 callers
Method
save
Save tokenizer, policy model, optimizer, scheduler state to disk.
train/trainers.py:1486
↓ 5 callers
Method
save_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 callers
Method
close
Close the JSON array and the file.
train/utils.py:64
↓ 4 callers
Function
formatted_dict
Format a dictionary for printing.
train/utils.py:188
↓ 4 callers
Method
get_process_data
Return the subset of data to be processed in the current process.
train/dataloader.py:259
↓ 4 callers
Method
loss
Compute the DPO loss for a batch of policy and reference model token-level log probabilities.
train/trainers.py:747
↓ 3 callers
Method
__init__
(self, config, **kwargs)
train/models.py:207
↓ 3 callers
Function
create_pairwise_feedback_item
Create feedback item with 50% chance of swapping pairs
train/label.py:159
↓ 3 callers
Method
forward
Run the given model on the given batch of inputs. Returns: chosen_logps: log probabilities of chosen examples
train/trainers.py:588
↓ 3 callers
Method
forward
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 callers
Method
forward
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 callers
Function
masked_var
Compute variance of tensor with masked values.
train/utils.py:148
↓ 2 callers
Method
__init__
(self, dataset_names: List[str], tokenizer, process_index:
train/dataloader.py:37
↓ 2 callers
Method
_remove_padding
(self, token_ids)
train/models.py:466
↓ 2 callers
Method
_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 callers
Method
concatenated_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 callers
Method
eval
(self)
train/models.py:549
↓ 2 callers
Method
forward
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 callers
Method
forward
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 callers
Method
generate
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 callers
Function
get_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 callers
Method
get_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 callers
Method
get_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 callers
Method
get_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 callers
Method
get_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 callers
Function
get_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 callers
Method
get_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 callers
Method
gradient_checkpointing_enable
Enable gradient chekpointing.
train/models.py:409
↓ 2 callers
Function
pad_to_length
(tensor: torch.Tensor, length: int, pad_value: Union[int, float], dim: int = -1)
train/utils.py:122
↓ 2 callers
Function
process_log_file
Process a single log file and extract top-level model metrics.
evals/scripts/summarize_metrics.py:116
↓ 2 callers
Method
resize_token_embeddings
Resize the vocabulary size of the language model.
train/models.py:403
↓ 2 callers
Method
sync_reference_with_policy
Update the reference model to have the policy weights.
train/trainers.py:452
↓ 2 callers
Method
train
Train with PPO.
train/trainers.py:1361
↓ 2 callers
Method
write_item
Write a single item to the JSON array.
train/utils.py:55
↓ 1 callers
Method
_compute_log_probs
Compute the token-level log probabilities of the given labels under the given logits.
train/models.py:516
↓ 1 callers
Method
_free_memory
(self)
train/models.py:533
↓ 1 callers
Method
_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 callers
Method
_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 callers
Function
build_conversation
(path: List[pd.Series])
train/data.py:428
↓ 1 callers
Method
compute_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 callers
Function
convert_to_binary_feedback
Convert samples to binary feedback format.
train/label.py:133
↓ 1 callers
Function
convert_to_pairwise_feedback
Convert samples to pairwise feedback format.
train/label.py:177
↓ 1 callers
Function
entropy_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 callers
Method
eval
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 callers
Function
extract_alpaca_eval_metrics
Extract AlpacaEval metrics from the log text.
evals/scripts/summarize_metrics.py:8
↓ 1 callers
Function
extract_log_values
Extract only top-level metric values from the log text.
evals/scripts/summarize_metrics.py:43
↓ 1 callers
Method
forward
Get logits for both chosen and rejected examples. Args: model: The Bradley-Terry model batch: Dictionary cont
train/trainers.py:1545
↓ 1 callers
Method
forward
Return the cached log probabilities for the given input ids.
train/models.py:538
↓ 1 callers
Function
get_api_completion
Get completion from API with retry logic.
train/utils.py:19
↓ 1 callers
Function
get_available_datasets
Get list of available datasets by finding all get_* functions in dataloader.py
train/sample.py:39
↓ 1 callers
Method
get_num_training_steps
Get the number of training steps (needed for learning rate scheduler).
train/dataloader.py:248
↓ 1 callers
Function
get_path_to_root
(node: pd.Series)
train/data.py:421
↓ 1 callers
Method
get_reward_scores
Get reward scores either from reward model or binary labels. Args: batch: Dictionary containing batch data
train/trainers.py:1157
↓ 1 callers
Function
hydra_main
(config: DictConfig)
launch.py:333
↓ 1 callers
Method
loss
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 callers
Method
loss
Compute the GRPO loss. Args: policy_logps: log probability of the output under the policy (microbatch_size, sequence_len
train/trainers.py:1010
↓ 1 callers
Method
loss
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 callers
Method
loss
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 callers
Function
main
Main entry point for training. Validates config, creates/initializes model(s), and starts training.
launch.py:42
↓ 1 callers
Function
main
(args)
train/label.py:231
↓ 1 callers
Function
main
(args)
train/sample.py:59
↓ 1 callers
Method
post_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 callers
Method
prepare_accelerator
Prepare the Accelerator.
train/trainers.py:107
↓ 1 callers
Function
process_batch_with_reward_model
Process a batch through the reward model using the already tokenized sequences.
train/label.py:40
↓ 1 callers
Function
process_directory
Process all log files in a directory.
evals/scripts/summarize_metrics.py:133
↓ 1 callers
Function
process_samples_with_api
Process all samples through the API.
train/label.py:77
↓ 1 callers
Method
push_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 callers
Function
rowwise_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 callers
Method
save
Save tokenizer, policy model, optimizer, scheduler state to disk.
train/trainers.py:400
↓ 1 callers
Function
set_offline_if_needed
()
train/utils.py:98
↓ 1 callers
Function
split_prompt_and_responses
(ex)
train/data.py:359
↓ 1 callers
Function
validate_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