From 4d5e57f61b1594d235ed570955076ab6a1b7e21f Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Wed, 21 Jan 2026 14:54:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(task):=20=E4=BC=98=E5=8C=96=20GPU=20?= =?UTF-8?q?=E8=B0=83=E5=BA=A6=E4=BB=A5=E6=94=AF=E6=8C=81=E7=89=B9=E5=AE=9A?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 GPU_REQUIRED_TASK_TYPES 集合定义需要 GPU 加速的任务类型 - 修改任务执行逻辑仅对需要 GPU 的任务类型获取 GPU 设备 - 更新 GPU 设备释放逻辑确保仅在实际分配设备时进行释放 - 改进日志记录和资源管理流程 --- services/task_executor.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/services/task_executor.py b/services/task_executor.py index efb8883..5d4038e 100644 --- a/services/task_executor.py +++ b/services/task_executor.py @@ -12,6 +12,12 @@ from typing import Dict, Optional, TYPE_CHECKING from domain.task import Task, TaskType from domain.result import TaskResult, ErrorCode + +# 需要 GPU 加速的任务类型 +GPU_REQUIRED_TASK_TYPES = { + TaskType.RENDER_SEGMENT_VIDEO, + TaskType.COMPOSE_TRANSITION, +} from domain.config import WorkerConfig from core.handler import TaskHandler from services.lease_service import LeaseService @@ -179,9 +185,10 @@ class TaskExecutor: ) lease_service.start() - # 获取 GPU 设备 + # 获取 GPU 设备(仅对需要 GPU 的任务类型) device_index = None - if self.gpu_scheduler.enabled: + needs_gpu = task.task_type in GPU_REQUIRED_TASK_TYPES + if needs_gpu and self.gpu_scheduler.enabled: device_index = self.gpu_scheduler.acquire() if device_index is not None: logger.info(f"[task:{task_id}] Assigned to GPU device {device_index}") @@ -227,8 +234,8 @@ class TaskExecutor: if handler: handler.clear_gpu_device() - # 释放 GPU 设备 - if self.gpu_scheduler.enabled: + # 释放 GPU 设备(仅当实际分配了设备时) + if device_index is not None: self.gpu_scheduler.release(device_index) # 停止租约续期