TensorRT-LLMs/tests/integration/defs/examples/test_commandr.py
Omer Ullman Argov 8731f5f14f
chore: Mass integration of release/0.20 (#4898)
Signed-off-by: Ivy Zhang <25222398+crazydemo@users.noreply.github.com>
Signed-off-by: Yiqing Yan <yiqingy@nvidia.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Hui Gao <huig@nvidia.com>
Signed-off-by: Balaram Buddharaju <169953907+brb-nv@users.noreply.github.com>
Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
Signed-off-by: Bo Li <22713281+bobboli@users.noreply.github.com>
Signed-off-by: Iman Tabrizian <10105175+tabrizian@users.noreply.github.com>
Signed-off-by: Ruodi <200874449+ruodil@users.noreply.github.com>
Signed-off-by: ruodil <200874449+ruodil@users.noreply.github.com>
Signed-off-by: Stanley Sun <190317771+StanleySun639@users.noreply.github.com>
Signed-off-by: Pamela Peng <179191831+pamelap-nvidia@users.noreply.github.com>
Signed-off-by: Anurag Mukkara <134339030+amukkara@users.noreply.github.com>
Signed-off-by: xinhe-nv <200704525+xinhe-nv@users.noreply.github.com>
Signed-off-by: Faraz Khoubsirat <58580514+farazkh80@users.noreply.github.com>
Signed-off-by: moraxu <mguzek@nvidia.com>
Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Signed-off-by: yechank <161688079+yechank-nvidia@users.noreply.github.com>
Co-authored-by: Ivy Zhang <25222398+crazydemo@users.noreply.github.com>
Co-authored-by: Yiqing Yan <yiqingy@nvidia.com>
Co-authored-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Co-authored-by: HuiGao-NV <huig@nvidia.com>
Co-authored-by: brb-nv <169953907+brb-nv@users.noreply.github.com>
Co-authored-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
Co-authored-by: Bo Li <22713281+bobboli@users.noreply.github.com>
Co-authored-by: Iman Tabrizian <10105175+Tabrizian@users.noreply.github.com>
Co-authored-by: ruodil <200874449+ruodil@users.noreply.github.com>
Co-authored-by: Stanley Sun <190317771+StanleySun639@users.noreply.github.com>
Co-authored-by: Pamela Peng <179191831+pamelap-nvidia@users.noreply.github.com>
Co-authored-by: Anurag Mukkara <134339030+amukkara@users.noreply.github.com>
Co-authored-by: xinhe-nv <200704525+xinhe-nv@users.noreply.github.com>
Co-authored-by: Faraz <58580514+farazkh80@users.noreply.github.com>
Co-authored-by: Michal Guzek <moraxu@users.noreply.github.com>
Co-authored-by: Larry <197874197+LarryXFly@users.noreply.github.com>
Co-authored-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
Co-authored-by: Yechan Kim <161688079+yechank-nvidia@users.noreply.github.com>
2025-06-08 23:26:26 +08:00

141 lines
5.4 KiB
Python

# SPDX-FileCopyrightText: Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module test_commandr test commandr examples."""
import os
import pytest
from defs.common import (convert_weights, generate_summary_cmd, venv_check_call,
venv_mpi_check_call)
from defs.conftest import get_gpu_device_list
from defs.trt_test_alternative import check_call
@pytest.mark.skip_less_device_memory(80000)
@pytest.mark.parametrize("use_weight_only", [True, False],
ids=["enable_weight_only", "disable_weight_only"])
def test_llm_commandr_v01_single_gpu_summary(commandr_example_root,
llm_commandr_v01_model_root,
llm_datasets_root, llm_rouge_root,
llm_venv, cmodel_dir, engine_dir,
use_weight_only):
"Build & run commandr_v01 on single gpu."
if "GH200" in get_gpu_device_list()[0] and not use_weight_only:
pytest.skip("OOM on GH200. https://nvbugs/5250460")
print("Converting checkpoint...")
dtype = 'float16'
model_name = os.path.basename(llm_commandr_v01_model_root)
ckpt_dir = convert_weights(llm_venv=llm_venv,
example_root=commandr_example_root,
cmodel_dir=cmodel_dir,
model=model_name,
model_path=llm_commandr_v01_model_root,
data_type=dtype,
use_weight_only=use_weight_only)
print("Building engines...")
build_cmd = [
"trtllm-build",
f"--checkpoint_dir={ckpt_dir}",
f"--output_dir={engine_dir}",
f"--max_batch_size={8}",
f"--max_input_len={924}",
f"--max_seq_len={1024}",
f"--gemm_plugin={dtype}",
f"--gpt_attention_plugin={dtype}",
]
check_call(" ".join(build_cmd), shell=True, env=llm_venv._new_env)
summary_cmd = [
f"{commandr_example_root}/../../../summarize.py",
"--test_trt_llm",
"--hf_model_dir",
f"{llm_commandr_v01_model_root}",
"--data_type",
"fp16",
"--check_accuracy",
f"--engine_dir={engine_dir}",
"--tensorrt_llm_rouge1_threshold=12",
f"--dataset_dir={llm_datasets_root}",
f"--rouge_dir={llm_rouge_root}",
]
venv_check_call(llm_venv, summary_cmd)
@pytest.mark.skip_less_device(4)
@pytest.mark.skip_less_device_memory(80000)
@pytest.mark.skip_less_host_memory(1000000)
@pytest.mark.parametrize("use_weight_only", [True, False],
ids=["enable_weight_only", "disable_weight_only"])
def test_llm_commandr_plus_4gpus_summary(commandr_example_root,
llm_commandr_plus_model_root,
llm_datasets_root, llm_rouge_root,
llm_venv, cmodel_dir, engine_dir,
use_weight_only):
"Build & run Command-R+ with smoothquant on 4 gpus."
dtype = 'float16'
tp_size = 4
model_name = os.path.basename(llm_commandr_plus_model_root)
print("Converting checkpoint...")
ckpt_dir = convert_weights(llm_venv=llm_venv,
example_root=commandr_example_root,
cmodel_dir=cmodel_dir,
model=model_name,
model_path=llm_commandr_plus_model_root,
data_type=dtype,
tp_size=tp_size,
gpus=tp_size,
use_weight_only=use_weight_only)
print("Building engines...")
build_cmd = [
"trtllm-build",
f"--checkpoint_dir={ckpt_dir}",
f"--output_dir={engine_dir}",
f"--max_batch_size={8}",
f"--max_input_len={924}",
f"--max_seq_len={1024}",
f"--max_beam_width={4}",
f"--gemm_plugin={dtype}",
f"--gpt_attention_plugin={dtype}",
]
run_cmd = [
f"{commandr_example_root}/../../../run.py",
f"--max_output_len={50}",
f"--tokenizer_dir={llm_commandr_plus_model_root}",
f"--engine_dir={engine_dir}",
]
check_call(" ".join(build_cmd), shell=True, env=llm_venv._new_env)
venv_mpi_check_call(
llm_venv,
["mpirun", "-n", str(tp_size), "--allow-run-as-root"], run_cmd)
summary_cmd = generate_summary_cmd(
commandr_example_root,
hf_model_dir=llm_commandr_plus_model_root,
data_type="fp16",
engine_dir=engine_dir,
dataset_dir=llm_datasets_root,
rouge_dir=llm_rouge_root)
venv_mpi_check_call(
llm_venv,
["mpirun", "-n", str(tp_size), "--allow-run-as-root"], summary_cmd)