|
17 | 17 | # This file is modified from https://github.com/vllm-project/vllm/blob/main/benchmarks/backend_request_func.py |
18 | 18 |
|
19 | 19 |
|
| 20 | +import asyncio |
20 | 21 | import copy |
21 | 22 | import io |
22 | 23 | import json |
@@ -91,6 +92,8 @@ class RequestFuncOutput: |
91 | 92 | metrics: dict = field(default_factory=dict) |
92 | 93 | tool_calls: list = field(default_factory=list) |
93 | 94 | output_ids: list = field(default_factory=list) |
| 95 | + # 本轮请求之前的环境交互等待时长(秒),来自数据集里对应 tool 消息的 env_interact_time |
| 96 | + env_wait_time: float = 0.0 |
94 | 97 |
|
95 | 98 |
|
96 | 99 | @dataclass |
@@ -788,6 +791,19 @@ async def async_request_eb_openai_chat_completions_multi_turn( |
788 | 791 | ) as session: |
789 | 792 | for i, message in enumerate(ori_history): |
790 | 793 | if message["role"] == "user" or message["role"] == "tool": |
| 794 | + # 模拟真实 rollout 里工具执行 / 环境交互的等待时间: |
| 795 | + # 数据集里 tool 消息可能带 env_interact_time(秒), 表示上一步 assistant 生成完到 tool 结果返回的耗时。 |
| 796 | + turn_env_wait = 0.0 |
| 797 | + env_delay = message.get("env_interact_time") if isinstance(message, dict) else None |
| 798 | + if env_delay and os.environ.get("DISABLE_ENV_TOOL_WAIT", "").lower() not in ("1", "true", "yes", "on"): |
| 799 | + try: |
| 800 | + delay_sec = float(env_delay) |
| 801 | + except (TypeError, ValueError): |
| 802 | + delay_sec = 0.0 |
| 803 | + if delay_sec > 0: |
| 804 | + turn_env_wait = delay_sec |
| 805 | + await asyncio.sleep(delay_sec) |
| 806 | + |
791 | 807 | history.append(message) |
792 | 808 | round_input = copy.deepcopy(request_func_input) |
793 | 809 | round_input.history_QA = history |
@@ -841,6 +857,7 @@ async def async_request_eb_openai_chat_completions_multi_turn( |
841 | 857 | ) |
842 | 858 | s1 = time.perf_counter() |
843 | 859 | llm_time += s1 - s0 |
| 860 | + output.env_wait_time = turn_env_wait |
844 | 861 |
|
845 | 862 | outputs.append(output) |
846 | 863 |
|
|
0 commit comments