fix: 修复异常处理问题

This commit is contained in:
2026-04-05 20:44:35 +08:00
parent d2b36cc85d
commit 23ce4bc3ae
2 changed files with 126 additions and 13 deletions
+18
View File
@@ -68,6 +68,9 @@ def apply_sampling_strategies(
filter_value: float = -float("inf"),
) -> Tensor:
"""Apply sampling strategies to the logits tensor."""
# Clone logits to avoid inplace updates on inference tensor
logits = logits.clone()
if temperature != 1.0:
logits = logits / temperature
@@ -377,6 +380,21 @@ class InferenceScheduler:
self._running = False
if hasattr(self, "_loop_thread"):
self._loop_thread.join(timeout=1.0)
# Clear KV cache to free GPU memory
if self.kv_cache is not None:
k_cache, v_cache = self.kv_cache
if k_cache is not None:
k_cache.detach()
if v_cache is not None:
v_cache.detach()
# Clear seq mask
self.seq_mask.detach()
# Clear task lists
self.waiting_queue.clear()
self.active_tasks.clear()
def get_stats(self) -> Dict[str, Any]:
"""Get scheduler statistics."""