[Worker]Lazy import torch_npu (#184)
### What this PR does / why we need it? To avoid unnecessary delays, we only import torch_npu when profilling is enabled. Signed-off-by: wangli <wangli858794774@gmail.com>
This commit is contained in:
@@ -22,7 +22,6 @@ from typing import Dict, List, Optional, Set, Tuple, Type, Union
|
||||
|
||||
import torch
|
||||
import torch.distributed
|
||||
import torch_npu
|
||||
from torch import nn
|
||||
from vllm import envs
|
||||
from vllm.config import ParallelConfig, VllmConfig
|
||||
@@ -124,6 +123,8 @@ class NPUWorker(LocalOrDistributedWorkerBase):
|
||||
# Torch profiler. Enabled and configured through env vars:
|
||||
# VLLM_TORCH_PROFILER_DIR=/path/to/save/trace
|
||||
if envs.VLLM_TORCH_PROFILER_DIR:
|
||||
# lazy import so that torch_npu is not required for normal use.
|
||||
import torch_npu
|
||||
torch_profiler_trace_dir = envs.VLLM_TORCH_PROFILER_DIR
|
||||
logger.info("Profiling enabled. Traces will be saved to: %s",
|
||||
torch_profiler_trace_dir)
|
||||
|
||||
Reference in New Issue
Block a user