diff --git a/python/sglang/multimodal_gen/runtime/platforms/xpu.py b/python/sglang/multimodal_gen/runtime/platforms/xpu.py index 5668eebfd..f6064455f 100644 --- a/python/sglang/multimodal_gen/runtime/platforms/xpu.py +++ b/python/sglang/multimodal_gen/runtime/platforms/xpu.py @@ -103,23 +103,9 @@ class XpuPlatform(Platform): if empty_cache: torch.xpu.empty_cache() - # Use mem_get_info() with a sanity cap to avoid KV-cache over-allocation - # on drivers that incorrectly return total memory as free memory. - # Consistent with the fallback: free = max(0, total - allocated). - try: - free_gpu_memory, total_gpu_memory = torch.xpu.mem_get_info(device_id) - used_memory = float(torch.xpu.memory_allocated(device_id)) - free_gpu_memory = min( - float(free_gpu_memory), - max(0.0, float(total_gpu_memory) - used_memory), - ) - except Exception: - # Fallback for devices/drivers that do not support querying free memory - used_memory = float(torch.xpu.memory_allocated(device_id)) - total_gpu_memory = float( - torch.xpu.get_device_properties(device_id).total_memory - ) - free_gpu_memory = max(0.0, total_gpu_memory - used_memory) + used_memory = torch.xpu.memory_allocated(device_id) + total_gpu_memory = torch.xpu.get_device_properties(device_id).total_memory + free_gpu_memory = total_gpu_memory - used_memory if distributed: import torch.distributed as dist diff --git a/python/sglang/srt/utils/common.py b/python/sglang/srt/utils/common.py index 5a1259cb0..aa9bd36d6 100644 --- a/python/sglang/srt/utils/common.py +++ b/python/sglang/srt/utils/common.py @@ -434,23 +434,9 @@ def get_available_gpu_memory( if empty_cache: empty_device_cache(torch.xpu) - # Use mem_get_info() with a sanity cap to avoid KV-cache over-allocation - # on drivers that incorrectly return total memory as free memory. - # Consistent with the fallback: free = max(0, total - allocated). - try: - free_gpu_memory, total_gpu_memory = torch.xpu.mem_get_info(gpu_id) - used_memory = float(torch.xpu.memory_allocated(gpu_id)) - free_gpu_memory = min( - float(free_gpu_memory), - max(0.0, float(total_gpu_memory) - used_memory), - ) - except Exception: - # Fallback for devices/drivers that do not support querying free memory - used_memory = float(torch.xpu.memory_allocated(gpu_id)) - total_gpu_memory = float( - torch.xpu.get_device_properties(gpu_id).total_memory - ) - free_gpu_memory = max(0.0, total_gpu_memory - used_memory) + used_memory = torch.xpu.memory_allocated(gpu_id) + total_gpu_memory = torch.xpu.get_device_properties(gpu_id).total_memory + free_gpu_memory = total_gpu_memory - used_memory elif device == "hpu": num_gpus = torch.hpu.device_count()