TensorRT-LLMs/cpp/tests/resources/scripts/generate_expected_eagle_output.py
石晓伟 548b5b7310
Update TensorRT-LLM (#2532)
* blossom-ci.yml: run vulnerability scan on blossom

* open source efb18c1256f8c9c3d47b7d0c740b83e5d5ebe0ec

---------

Co-authored-by: niukuo <6831097+niukuo@users.noreply.github.com>
Co-authored-by: pei0033 <59505847+pei0033@users.noreply.github.com>
Co-authored-by: Kyungmin Lee <30465912+lkm2835@users.noreply.github.com>
Co-authored-by: Kaiyu Xie <26294424+kaiyux@users.noreply.github.com>
2024-12-04 21:16:56 +08:00

90 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python3
# 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.
import argparse as _arg
from pathlib import Path
import run
from build_engines_utils import init_model_spec_module
init_model_spec_module()
import os
import model_spec
import tensorrt_llm.bindings as _tb
def generate_output(engine: str,
model_spec_obj: model_spec.ModelSpec,
max_output_len: int = 8):
model = 'vicuna-7b-v1.3'
model_eagle = 'vicuna-7b-eagle'
hf_model = 'vicuna-7b-v1.3'
resources_dir = Path(__file__).parent.resolve().parent
models_dir = resources_dir / 'models'
hf_dir = models_dir / hf_model
tp_pp_cp_dir = 'tp1-pp1-cp1-gpu/'
engine_dir = models_dir / 'rt_engine' / model / engine / tp_pp_cp_dir
data_dir = resources_dir / 'data'
input_file = data_dir / 'input_vicuna.npy'
model_data_dir = data_dir / model_eagle
output_dir = model_data_dir / 'sampling'
base_output_name = os.path.splitext(model_spec_obj.get_results_file())[0]
args = run.parse_arguments([
'--engine_dir',
str(engine_dir), '--input_file',
str(input_file), '--tokenizer_dir',
str(hf_dir), '--output_npy',
str(output_dir / (base_output_name + '.npy')), '--output_csv',
str(output_dir / (base_output_name + '.csv')), '--max_output_len',
str(max_output_len), '--use_py_session', '--temperature', '1.0'
])
run.main(args)
print(f"Output saved at {str(output_dir / base_output_name)}.[npy|csv]")
def generate_outputs():
print(f'Generating outputs for Vicuna 7B v1.3 FP16')
max_output_len = 128
model_spec_obj = model_spec.ModelSpec('input_tokens_long.npy',
_tb.DataType.HALF)
model_spec_obj.use_gpt_plugin()
model_spec_obj.set_max_output_length(max_output_len)
model_spec_obj.use_packed_input()
model_spec_obj.set_kv_cache_type(_tb.KVCacheType.PAGED)
generate_output(engine=model_spec_obj.get_model_path(),
model_spec_obj=model_spec_obj,
max_output_len=max_output_len)
if __name__ == '__main__':
parser = _arg.ArgumentParser()
parser.add_argument(
"--only_multi_gpu",
action="store_true",
help="Generate data with Pipeline and Tensor Parallelism")
args = parser.parse_args()
generate_outputs()
print("Done")