MCPcopy Create free account
hub / github.com/eric-mitchell/direct-preference-optimization / __init__

Method __init__

trainers.py:524–536  ·  view source on GitHub ↗

A trainer subclass that uses TensorParallel to shard the model across multiple GPUs. Based on https://github.com/BlackSamorez/tensor_parallel. Note sampling is extremely slow, see https://github.com/BlackSamorez/tensor_parallel/issues/66.

(self, policy, config, seed, run_dir, reference_model=None, rank=0, world_size=1)

Source from the content-addressed store, hash-verified

522
523class TensorParallelTrainer(BasicTrainer):
524 def __init__(self, policy, config, seed, run_dir, reference_model=None, rank=0, world_size=1):
525 """A trainer subclass that uses TensorParallel to shard the model across multiple GPUs.
526
527 Based on https://github.com/BlackSamorez/tensor_parallel. Note sampling is extremely slow,
528 see https://github.com/BlackSamorez/tensor_parallel/issues/66.
529 """
530 super().__init__(policy, config, seed, run_dir, reference_model, rank, world_size)
531
532 rank0_print('Sharding policy...')
533 self.policy = tp.tensor_parallel(policy, sharded=True)
534 if config.loss.name in {'dpo', 'ipo'}:
535 rank0_print('Sharding reference model...')
536 self.reference_model = tp.tensor_parallel(reference_model, sharded=False)
537
538 def save(self, output_dir=None, metrics=None):
539 """Save (unsharded) policy state to disk."""

Callers

nothing calls this directly

Calls 2

rank0_printFunction · 0.90
__init__Method · 0.45

Tested by

no test coverage detected