MCPcopy Create free account

hub / github.com/eric-mitchell/direct-preference-optimization / functions

Functions48 in github.com/eric-mitchell/direct-preference-optimization

↓ 22 callersFunctionrank0_print
Print, but only on rank 0.
utils.py:40
↓ 9 callersFunctionget_local_dir
Return the path to the cache directory for this user.
utils.py:46
↓ 8 callersFunctionall_gather_if_needed
Gather and stack/cat values from all processes, if there are multiple processes.
utils.py:83
↓ 7 callersMethodwrite_state_dict
Write a checkpoint to disk.
trainers.py:401
↓ 4 callersFunctionpad_to_length
(tensor: torch.Tensor, length: int, pad_value: Union[int, float], dim: int = -1)
utils.py:74
↓ 4 callersFunctionslice_and_move_batch_for_device
Slice a batch into chunks, and move each chunk to the specified device.
utils.py:64
↓ 3 callersMethodsave
Save policy, optimizer, and scheduler state to disk, gathering from all processes and saving only on the rank 0 process.
trainers.py:497
↓ 2 callersFunction_get_batch_logps
Compute the log probabilities of the given labels under the given logits. Args: logits: Logits of the model (unnormalized). Shape: (batch
trainers.py:90
↓ 2 callersFunctioncollate_fn
(batch)
preference_datasets.py:186
↓ 2 callersMethodconcatenated_forward
Run the given model on the given batch of inputs, concatenating the chosen and rejected inputs together. We do this to avoid doing
trainers.py:210
↓ 2 callersFunctiondisable_dropout
Disable dropout in a model.
utils.py:99
↓ 2 callersFunctionformatted_dict
Format a dictionary for printing.
utils.py:94
↓ 2 callersFunctionget_batch_iterator
Get an iterator over batches of data. Stops after n_epochs or n_examples, whichever comes first. Args: names: Names of datasets to use.
preference_datasets.py:280
↓ 2 callersMethodget_batch_metrics
Compute the SFT or DPO loss and other metrics for the given batch of inputs.
trainers.py:223
↓ 2 callersFunctionstrip_html_tags
Strip HTML tags from a string, except for <code> tags (which contain real code in the StackExchange answers).
preference_datasets.py:22
↓ 2 callersFunctiontokenize_batch_element
Tokenize a single batch element. At this stage, we don't convert to PyTorch tensors yet; we just handle the truncation in case th
preference_datasets.py:214
↓ 1 callersMethod__init__
A trainer subclass that uses PyTorch FSDP to shard the model across multiple GPUs. This trainer will shard both the policy and ref
trainers.py:431
↓ 1 callersMethodclip_gradient
Clip the gradient norm of the parameters of a non-FSDP policy.
trainers.py:397
↓ 1 callersFunctionconcatenated_inputs
Concatenate the chosen and rejected inputs into a single tensor. Args: batch: A batch of data. Must contain the keys 'chosen_input_id
trainers.py:118
↓ 1 callersFunctionextract_anthropic_prompt
Extract the anthropic prompt from a prompt and response pair.
preference_datasets.py:14
↓ 1 callersMethodget_batch_samples
Generate samples from the policy (and reference model, if doing DPO training) for the given batch of inputs.
trainers.py:182
↓ 1 callersFunctionget_block_class_from_model
Get the class of a block from a model, using the block's class name.
utils.py:120
↓ 1 callersFunctionget_collate_fn
Returns a collate function for the given tokenizer. The collate function takes a list of examples (dicts, where values are lists of
preference_datasets.py:180
↓ 1 callersFunctionget_dataset
Load the given dataset by name. Supported by default are 'shp', 'hh', and 'se'.
preference_datasets.py:163
↓ 1 callersFunctionget_hh
Load the Anthropic Helpful-Harmless dataset from Huggingface and convert it to the necessary format. The dataset is converted to a diction
preference_datasets.py:120
↓ 1 callersFunctionget_local_run_dir
Create a local directory to store outputs for this run, and return its path.
utils.py:55
↓ 1 callersFunctionget_open_port
()
utils.py:15
↓ 1 callersFunctionget_se
Load the StackExchange dataset from Huggingface, and return a dict of prompts and responses. See get_hh for the format. We strip the HTML
preference_datasets.py:46
↓ 1 callersFunctionget_shp
Load the Stanford Human Preferences dataset from Huggingface and convert it to the necessary format. See hh for the format. We filter preferen
preference_datasets.py:85
↓ 1 callersFunctioninit_distributed
(rank: int, world_size: int, master_addr: str = 'localhost', port: int = 12355, backend: str = 'nccl')
utils.py:148
↓ 1 callersFunctionmain
Main entry point for training. Validates config, creates/initializes model(s), and kicks off worker process(es).
train.py:49
↓ 1 callersFunctionpreference_loss
Compute the DPO loss for a batch of policy and reference model log probabilities. Args: policy_chosen_logps: Log probabilities of the pol
trainers.py:45
↓ 1 callersMethodsave
Save policy, optimizer, and scheduler state to disk.
trainers.py:415
↓ 1 callersFunctionsplit_prompt_and_responses
(ex)
preference_datasets.py:145
↓ 1 callersMethodtrain
Begin either SFT or DPO training, with periodic evaluation.
trainers.py:272
↓ 1 callersFunctionworker_main
Main function for each worker process (may be only 1 for BasicTrainer/TensorParallelTrainer).
train.py:21
Method__enter__
(self)
utils.py:163
Method__exit__
(self, exc_type, exc_value, traceback)
utils.py:172
Method__init__
A trainer for a language model, supporting either SFT or DPO training. If multiple GPUs are present, naively splits the model a
trainers.py:146
Method__init__
A trainer subclass that uses TensorParallel to shard the model across multiple GPUs. Based on https://github.com/BlackSamorez/tensor_paral
trainers.py:524
Method__init__
Temporarily set the random seed, and then restore it when exiting the context.
utils.py:157
Methodclip_gradient
Clip the gradient norm of the parameters of an FSDP policy, gathering the gradients across all GPUs.
trainers.py:493
Functionget_block_class_from_model_class_and_block_name
(model_class: Type, block_class_name: str)
utils.py:128
Functionget_remote_file
(remote_path, local_path=None)
utils.py:21
Functionprint_gpu_memory
Print the amount of GPU memory currently allocated for each GPU.
utils.py:106
Methodsave
Save (unsharded) policy state to disk.
trainers.py:538
Functionstrings_match_up_to_spaces
Returns True if str_a and str_b match up to spaces, False otherwise.
preference_datasets.py:374
Functionstrip_html
(x)
preference_datasets.py:60