MCPcopy Create free account
hub / github.com/X-PLUG/MobileAgent / fit

Function fit

UI-S1/examples/split_placement/split_monkey_patch.py:37–214  ·  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

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

Callers

nothing calls this directly

Calls 15

logMethod · 0.95
TrackingClass · 0.90
apply_kl_penaltyFunction · 0.90
compute_advantageFunction · 0.90
reduce_metricsFunction · 0.90
_timerFunction · 0.85
compute_data_metricsFunction · 0.85
compute_timing_metricsFunction · 0.85
_load_checkpointMethod · 0.80
from_single_dictMethod · 0.80
popMethod · 0.80
unionMethod · 0.80

Tested by

no test coverage detected