MCPcopy Create free account
hub / github.com/agentscope-ai/Trinity-RFT / sync_weight

Method sync_weight

trinity/trainer/trainer.py:223–254  ·  view source on GitHub ↗

Sync the model weight.

(self)

Source from the content-addressed store, hash-verified

221 return self.save_interval > 0 and self.train_step_num % self.save_interval == 0
222
223 async def sync_weight(self) -> Dict:
224 """Sync the model weight."""
225 self.logger.info(f"Trainer sync_weights at step {self.train_step_num} started.")
226 metrics = {}
227 if self.last_sync_time is not None:
228 metrics["time/trainer_sync_interval"] = time.time() - self.last_sync_time
229 with Timer(metrics, "time/sync_weight"):
230 if self.sync_method == SyncMethod.NCCL:
231 result = await self.synchronizer.ready_to_nccl_sync.remote(
232 "trainer", self.train_step_num
233 )
234 if result is None:
235 self.logger.warning(
236 "NCCL weight sync skipped: Explorer has stopped or is unreachable."
237 )
238 else:
239 try:
240 self.engine.sync_weight_nccl()
241 except Exception:
242 self.logger.warning(
243 "NCCL weight sync failed (Explorer may have exited);"
244 f" continuing with stale weights:\n{traceback.format_exc()}"
245 )
246 elif self.train_step_num > 0:
247 if self.sync_method == SyncMethod.CHECKPOINT:
248 await self.engine.save_state_dict()
249 elif self.sync_method == SyncMethod.MEMORY:
250 await self.engine.upload_state_dict()
251 self.last_sync_step = self.train_step_num
252 self.last_sync_time = time.time()
253 self.logger.info(f"Trainer sync_weights at step {self.train_step_num} finished.")
254 return metrics
255
256 def _log_experiences(self, samples: List[Dict]) -> None:
257 self._sample_exps_to_log.extend(samples)

Callers 1

trainMethod · 0.95

Calls 5

TimerClass · 0.90
remoteMethod · 0.80
sync_weight_ncclMethod · 0.45
save_state_dictMethod · 0.45
upload_state_dictMethod · 0.45

Tested by

no test coverage detected