2024-10-10 12:39:36 -07:00
|
|
|
import os
|
|
|
|
|
|
2024-07-21 18:43:11 -07:00
|
|
|
import torch
|
|
|
|
|
|
2024-10-10 12:39:36 -07:00
|
|
|
import vllm.envs as envs
|
|
|
|
|
from vllm.compilation.levels import CompilationLevel
|
|
|
|
|
from vllm.plugins import set_torch_compile_backend
|
|
|
|
|
|
2024-07-21 18:43:11 -07:00
|
|
|
from .interface import Platform, PlatformEnum
|
|
|
|
|
|
2024-10-10 12:39:36 -07:00
|
|
|
if "VLLM_TORCH_COMPILE_LEVEL" not in os.environ:
|
|
|
|
|
os.environ["VLLM_TORCH_COMPILE_LEVEL"] = str(CompilationLevel.DYNAMO_ONCE)
|
|
|
|
|
|
2024-10-29 23:03:49 -07:00
|
|
|
assert envs.VLLM_TORCH_COMPILE_LEVEL < CompilationLevel.PIECEWISE,\
|
2024-10-10 12:39:36 -07:00
|
|
|
"TPU does not support Inductor."
|
|
|
|
|
|
|
|
|
|
set_torch_compile_backend("openxla")
|
|
|
|
|
|
2024-07-21 18:43:11 -07:00
|
|
|
|
|
|
|
|
class TpuPlatform(Platform):
|
|
|
|
|
_enum = PlatformEnum.TPU
|
|
|
|
|
|
2024-09-18 18:38:11 +08:00
|
|
|
@classmethod
|
|
|
|
|
def get_device_name(cls, device_id: int = 0) -> str:
|
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
2024-09-29 10:50:51 +08:00
|
|
|
@classmethod
|
|
|
|
|
def get_device_total_memory(cls, device_id: int = 0) -> int:
|
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
2024-09-18 18:38:11 +08:00
|
|
|
@classmethod
|
|
|
|
|
def inference_mode(cls):
|
2024-07-21 18:43:11 -07:00
|
|
|
return torch.no_grad()
|