[RL] add pause, update_weights, resume interface for async RL - #6052
Conversation
…gine by common run_control_method
|
Thanks for your contribution! |
…_requests, resource_manager_v1.preempted_all
There was a problem hiding this comment.
Pull request overview
这个PR为异步RL场景添加了pause、update_weights、resume接口,支持通过RDMA进行权重原地更新。实现了api-server、engine和worker之间的控制信号通信机制。
Changes:
- 新增4个REST API接口:/v1/pause、/v1/resume、/v1/is_paused、/v1/update_weights
- 实现ControlRequest和ControlResponse类以支持控制消息的序列化和传输
- 在engine层添加pause/resume状态管理和权重更新协调逻辑
- 在worker层实现RDMA权重同步和原地更新能力
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 29 comments.
Show a summary per file
| File | Description |
|---|---|
| fastdeploy/entrypoints/openai/api_server.py | 新增4个控制接口端点 |
| fastdeploy/entrypoints/engine_client.py | 添加run_control_method方法处理控制请求 |
| fastdeploy/engine/request.py | 定义ControlRequest和ControlResponse类 |
| fastdeploy/engine/common_engine.py | 实现pause/resume/update_weights核心逻辑 |
| fastdeploy/engine/sched/resource_manager_v1.py | 添加preempted_all和wait相关方法 |
| fastdeploy/worker/worker_process.py | 添加控制请求处理和control output queue |
| fastdeploy/worker/gpu_worker.py | 添加update_weights方法 |
| fastdeploy/worker/gpu_model_runner.py | 转发update_weights到dynamic_weight_manager |
| fastdeploy/rl/dynamic_weight_manager.py | 实现RDMA权重同步和参数验证 |
| fastdeploy/scheduler/local_scheduler.py | 添加get_inflight_requests方法 |
| fastdeploy/config.py | 添加rsync_config配置项 |
| fastdeploy/engine/args_utils.py | 添加rsync_config命令行参数 |
| fastdeploy/inter_communicator/fmq.py | 改进日志输出 |
| fastdeploy/output/token_processor.py | 修复metrics访问方式 |
| tests/scheduler/test_local_scheduler.py | 添加get_inflight_requests测试 |
| tests/engine/test_resource_manager_v1.py | 添加preempted_all测试 |
| tests/engine/test_control_request_response.py | 添加ControlRequest/Response单元测试 |
| asyncio.run(self._ctrl_output.put(succ_result, shm_threshold=100 * 1024 * 1024)) | ||
| except Exception as e: | ||
| error_msg = f"Rank-{self.local_rank} Failed run control method {method}: {str(e)}" | ||
| logger.info(f"{error_msg}\n{traceback.format_exc()}") |
There was a problem hiding this comment.
日志级别使用不当。这里使用的是logger.info记录失败信息,应该使用logger.error或logger.warning来记录错误信息。
| logger.info(f"{error_msg}\n{traceback.format_exc()}") | |
| logger.error(f"{error_msg}\n{traceback.format_exc()}") |
| def _control_pause(self, control_request: ControlRequest) -> dict | None: | ||
| """暂停请求生成 | ||
|
|
||
| Args: | ||
| args: 控制参数字典,暂停相关的配置参数 | ||
|
|
||
| Returns: | ||
| tuple: (error_code, error_msg) 元组 | ||
| - error_code: 错误代码,0表示成功,非0表示失败 | ||
| - error_msg: 错误信息,成功时为空字符串 |
There was a problem hiding this comment.
注释应该使用英文。根据代码规范,代码中的注释应该使用英文,而不是中文。
| def _control_update_weights(self, control_request: ControlRequest) -> dict | None: | ||
| """更新模型权重 | ||
|
|
||
| Args: | ||
| args: 控制参数字典,更新权重相关的配置参数 | ||
|
|
||
| Returns: | ||
| dict | None: 返回结果字典或None,包含更新权重的操作结果信息 |
There was a problem hiding this comment.
注释应该使用英文。根据代码规范,代码中的注释应该使用英文,而不是中文。
| def _control_resume(self, control_request: ControlRequest) -> dict | None: | ||
| """恢复暂停的请求生成 | ||
|
|
||
| Args: | ||
| args: 控制参数字典,恢复生成相关的配置参数 | ||
|
|
||
| Returns: | ||
| dict | None: 返回结果字典或None,包含恢复操作的状态信息 |
There was a problem hiding this comment.
注释应该使用英文。根据代码规范,代码中的注释应该使用英文,而不是中文。
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| tp_size = cfg.parallel_config.tensor_parallel_size | ||
| dp_index = cfg.parallel_config.local_data_parallel_id | ||
| for rank in range(tp_size): | ||
| name = f"ctrl_w2e_rank{rank+tp_size*dp_index}" |
There was a problem hiding this comment.
如果一台机器上部署多个实例,不同实例之间的 fmq 命名会冲突吗
There was a problem hiding this comment.
这个确实有可能,命名上我把engine_worker_queue的port加进去吧,这样不同fd实例启动时指定的engine_worker_queue port不同可以独立区分开
| control_reqs.append(req_dict[0]) | ||
| else: | ||
| max_occupied_batch_index = int(bsz) | ||
| req_dicts.extend(req_dict) |
There was a problem hiding this comment.
如果这个 batch 能同时包含控制请求和普通请求,更新权重之后,普通请求还需要执行 execute_model 吗?如果执行的话那本次生成 token 所使用的权重是不是和已生成的 token 所使用的权重不一致
There was a problem hiding this comment.
对于权重更新的场景:这里预期是不会既包含控制请求,又包含推理请求的,这个是在engine(作为worker的client)来控制的,可以参考common_engine里的逻辑。
这里更多的是对更通用的控制信号通信时留得一点buffer,比如某些控制信号可能只是想知道当前worker的状态是不是health的,或者想知道worker当前内部的一些动态的状态。不过通用的控制信号通信逻辑也还有一些todo,比如支持可选的异步执行等。
| self.llm_logger.info(f"Total {len(running_reqs)} requests need to be aborted.") | ||
| self.resource_manager.get_real_bsz() | ||
| self.engine_worker_queue.put_tasks((running_reqs, self.resource_manager.real_bsz)) | ||
| self.resource_manager.wait_worker_inflight_requests_finish(timeout=60) |
There was a problem hiding this comment.
这里是需要等待推理自然结束还是中止推理呢
There was a problem hiding this comment.
因为在上一步将当前所有running请求都调度成了抢占请求,因此worker会在下一个step将所有正在推理请求按照抢占逻辑打断,这里虽然是等待,但其实不是等待正常推理结束,而是在等待worker执行抢占操作。
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #6052 +/- ##
==========================================
Coverage ? 67.63%
==========================================
Files ? 381
Lines ? 50321
Branches ? 7872
==========================================
Hits ? 34036
Misses ? 13802
Partials ? 2483
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…Paddle#6052) * support dynamic run_control_request through zmq from apiserver to common_engine * support pause/resume/is_paused/update_weights in apiserver->common_engine by common run_control_method * change /is_puased from HTTP POST method to GET method * add pause、resume、is_paused implementation * support engine <==> worker communication(request&response) * support sync weights through RDMA from checkpoint_transfer * support specified version, rsync_config in update_weights rpc call * add pause, update_weights, resume interface for async RL * bug fix: update_weights support using default arguments * fix typo * typo fix * typo fix * typo fix * add unitest for control request/response, localscheduler.get_inflight_requests, resource_manager_v1.preempted_all * add "rsync" to LoadConfig.load_strategy Literal type hints Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * typo fix * typo fix * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * check version/rsync params * add error log when version.txt not exists Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * raise specified ValueError when paramters check failed Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * tp barrier after run_control_method * encode 'engine_worker_queue_port' to unique name of worker2engine fmq queue * typo fix * typo fix --------- Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Paddle#6052) * support dynamic run_control_request through zmq from apiserver to common_engine * support pause/resume/is_paused/update_weights in apiserver->common_engine by common run_control_method * change /is_puased from HTTP POST method to GET method * add pause、resume、is_paused implementation * support engine <==> worker communication(request&response) * support sync weights through RDMA from checkpoint_transfer * support specified version, rsync_config in update_weights rpc call * add pause, update_weights, resume interface for async RL * bug fix: update_weights support using default arguments * fix typo * typo fix * typo fix * typo fix * add unitest for control request/response, localscheduler.get_inflight_requests, resource_manager_v1.preempted_all * add "rsync" to LoadConfig.load_strategy Literal type hints Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * typo fix * typo fix * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * check version/rsync params * add error log when version.txt not exists Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * raise specified ValueError when paramters check failed Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * tp barrier after run_control_method * encode 'engine_worker_queue_port' to unique name of worker2engine fmq queue * typo fix * typo fix --------- Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Paddle#6052) * support dynamic run_control_request through zmq from apiserver to common_engine * support pause/resume/is_paused/update_weights in apiserver->common_engine by common run_control_method * change /is_puased from HTTP POST method to GET method * add pause、resume、is_paused implementation * support engine <==> worker communication(request&response) * support sync weights through RDMA from checkpoint_transfer * support specified version, rsync_config in update_weights rpc call * add pause, update_weights, resume interface for async RL * bug fix: update_weights support using default arguments * fix typo * typo fix * typo fix * typo fix * add unitest for control request/response, localscheduler.get_inflight_requests, resource_manager_v1.preempted_all * add "rsync" to LoadConfig.load_strategy Literal type hints Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * typo fix * typo fix * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * check version/rsync params * add error log when version.txt not exists Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * raise specified ValueError when paramters check failed Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * tp barrier after run_control_method * encode 'engine_worker_queue_port' to unique name of worker2engine fmq queue * typo fix * typo fix --------- Co-authored-by: Jiang-Jia-Jun <163579578+Jiang-Jia-Jun@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Motivation
Modifications
其他说明:
Usage or Command
说明:
Accuracy Tests
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.