vllm-npu 0.4.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- vllm/__init__.py +23 -0
- vllm/_custom_ops.py +251 -0
- vllm/attention/__init__.py +13 -0
- vllm/attention/backends/__init__.py +0 -0
- vllm/attention/backends/abstract.py +127 -0
- vllm/attention/backends/flash_attn.py +271 -0
- vllm/attention/backends/flashinfer.py +220 -0
- vllm/attention/backends/rocm_flash_attn.py +374 -0
- vllm/attention/backends/torch_sdpa.py +250 -0
- vllm/attention/backends/xformers.py +393 -0
- vllm/attention/layer.py +56 -0
- vllm/attention/ops/__init__.py +0 -0
- vllm/attention/ops/paged_attn.py +216 -0
- vllm/attention/ops/prefix_prefill.py +792 -0
- vllm/attention/ops/triton_flash_attention.py +810 -0
- vllm/attention/selector.py +91 -0
- vllm/block.py +84 -0
- vllm/config.py +1225 -0
- vllm/core/__init__.py +0 -0
- vllm/core/block/__init__.py +0 -0
- vllm/core/block/block_table.py +295 -0
- vllm/core/block/common.py +199 -0
- vllm/core/block/cpu_gpu_block_allocator.py +228 -0
- vllm/core/block/interfaces.py +205 -0
- vllm/core/block/naive_block.py +318 -0
- vllm/core/block/prefix_caching_block.py +606 -0
- vllm/core/block_manager_v1.py +625 -0
- vllm/core/block_manager_v2.py +258 -0
- vllm/core/evictor_v1.py +105 -0
- vllm/core/evictor_v2.py +127 -0
- vllm/core/interfaces.py +113 -0
- vllm/core/policy.py +45 -0
- vllm/core/scheduler.py +1163 -0
- vllm/distributed/__init__.py +3 -0
- vllm/distributed/communication_op.py +237 -0
- vllm/distributed/device_communicators/__init__.py +0 -0
- vllm/distributed/device_communicators/custom_all_reduce.py +274 -0
- vllm/distributed/device_communicators/pynccl.py +287 -0
- vllm/distributed/device_communicators/pynccl_utils.py +66 -0
- vllm/distributed/parallel_state.py +339 -0
- vllm/distributed/utils.py +136 -0
- vllm/engine/__init__.py +0 -0
- vllm/engine/arg_utils.py +649 -0
- vllm/engine/async_llm_engine.py +737 -0
- vllm/engine/llm_engine.py +784 -0
- vllm/engine/metrics.py +368 -0
- vllm/engine/output_processor/__init__.py +0 -0
- vllm/engine/output_processor/interfaces.py +76 -0
- vllm/engine/output_processor/multi_step.py +142 -0
- vllm/engine/output_processor/single_step.py +284 -0
- vllm/engine/output_processor/stop_checker.py +101 -0
- vllm/engine/output_processor/util.py +19 -0
- vllm/entrypoints/__init__.py +0 -0
- vllm/entrypoints/api_server.py +119 -0
- vllm/entrypoints/llm.py +259 -0
- vllm/entrypoints/openai/__init__.py +0 -0
- vllm/entrypoints/openai/api_server.py +186 -0
- vllm/entrypoints/openai/cli_args.py +115 -0
- vllm/entrypoints/openai/protocol.py +460 -0
- vllm/entrypoints/openai/serving_chat.py +392 -0
- vllm/entrypoints/openai/serving_completion.py +347 -0
- vllm/entrypoints/openai/serving_engine.py +234 -0
- vllm/envs.py +217 -0
- vllm/executor/__init__.py +0 -0
- vllm/executor/cpu_executor.py +152 -0
- vllm/executor/distributed_gpu_executor.py +115 -0
- vllm/executor/executor_base.py +115 -0
- vllm/executor/gpu_executor.py +150 -0
- vllm/executor/multiproc_worker_utils.py +263 -0
- vllm/executor/neuron_executor.py +91 -0
- vllm/executor/ray_gpu_executor.py +327 -0
- vllm/executor/ray_utils.py +119 -0
- vllm/logger.py +153 -0
- vllm/logging/__init__.py +5 -0
- vllm/logging/formatter.py +15 -0
- vllm/lora/__init__.py +0 -0
- vllm/lora/fully_sharded_layers.py +262 -0
- vllm/lora/layers.py +1181 -0
- vllm/lora/lora.py +167 -0
- vllm/lora/models.py +645 -0
- vllm/lora/punica.py +213 -0
- vllm/lora/request.py +32 -0
- vllm/lora/utils.py +98 -0
- vllm/lora/worker_manager.py +251 -0
- vllm/model_executor/__init__.py +7 -0
- vllm/model_executor/guided_decoding/__init__.py +25 -0
- vllm/model_executor/guided_decoding/lm_format_enforcer_decoding.py +70 -0
- vllm/model_executor/guided_decoding/outlines_decoding.py +130 -0
- vllm/model_executor/guided_decoding/outlines_logits_processors.py +184 -0
- vllm/model_executor/layers/__init__.py +0 -0
- vllm/model_executor/layers/activation.py +173 -0
- vllm/model_executor/layers/fused_moe/__init__.py +7 -0
- vllm/model_executor/layers/fused_moe/configs/E=16,N=1344,device_name=NVIDIA_A100-SXM4-40GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=16,N=1344,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=16,N=1344,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=16,N=2688,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=16,N=2688,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_A100-SXM4-40GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=1792,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=2048,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_A100-SXM4-40GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H100_80GB_HBM3,dtype=float8.json +140 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=3584,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=4096,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_A100-SXM4-80GB.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H100_80GB_HBM3,dtype=float8.json +146 -0
- vllm/model_executor/layers/fused_moe/configs/E=8,N=7168,device_name=NVIDIA_H100_80GB_HBM3.json +146 -0
- vllm/model_executor/layers/fused_moe/fused_moe.py +479 -0
- vllm/model_executor/layers/layernorm.py +71 -0
- vllm/model_executor/layers/linear.py +709 -0
- vllm/model_executor/layers/logits_processor.py +115 -0
- vllm/model_executor/layers/ops/__init__.py +0 -0
- vllm/model_executor/layers/ops/rand.py +157 -0
- vllm/model_executor/layers/ops/sample.py +406 -0
- vllm/model_executor/layers/quantization/__init__.py +35 -0
- vllm/model_executor/layers/quantization/aqlm.py +376 -0
- vllm/model_executor/layers/quantization/awq.py +175 -0
- vllm/model_executor/layers/quantization/base_config.py +97 -0
- vllm/model_executor/layers/quantization/fp8.py +265 -0
- vllm/model_executor/layers/quantization/gptq.py +224 -0
- vllm/model_executor/layers/quantization/gptq_marlin.py +438 -0
- vllm/model_executor/layers/quantization/marlin.py +227 -0
- vllm/model_executor/layers/quantization/schema.py +84 -0
- vllm/model_executor/layers/quantization/squeezellm.py +137 -0
- vllm/model_executor/layers/rejection_sampler.py +405 -0
- vllm/model_executor/layers/rotary_embedding.py +525 -0
- vllm/model_executor/layers/sampler.py +1051 -0
- vllm/model_executor/layers/vocab_parallel_embedding.py +155 -0
- vllm/model_executor/model_loader/__init__.py +30 -0
- vllm/model_executor/model_loader/loader.py +362 -0
- vllm/model_executor/model_loader/neuron.py +136 -0
- vllm/model_executor/model_loader/tensorizer.py +368 -0
- vllm/model_executor/model_loader/utils.py +41 -0
- vllm/model_executor/model_loader/weight_utils.py +372 -0
- vllm/model_executor/models/__init__.py +119 -0
- vllm/model_executor/models/baichuan.py +410 -0
- vllm/model_executor/models/bloom.py +327 -0
- vllm/model_executor/models/chatglm.py +386 -0
- vllm/model_executor/models/commandr.py +373 -0
- vllm/model_executor/models/dbrx.py +413 -0
- vllm/model_executor/models/decilm.py +122 -0
- vllm/model_executor/models/deepseek.py +438 -0
- vllm/model_executor/models/falcon.py +444 -0
- vllm/model_executor/models/gemma.py +393 -0
- vllm/model_executor/models/gpt2.py +266 -0
- vllm/model_executor/models/gpt_bigcode.py +274 -0
- vllm/model_executor/models/gpt_j.py +281 -0
- vllm/model_executor/models/gpt_neox.py +295 -0
- vllm/model_executor/models/internlm2.py +323 -0
- vllm/model_executor/models/jais.py +333 -0
- vllm/model_executor/models/llama.py +442 -0
- vllm/model_executor/models/llava.py +239 -0
- vllm/model_executor/models/minicpm.py +531 -0
- vllm/model_executor/models/mixtral.py +583 -0
- vllm/model_executor/models/mixtral_quant.py +404 -0
- vllm/model_executor/models/mpt.py +295 -0
- vllm/model_executor/models/olmo.py +356 -0
- vllm/model_executor/models/opt.py +349 -0
- vllm/model_executor/models/orion.py +319 -0
- vllm/model_executor/models/phi.py +300 -0
- vllm/model_executor/models/qwen.py +284 -0
- vllm/model_executor/models/qwen2.py +367 -0
- vllm/model_executor/models/qwen2_moe.py +447 -0
- vllm/model_executor/models/stablelm.py +301 -0
- vllm/model_executor/models/starcoder2.py +302 -0
- vllm/model_executor/models/xverse.py +366 -0
- vllm/model_executor/sampling_metadata.py +588 -0
- vllm/model_executor/utils.py +35 -0
- vllm/outputs.py +150 -0
- vllm/py.typed +2 -0
- vllm/sampling_params.py +340 -0
- vllm/sequence.py +766 -0
- vllm/spec_decode/__init__.py +0 -0
- vllm/spec_decode/batch_expansion.py +397 -0
- vllm/spec_decode/interfaces.py +73 -0
- vllm/spec_decode/metrics.py +191 -0
- vllm/spec_decode/multi_step_worker.py +203 -0
- vllm/spec_decode/ngram_worker.py +176 -0
- vllm/spec_decode/spec_decode_worker.py +472 -0
- vllm/spec_decode/top1_proposer.py +200 -0
- vllm/spec_decode/util.py +228 -0
- vllm/test_utils.py +41 -0
- vllm/transformers_utils/__init__.py +0 -0
- vllm/transformers_utils/config.py +58 -0
- vllm/transformers_utils/configs/__init__.py +16 -0
- vllm/transformers_utils/configs/chatglm.py +68 -0
- vllm/transformers_utils/configs/dbrx.py +278 -0
- vllm/transformers_utils/configs/falcon.py +87 -0
- vllm/transformers_utils/configs/jais.py +236 -0
- vllm/transformers_utils/configs/mpt.py +178 -0
- vllm/transformers_utils/detokenizer.py +313 -0
- vllm/transformers_utils/tokenizer.py +149 -0
- vllm/transformers_utils/tokenizer_group/__init__.py +33 -0
- vllm/transformers_utils/tokenizer_group/base_tokenizer_group.py +55 -0
- vllm/transformers_utils/tokenizer_group/ray_tokenizer_group.py +169 -0
- vllm/transformers_utils/tokenizer_group/tokenizer_group.py +78 -0
- vllm/transformers_utils/tokenizers/__init__.py +5 -0
- vllm/transformers_utils/tokenizers/baichuan.py +255 -0
- vllm/usage/__init__.py +0 -0
- vllm/usage/usage_lib.py +209 -0
- vllm/utils.py +677 -0
- vllm/worker/__init__.py +0 -0
- vllm/worker/cache_engine.py +105 -0
- vllm/worker/cpu_model_runner.py +346 -0
- vllm/worker/cpu_worker.py +321 -0
- vllm/worker/model_runner.py +1168 -0
- vllm/worker/neuron_model_runner.py +196 -0
- vllm/worker/neuron_worker.py +98 -0
- vllm/worker/worker.py +345 -0
- vllm/worker/worker_base.py +146 -0
- vllm_npu-0.4.2.dist-info/LICENSE +201 -0
- vllm_npu-0.4.2.dist-info/METADATA +173 -0
- vllm_npu-0.4.2.dist-info/RECORD +219 -0
- vllm_npu-0.4.2.dist-info/WHEEL +5 -0
- vllm_npu-0.4.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
# Copyright 2023 The vLLM team.
|
2
|
+
# Adapted from
|
3
|
+
# https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/core/tensor_parallel/utils.py
|
4
|
+
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
|
5
|
+
import json
|
6
|
+
import os
|
7
|
+
from typing import Dict, Optional, Sequence
|
8
|
+
|
9
|
+
import torch
|
10
|
+
import torch.distributed as dist
|
11
|
+
|
12
|
+
import vllm.envs as envs
|
13
|
+
from vllm.logger import init_logger
|
14
|
+
|
15
|
+
from .parallel_state import get_cpu_world_group, get_local_rank
|
16
|
+
|
17
|
+
logger = init_logger(__name__)
|
18
|
+
|
19
|
+
|
20
|
+
def ensure_divisibility(numerator, denominator):
|
21
|
+
"""Ensure that numerator is divisible by the denominator."""
|
22
|
+
assert numerator % denominator == 0, "{} is not divisible by {}".format(
|
23
|
+
numerator, denominator)
|
24
|
+
|
25
|
+
|
26
|
+
def divide(numerator, denominator):
|
27
|
+
"""Ensure that numerator is divisible by the denominator and return
|
28
|
+
the division value."""
|
29
|
+
ensure_divisibility(numerator, denominator)
|
30
|
+
return numerator // denominator
|
31
|
+
|
32
|
+
|
33
|
+
def split_tensor_along_last_dim(
|
34
|
+
tensor: torch.Tensor,
|
35
|
+
num_partitions: int,
|
36
|
+
contiguous_split_chunks: bool = False,
|
37
|
+
) -> Sequence[torch.Tensor]:
|
38
|
+
""" Split a tensor along its last dimension.
|
39
|
+
|
40
|
+
Arguments:
|
41
|
+
tensor: input tensor.
|
42
|
+
num_partitions: number of partitions to split the tensor
|
43
|
+
contiguous_split_chunks: If True, make each chunk contiguous
|
44
|
+
in memory.
|
45
|
+
|
46
|
+
Returns:
|
47
|
+
A list of Tensors
|
48
|
+
"""
|
49
|
+
# Get the size and dimension.
|
50
|
+
last_dim = tensor.dim() - 1
|
51
|
+
last_dim_size = divide(tensor.size()[last_dim], num_partitions)
|
52
|
+
# Split.
|
53
|
+
tensor_list = torch.split(tensor, last_dim_size, dim=last_dim)
|
54
|
+
# NOTE: torch.split does not create contiguous tensors by default.
|
55
|
+
if contiguous_split_chunks:
|
56
|
+
return tuple(chunk.contiguous() for chunk in tensor_list)
|
57
|
+
|
58
|
+
return tensor_list
|
59
|
+
|
60
|
+
|
61
|
+
# code partly borrowed from
|
62
|
+
# https://github.com/turboderp/exllamav2/blob/1c67f97f3d2a968605a9c31ab791a05c85bb7879/exllamav2/compat.py#L10
|
63
|
+
# License: MIT
|
64
|
+
def _can_actually_p2p(idx_a, idx_b):
|
65
|
+
dev_i = f"cuda:{idx_a}"
|
66
|
+
dev_j = f"cuda:{idx_b}"
|
67
|
+
a = torch.randn(5, device=dev_i) + 123.0
|
68
|
+
b = a.to(dev_j)
|
69
|
+
c = b.to(dev_i)
|
70
|
+
return torch.all(a == c).cpu().item()
|
71
|
+
|
72
|
+
|
73
|
+
# why do we need this cache?
|
74
|
+
# 1. we can have runtime checks for P2P access, where every process checks
|
75
|
+
# P2P access to all other GPUs. Unfortunately, the test might cost many
|
76
|
+
# (world_size * world_size) cuda context, and reduce the memory available
|
77
|
+
# for the model. see https://github.com/vllm-project/vllm/issues/3821
|
78
|
+
# 2. alternatively, we can have a p2p map that is generated by the master
|
79
|
+
# process and broadcasted to all other processes. This still requires
|
80
|
+
# #world_size of cuda context, belonging to the master process, on each GPU.
|
81
|
+
# 3. we can have a cache file, that records the p2p access status. The first
|
82
|
+
# time the master process checks the p2p access, it will generate the cache
|
83
|
+
# file, at the cost of #world_size of cuda context. Later on, all processes
|
84
|
+
# can read the cache file to check the p2p access status without any cost of
|
85
|
+
# additional cuda context.
|
86
|
+
# Note that the cache file is suffixed by the CUDA_VISIBLE_DEVICES, so that we
|
87
|
+
# can have different cache files for different CUDA_VISIBLE_DEVICES settings,
|
88
|
+
# e.g. used by different vllm engines. The device id in the cache file is a
|
89
|
+
# **local** device id, i.e. from 0 to num_dev-1, where num_dev is the number
|
90
|
+
# of visible devices in the vllm engine.
|
91
|
+
_gpu_p2p_access_cache: Optional[Dict[str, bool]] = None
|
92
|
+
|
93
|
+
|
94
|
+
def gpu_p2p_access_check(i: int, j: int) -> bool:
|
95
|
+
"""Check if GPU i can access GPU j."""
|
96
|
+
|
97
|
+
# if the cache variable is already calculated,
|
98
|
+
# read from the cache instead of checking it again
|
99
|
+
global _gpu_p2p_access_cache
|
100
|
+
if _gpu_p2p_access_cache is not None:
|
101
|
+
return _gpu_p2p_access_cache[f"{i}->{j}"]
|
102
|
+
|
103
|
+
is_distributed = dist.is_initialized()
|
104
|
+
|
105
|
+
num_dev = torch.cuda.device_count()
|
106
|
+
cuda_visible_devices = envs.CUDA_VISIBLE_DEVICES
|
107
|
+
if cuda_visible_devices is None:
|
108
|
+
cuda_visible_devices = ",".join(str(i) for i in range(num_dev))
|
109
|
+
VLLM_CONFIG_ROOT = envs.VLLM_CONFIG_ROOT
|
110
|
+
path = os.path.expanduser(
|
111
|
+
f"{VLLM_CONFIG_ROOT}/vllm/gpu_p2p_access_cache_for_{cuda_visible_devices}.json"
|
112
|
+
)
|
113
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
114
|
+
if (not is_distributed or get_local_rank() == 0) \
|
115
|
+
and (not os.path.exists(path)):
|
116
|
+
# only the local master process (with local_rank == 0) can
|
117
|
+
# enter this block to calculate the cache
|
118
|
+
logger.info("generating GPU P2P access cache for in %s", path)
|
119
|
+
cache = {}
|
120
|
+
for _i in range(num_dev):
|
121
|
+
for _j in range(num_dev):
|
122
|
+
# on some platforms, P2P support might be buggy and we need
|
123
|
+
# additional checks. See also:
|
124
|
+
# https://github.com/vllm-project/vllm/issues/2728
|
125
|
+
cache[f"{_i}->{_j}"] = torch.cuda.can_device_access_peer(
|
126
|
+
_i, _j) and _can_actually_p2p(_i, _j)
|
127
|
+
with open(path, "w") as f:
|
128
|
+
json.dump(cache, f, indent=4)
|
129
|
+
if is_distributed:
|
130
|
+
cpu_world_group = get_cpu_world_group()
|
131
|
+
dist.barrier(cpu_world_group)
|
132
|
+
logger.info("reading GPU P2P access cache from %s", path)
|
133
|
+
with open(path, "r") as f:
|
134
|
+
cache = json.load(f)
|
135
|
+
_gpu_p2p_access_cache = cache
|
136
|
+
return _gpu_p2p_access_cache[f"{i}->{j}"]
|
vllm/engine/__init__.py
ADDED
File without changes
|