MCPcopy Create free account
hub / github.com/Tencent/digitalhuman / fit

Function fit

RLVER/code/examples/split_placement/split_monkey_patch.py:26–198  ·  view source on GitHub ↗

The training loop of PPO. The driver process only need to call the compute functions of the worker group through RPC to construct the PPO dataflow. The light-weight advantage computation is done on the driver process.

(self)

Source from the content-addressed store, hash-verified

24
25
26def fit(self):
27 """
28 The training loop of PPO.
29 The driver process only need to call the compute functions of the worker group through RPC to construct the PPO dataflow.
30 The light-weight advantage computation is done on the driver process.
31 """
32 from verl.utils.tracking import Tracking
33 from omegaconf import OmegaConf
34
35 logger = Tracking(entity_name=self.config.trainer.entity_name,
36 project_name=self.config.trainer.project_name,
37 experiment_name=self.config.trainer.experiment_name,
38 default_backend=self.config.trainer.logger,
39 config=OmegaConf.to_container(self.config, resolve=True))
40
41 self.global_steps = 0
42
43 # load checkpoint before doing anything
44 self._load_checkpoint()
45
46 # perform validation before training
47 # currently, we only support validation using the reward_function.
48 if self.val_reward_fn is not None and self.config.trainer.get('val_before_train', True):
49 val_metrics = self._validate()
50 pprint(f'Initial validation metrics: {val_metrics}')
51 logger.log(data=val_metrics, step=self.global_steps)
52 if self.config.trainer.get('val_only', False):
53 return
54
55 # we start from step 1
56 self.global_steps += 1
57
58 for epoch in range(self.config.trainer.total_epochs):
59 for batch_dict in self.train_dataloader:
60 metrics = {}
61 timing_raw = {}
62
63 batch: DataProto = DataProto.from_single_dict(batch_dict)
64
65 # pop those keys for generation
66 gen_batch = batch.pop(batch_keys=['input_ids', 'attention_mask', 'position_ids'])
67
68 with _timer('step', timing_raw):
69 # generate a batch
70 with _timer('gen', timing_raw):
71 gen_batch_output = self.actor_rollout_wg.generate_sequences(gen_batch)
72
73 if self.config.algorithm.adv_estimator == AdvantageEstimator.REMAX:
74 with _timer('gen_max', timing_raw):
75 gen_baseline_batch = deepcopy(gen_batch)
76 gen_baseline_batch.meta_info['do_sample'] = False
77 gen_baseline_output = self.actor_rollout_wg.generate_sequences(gen_baseline_batch)
78
79 batch = batch.union(gen_baseline_output)
80 reward_baseline_tensor = self.reward_fn(batch)
81 reward_baseline_tensor = reward_baseline_tensor.sum(dim=-1)
82
83 batch.pop(batch_keys=list(gen_baseline_output.batch.keys()))

Callers

nothing calls this directly

Calls 15

logMethod · 0.95
TrackingClass · 0.90
_timerFunction · 0.90
apply_kl_penaltyFunction · 0.90
compute_advantageFunction · 0.90
reduce_metricsFunction · 0.90
compute_data_metricsFunction · 0.90
compute_timing_metricsFunction · 0.90
reward_fnMethod · 0.80
sumMethod · 0.80
_load_checkpointMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected