Add measured collective profile gate for Qwen235
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Profile vLLM 0.20 TP all-reduce and assert FlashInfer TRTLLM dispatch."""
|
||||
"""Profile the vLLM 0.20 TP all-reduce path under a frozen runtime contract."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -27,8 +27,14 @@ def parse_args() -> argparse.Namespace:
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
parser.add_argument("--num-tokens", type=int, nargs="+", default=[8])
|
||||
parser.add_argument("--hidden-dim", type=int, default=2048)
|
||||
parser.add_argument(
|
||||
"--collective-contract",
|
||||
choices=("flashinfer-trtllm", "qwen235-serving-projected"),
|
||||
default="flashinfer-trtllm",
|
||||
)
|
||||
parser.add_argument("--warmup-iters", type=int, default=3)
|
||||
parser.add_argument("--repeats", type=int, default=10)
|
||||
parser.add_argument("--trials", type=int, default=1)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -55,10 +61,19 @@ def main() -> None:
|
||||
source_head = git_head(args.vllm_source)
|
||||
if source_head != VLLM_COMMIT:
|
||||
raise SystemExit(f"expected vLLM source {VLLM_COMMIT}, got {source_head}")
|
||||
if args.repeats <= 0 or args.trials <= 0 or args.warmup_iters < 0:
|
||||
raise SystemExit("warmup/repeats/trials must be non-negative/positive")
|
||||
if os.getenv("VLLM_ALLREDUCE_USE_FLASHINFER") != "1":
|
||||
raise SystemExit("VLLM_ALLREDUCE_USE_FLASHINFER must equal 1")
|
||||
if os.getenv("VLLM_FLASHINFER_ALLREDUCE_BACKEND") != "trtllm":
|
||||
raise SystemExit("VLLM_FLASHINFER_ALLREDUCE_BACKEND must equal trtllm")
|
||||
expected_symm_mem = (
|
||||
"1" if args.collective_contract == "qwen235-serving-projected" else "0"
|
||||
)
|
||||
if os.getenv("VLLM_ALLREDUCE_USE_SYMM_MEM") != expected_symm_mem:
|
||||
raise SystemExit(
|
||||
f"VLLM_ALLREDUCE_USE_SYMM_MEM must equal {expected_symm_mem}"
|
||||
)
|
||||
if "RANK" not in os.environ or "WORLD_SIZE" not in os.environ:
|
||||
raise SystemExit("launch with torchrun")
|
||||
|
||||
@@ -67,6 +82,7 @@ def main() -> None:
|
||||
destroy_model_parallel,
|
||||
init_distributed_environment,
|
||||
initialize_model_parallel,
|
||||
set_custom_all_reduce,
|
||||
tensor_model_parallel_all_reduce,
|
||||
)
|
||||
from vllm.distributed.parallel_state import get_tp_group
|
||||
@@ -80,11 +96,15 @@ def main() -> None:
|
||||
rank = int(os.environ["RANK"])
|
||||
local_rank = int(os.environ["LOCAL_RANK"])
|
||||
world_size = int(os.environ["WORLD_SIZE"])
|
||||
if world_size not in (2, 4):
|
||||
raise SystemExit(f"expected TP world size 2 or 4, got {world_size}")
|
||||
if world_size not in (2, 4, 8):
|
||||
raise SystemExit(f"expected TP world size 2, 4, or 8, got {world_size}")
|
||||
device = torch.device(f"cuda:{local_rank}")
|
||||
torch.accelerator.set_device_index(device)
|
||||
torch.set_default_device(device)
|
||||
disable_custom_all_reduce = (
|
||||
args.collective_contract == "qwen235-serving-projected"
|
||||
)
|
||||
set_custom_all_reduce(not disable_custom_all_reduce)
|
||||
init_distributed_environment()
|
||||
model_config = ModelConfig(
|
||||
model=str(args.model),
|
||||
@@ -95,11 +115,80 @@ def main() -> None:
|
||||
)
|
||||
vllm_config = VllmConfig(
|
||||
model_config=model_config,
|
||||
parallel_config=ParallelConfig(tensor_parallel_size=world_size)
|
||||
parallel_config=ParallelConfig(
|
||||
tensor_parallel_size=world_size,
|
||||
disable_custom_all_reduce=disable_custom_all_reduce,
|
||||
)
|
||||
)
|
||||
with set_current_vllm_config(vllm_config):
|
||||
initialize_model_parallel(tensor_model_parallel_size=world_size)
|
||||
|
||||
from vllm.distributed.device_communicators.all_reduce_utils import (
|
||||
should_nccl_symm_mem_allreduce,
|
||||
)
|
||||
|
||||
def resolve_profile_operation(input_tensor: torch.Tensor):
|
||||
communicator = get_tp_group().device_communicator
|
||||
if args.collective_contract == "qwen235-serving-projected":
|
||||
from vllm.compilation.passes.fusion.allreduce_rms_fusion import (
|
||||
FI_ALLREDUCE_FUSION_MAX_SIZE_MB,
|
||||
)
|
||||
|
||||
major, minor = torch.cuda.get_device_capability(device)
|
||||
capability = major * 10 + minor
|
||||
try:
|
||||
fusion_limit_bytes = int(
|
||||
FI_ALLREDUCE_FUSION_MAX_SIZE_MB[capability][world_size]
|
||||
* 1024
|
||||
* 1024
|
||||
)
|
||||
except KeyError as error:
|
||||
raise SystemExit(
|
||||
f"no FlashInfer fusion limit for SM{capability}, TP{world_size}"
|
||||
) from error
|
||||
if input_tensor.nbytes <= fusion_limit_bytes:
|
||||
fi_comm = communicator.fi_ar_comm
|
||||
if fi_comm is None or fi_comm.disabled:
|
||||
raise SystemExit("FlashInfer all-reduce communicator is unavailable")
|
||||
if not fi_comm.should_use_fi_ar(input_tensor):
|
||||
raise SystemExit("FlashInfer rejected a fusion-eligible payload")
|
||||
return (
|
||||
"flashinfer_trtllm_fused_projection",
|
||||
fi_comm.all_reduce,
|
||||
fusion_limit_bytes,
|
||||
)
|
||||
if (
|
||||
communicator.pynccl_comm is not None
|
||||
and should_nccl_symm_mem_allreduce(world_size, input_tensor)
|
||||
):
|
||||
return (
|
||||
"pynccl_symmetric_with_copy",
|
||||
torch.ops.vllm.all_reduce_symmetric_with_copy,
|
||||
fusion_limit_bytes,
|
||||
)
|
||||
if (
|
||||
communicator.symm_mem_comm is not None
|
||||
and communicator.symm_mem_comm.should_use_symm_mem(input_tensor)
|
||||
):
|
||||
return (
|
||||
"torch_symmetric_memory",
|
||||
communicator.symm_mem_comm.all_reduce,
|
||||
fusion_limit_bytes,
|
||||
)
|
||||
if communicator.pynccl_comm is not None:
|
||||
return "pynccl", communicator.pynccl_comm.all_reduce, fusion_limit_bytes
|
||||
return "torch_distributed", tensor_model_parallel_all_reduce, fusion_limit_bytes
|
||||
|
||||
fi_comm = communicator.fi_ar_comm
|
||||
selected_backend = (
|
||||
"flashinfer_trtllm"
|
||||
if fi_comm is not None
|
||||
and not fi_comm.disabled
|
||||
and fi_comm.should_use_fi_ar(input_tensor)
|
||||
else "non_flashinfer_fallback"
|
||||
)
|
||||
return selected_backend, tensor_model_parallel_all_reduce, None
|
||||
|
||||
rows: list[dict[str, Any]] = []
|
||||
expected_sum = world_size * (world_size + 1) / 2
|
||||
try:
|
||||
@@ -110,8 +199,11 @@ def main() -> None:
|
||||
dtype=torch.bfloat16,
|
||||
device=device,
|
||||
)
|
||||
selected_backend, profile_operation, fusion_limit_bytes = (
|
||||
resolve_profile_operation(input_tensor)
|
||||
)
|
||||
for _ in range(args.warmup_iters):
|
||||
output = tensor_model_parallel_all_reduce(input_tensor)
|
||||
output = profile_operation(input_tensor)
|
||||
torch.accelerator.synchronize()
|
||||
torch.testing.assert_close(
|
||||
output,
|
||||
@@ -120,30 +212,55 @@ def main() -> None:
|
||||
rtol=0.0,
|
||||
)
|
||||
|
||||
communicator = get_tp_group().device_communicator
|
||||
fi_comm = communicator.fi_ar_comm
|
||||
if fi_comm is None or fi_comm.disabled:
|
||||
if args.collective_contract == "flashinfer-trtllm":
|
||||
if selected_backend != "flashinfer_trtllm":
|
||||
raise SystemExit(
|
||||
f"expected FlashInfer TRTLLM, got {selected_backend} at "
|
||||
f"TP={world_size}, tokens={num_tokens}"
|
||||
)
|
||||
elif selected_backend not in {
|
||||
"flashinfer_trtllm_fused_projection",
|
||||
"pynccl_symmetric_with_copy",
|
||||
"torch_symmetric_memory",
|
||||
"pynccl",
|
||||
}:
|
||||
raise SystemExit(
|
||||
f"FlashInfer all-reduce was not selected at TP={world_size}, "
|
||||
f"tokens={num_tokens}"
|
||||
f"unexpected Qwen235 serving backend: {selected_backend}"
|
||||
)
|
||||
uses_flashinfer = fi_comm.should_use_fi_ar(input_tensor)
|
||||
|
||||
samples: list[float] = []
|
||||
for _ in range(args.repeats):
|
||||
dist.barrier()
|
||||
start = torch.cuda.Event(enable_timing=True)
|
||||
end = torch.cuda.Event(enable_timing=True)
|
||||
start.record()
|
||||
output = tensor_model_parallel_all_reduce(input_tensor)
|
||||
end.record()
|
||||
torch.accelerator.synchronize()
|
||||
samples.append(float(start.elapsed_time(end)))
|
||||
all_trial_rank_samples: list[list[list[float]]] = []
|
||||
critical_path_samples: list[float] = []
|
||||
for _ in range(args.trials):
|
||||
samples: list[float] = []
|
||||
for _ in range(args.repeats):
|
||||
dist.barrier()
|
||||
start = torch.cuda.Event(enable_timing=True)
|
||||
end = torch.cuda.Event(enable_timing=True)
|
||||
start.record()
|
||||
output = profile_operation(input_tensor)
|
||||
end.record()
|
||||
torch.accelerator.synchronize()
|
||||
samples.append(float(start.elapsed_time(end)))
|
||||
|
||||
gathered: list[list[float] | None] = [None] * world_size
|
||||
dist.all_gather_object(gathered, samples)
|
||||
gathered: list[list[float] | None] = [None] * world_size
|
||||
dist.all_gather_object(gathered, samples)
|
||||
if rank == 0:
|
||||
rank_samples = [item for item in gathered if item is not None]
|
||||
all_trial_rank_samples.append(rank_samples)
|
||||
critical_path_samples.extend(
|
||||
max(per_rank[index] for per_rank in rank_samples)
|
||||
for index in range(args.repeats)
|
||||
)
|
||||
if rank == 0:
|
||||
per_rank = [stats_ms(item) for item in gathered if item is not None]
|
||||
flattened_by_rank = [
|
||||
[
|
||||
sample
|
||||
for trial in all_trial_rank_samples
|
||||
for sample in trial[rank_index]
|
||||
]
|
||||
for rank_index in range(world_size)
|
||||
]
|
||||
per_rank = [stats_ms(samples) for samples in flattened_by_rank]
|
||||
row = {
|
||||
"tensor_parallel_size": world_size,
|
||||
"num_tokens": num_tokens,
|
||||
@@ -153,12 +270,16 @@ def main() -> None:
|
||||
* torch.tensor([], dtype=torch.bfloat16).element_size(),
|
||||
"dtype": "bfloat16",
|
||||
"communicator": "vllm.tensor_model_parallel_all_reduce",
|
||||
"selected_backend": (
|
||||
"flashinfer_trtllm" if uses_flashinfer else "nccl_fallback"
|
||||
),
|
||||
"collective_contract": args.collective_contract,
|
||||
"selected_backend": selected_backend,
|
||||
"real_fusion_limit_bytes": fusion_limit_bytes,
|
||||
"trials": args.trials,
|
||||
"repeats_per_trial": args.repeats,
|
||||
"per_trial_rank_samples_ms": all_trial_rank_samples,
|
||||
"per_rank_time_ms": per_rank,
|
||||
"critical_path_median_ms": max(
|
||||
rank_stats["median"] for rank_stats in per_rank
|
||||
"critical_path_time_ms": stats_ms(critical_path_samples),
|
||||
"critical_path_median_ms": statistics.median(
|
||||
critical_path_samples
|
||||
),
|
||||
}
|
||||
rows.append(row)
|
||||
@@ -169,7 +290,11 @@ def main() -> None:
|
||||
|
||||
if rank == 0:
|
||||
payload = {
|
||||
"schema_version": "qwen30_vllm020_allreduce_raw.v1",
|
||||
"schema_version": (
|
||||
"qwen30_vllm020_allreduce_raw.v1"
|
||||
if args.collective_contract == "flashinfer-trtllm"
|
||||
else "vllm020_allreduce_raw.v2"
|
||||
),
|
||||
"environment": {
|
||||
"vllm_version": vllm.__version__,
|
||||
"vllm_source_commit": source_head,
|
||||
@@ -178,9 +303,18 @@ def main() -> None:
|
||||
"gpu": torch.cuda.get_device_name(device),
|
||||
"model": str(args.model),
|
||||
"backend_env": {
|
||||
"VLLM_ALLREDUCE_USE_FLASHINFER": "1",
|
||||
"VLLM_FLASHINFER_ALLREDUCE_BACKEND": "trtllm",
|
||||
"VLLM_ALLREDUCE_USE_FLASHINFER": os.getenv(
|
||||
"VLLM_ALLREDUCE_USE_FLASHINFER", "0"
|
||||
),
|
||||
"VLLM_FLASHINFER_ALLREDUCE_BACKEND": os.getenv(
|
||||
"VLLM_FLASHINFER_ALLREDUCE_BACKEND"
|
||||
),
|
||||
"VLLM_ALLREDUCE_USE_SYMM_MEM": os.getenv(
|
||||
"VLLM_ALLREDUCE_USE_SYMM_MEM", "1"
|
||||
),
|
||||
},
|
||||
"collective_contract": args.collective_contract,
|
||||
"disable_custom_all_reduce": disable_custom_all_reduce,
|
||||
},
|
||||
"rows": rows,
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
TP="${TP:?TP must be set to 2 or 4}"
|
||||
TP="${TP:?TP must be set to 2, 4, or 8}"
|
||||
case "${TP}" in
|
||||
2) HARD_GPU_CAP="0.40_H20h" ;;
|
||||
4) HARD_GPU_CAP="0.80_H20h" ;;
|
||||
8) HARD_GPU_CAP="1.60_H20h" ;;
|
||||
*) echo "ERROR: invalid TP=${TP}" >&2; exit 1 ;;
|
||||
esac
|
||||
OUTPUT_ROOT="${OUTPUT_ROOT:?OUTPUT_ROOT must be set}"
|
||||
@@ -13,6 +14,10 @@ VENV_ROOT="${VENV_ROOT:-/tmp/wjh/venvs/vllm-0.20.0-cu129-profiler-v1}"
|
||||
VLLM_SOURCE="${VLLM_SOURCE:-/home/admin/cpfs/wjh/agentic-kv/third_party/vllm_v20_build}"
|
||||
MODEL="${MODEL:-/home/admin/cpfs/wjh/models/Qwen/Qwen3-30B-A3B}"
|
||||
NUM_TOKENS="${NUM_TOKENS:-8}"
|
||||
HIDDEN_DIM="${HIDDEN_DIM:-2048}"
|
||||
COLLECTIVE_CONTRACT="${COLLECTIVE_CONTRACT:-flashinfer-trtllm}"
|
||||
TRIALS="${TRIALS:-1}"
|
||||
REPEATS="${REPEATS:-10}"
|
||||
mkdir -p "${OUTPUT_ROOT}/logs" "${OUTPUT_ROOT}/provenance" "${OUTPUT_ROOT}/raw"
|
||||
exec > >(tee -a "${OUTPUT_ROOT}/logs/profile.log") 2>&1
|
||||
|
||||
@@ -22,9 +27,20 @@ if [[ "${#GPU_IDS[@]}" -ne "${TP}" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export VLLM_ALLREDUCE_USE_FLASHINFER=1
|
||||
export VLLM_FLASHINFER_ALLREDUCE_BACKEND=trtllm
|
||||
echo "PROFILE_LAUNCH_ECHO host=$(hostname) gpus=${CUDA_VISIBLE_DEVICES} model=${MODEL} runtime=vLLM-0.20.0+cu129 operator=tensor_model_parallel_all_reduce backend=FlashInfer-TRTLLM tp=${TP} tokens=${NUM_TOKENS} hidden=2048 dtype=BF16 output=${OUTPUT_ROOT} expected_wall=2-6m hard_wall=720s hard_gpu_cap=${HARD_GPU_CAP}"
|
||||
case "${COLLECTIVE_CONTRACT}" in
|
||||
flashinfer-trtllm)
|
||||
export VLLM_ALLREDUCE_USE_FLASHINFER=1
|
||||
export VLLM_FLASHINFER_ALLREDUCE_BACKEND=trtllm
|
||||
export VLLM_ALLREDUCE_USE_SYMM_MEM=0
|
||||
;;
|
||||
qwen235-serving-projected)
|
||||
export VLLM_ALLREDUCE_USE_FLASHINFER=1
|
||||
export VLLM_FLASHINFER_ALLREDUCE_BACKEND=trtllm
|
||||
export VLLM_ALLREDUCE_USE_SYMM_MEM=1
|
||||
;;
|
||||
*) echo "ERROR: invalid COLLECTIVE_CONTRACT=${COLLECTIVE_CONTRACT}" >&2; exit 1 ;;
|
||||
esac
|
||||
echo "PROFILE_LAUNCH_ECHO host=$(hostname) gpus=${CUDA_VISIBLE_DEVICES} model=${MODEL} runtime=vLLM-0.20.0+cu129 operator=tensor_model_parallel_all_reduce contract=${COLLECTIVE_CONTRACT} tp=${TP} tokens=${NUM_TOKENS} hidden=${HIDDEN_DIM} dtype=BF16 trials=${TRIALS} repeats=${REPEATS} output=${OUTPUT_ROOT} expected_wall=2-8m hard_wall=720s hard_gpu_cap=${HARD_GPU_CAP}"
|
||||
date -u +"START_UTC=%Y-%m-%dT%H:%M:%SZ"
|
||||
nvidia-smi --query-gpu=index,name,driver_version,memory.used,utilization.gpu --format=csv,noheader
|
||||
|
||||
@@ -46,8 +62,11 @@ timeout --signal=TERM --kill-after=30s 600 \
|
||||
--model "${MODEL}" \
|
||||
--output "${OUTPUT_ROOT}/raw/allreduce-tp${TP}.json" \
|
||||
--num-tokens "${TOKEN_ARGS[@]}" \
|
||||
--hidden-dim "${HIDDEN_DIM}" \
|
||||
--collective-contract "${COLLECTIVE_CONTRACT}" \
|
||||
--warmup-iters 3 \
|
||||
--repeats 10
|
||||
--repeats "${REPEATS}" \
|
||||
--trials "${TRIALS}"
|
||||
|
||||
test -s "${OUTPUT_ROOT}/raw/allreduce-tp${TP}.json"
|
||||
sha256sum "${OUTPUT_ROOT}/raw/allreduce-tp${TP}.json" \
|
||||
|
||||
Reference in New Issue
Block a user