MCPcopy Create free account
hub / github.com/OpenBMB/AgentCPM-GUI / sync_handler

Method sync_handler

rft/trainer/zmq.py:478–579  ·  view source on GitHub ↗

处理同步信号并更新任务状态

(self)

Source from the content-addressed store, hash-verified

476 self.ready_queue.put(chunk_data)
477
478 def sync_handler(self):
479 """处理同步信号并更新任务状态"""
480 while True:
481 parts = self.sync_signal.recv_multipart()
482 if len(parts) != 2:
483 logger.error(f"Invalid message parts: {len(parts)}, parts: {parts}")
484 continue
485
486 topic, d = parts
487 latest_gid = pickle.loads(d)
488
489 while self.local_gid <= latest_gid:
490 logger.debug(f"Sync advantages for group {self.local_gid}")
491 self.advantage_syncer.send_pyobj(SyncAdvantagesRequest(self.local_gid))
492 task_status = self.advantage_syncer.recv_pyobj()
493 task_status.sort(key=lambda x: x.advantage, reverse=True)
494
495 next_new_tasks = []
496 valid_next_task_completions = []
497 scores = []
498
499 for status in task_status:
500 scores.append(status.score)
501 if (status.score >= float(os.environ.get("MULTITURN_SAMPLE_THRESHOLD", DEFAULT_THRESHOLD)) and
502 status.advantage >= task_status[self.mt_max_beam_width % len(task_status)].advantage):
503 # 考虑将下一轮任务添加到任务队列
504 valid_next_task_completions.append(status.completion_id)
505
506 # 检查是否可能有进一步的任务
507 for status in task_status:
508 if status.completion_id in self.cached_tasks:
509 d = self.cached_tasks[status.completion_id]
510 if (d.data.get("next_id", None) is not None and
511 d.status.completion_id in valid_next_task_completions):
512 # 考虑将下一轮任务添加到任务队列
513 next_new_tasks.append(d)
514
515 if next_new_tasks:
516 # 发送到全局任务分发循环
517 data = []
518 for item in next_new_tasks:
519 data.append({
520 "id": item.data["id"],
521 "gid": self.local_gid,
522 "next_id": item.data["next_id"],
523 "completion_id": item.status.completion_id,
524 "completion": item.data["completion"],
525 })
526
527 # 计算发送数据的正确长度
528 valid_completions_counts = len(valid_next_task_completions)
529 ratio = len(task_status) // valid_completions_counts
530 data = data * ratio
531
532 if (rem := len(task_status) % valid_completions_counts) != 0:
533 # 仅对一个节点附加提醒
534 # 选择包含最小字典顺序UUID的节点并添加提醒
535 small_completion_id = sorted(valid_next_task_completions)[0]

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected