仅执行单个任务的推理阶段(不包括评测)。 推理使用 semaphore 限制并发数。 时间记录: - inference_start_time: 推理开始时间(获取信号量后) - inference_time: 推理耗时
(
task: Task,
save_dir: str,
semaphore: asyncio.Semaphore
)
| 131 | return content_parts |
| 132 | |
| 133 | async def inference_single_task( |
| 134 | task: Task, |
| 135 | save_dir: str, |
| 136 | semaphore: asyncio.Semaphore |
| 137 | ) -> Task: |
| 138 | """ |
| 139 | 仅执行单个任务的推理阶段(不包括评测)。 |
| 140 | 推理使用 semaphore 限制并发数。 |
| 141 | |
| 142 | 时间记录: |
| 143 | - inference_start_time: 推理开始时间(获取信号量后) |
| 144 | - inference_time: 推理耗时 |
| 145 | """ |
| 146 | task_id = task.task_id |
| 147 | |
| 148 | # 使用信号量限制并发推理数量 |
| 149 | async with semaphore: |
| 150 | # ✅ 在获取信号量后立即记录推理开始时间 |
| 151 | inference_start_time = time.time() |
| 152 | task.extra["inference_start_time"] = inference_start_time |
| 153 | |
| 154 | try: |
| 155 | logger.info(f"| 🚀 [Task {task_id}] Starting inference...") |
| 156 | |
| 157 | # --- 1. Prepare Prompt --- |
| 158 | question_text = task.input |
| 159 | # 检查模型是否支持视觉/是否被禁用视觉 |
| 160 | if TARGET_MODEL in NON_VISION_MODELS: |
| 161 | logger.info(f"| 🙈 [Task {task_id}] Vision disabled for model {TARGET_MODEL}, using text only.") |
| 162 | question_content = question_text |
| 163 | else: |
| 164 | question_content = parse_markdown_with_images(question_text) |
| 165 | |
| 166 | system_prompt_text = task.system_prompt |
| 167 | |
| 168 | logger.info(f"| 📋 [Task {task_id}] Input length: {len(question_text)}") |
| 169 | |
| 170 | if isinstance(question_content, list): |
| 171 | image_count = sum(1 for part in question_content if isinstance(part, ContentPartImage)) |
| 172 | logger.info(f"| 🖼️ [Task {task_id}] Found {image_count} image(s) in question") |
| 173 | |
| 174 | messages = [ |
| 175 | SystemMessage(content=system_prompt_text), |
| 176 | HumanMessage(content=question_content) |
| 177 | ] |
| 178 | # --- 2. Model Inference (Structured Output) --- |
| 179 | logger.info(f"| ⏳ [Task {task_id}] Model inferencing...") |
| 180 | |
| 181 | try: |
| 182 | response = await model_manager( |
| 183 | model=TARGET_MODEL, |
| 184 | messages=messages, |
| 185 | response_format=Response, |
| 186 | max_completion_tokens=65536 |
| 187 | ) |
| 188 | |
| 189 | if response.success: |
| 190 | response_model = response.extra.parsed_model |
no test coverage detected