Run a latency test on a TRT-LLM engine.
(
bench_env: BenchmarkEnvironment,
**params,
)
| 188 | ) |
| 189 | @click.pass_obj |
| 190 | def latency_command( |
| 191 | bench_env: BenchmarkEnvironment, |
| 192 | **params, |
| 193 | ) -> None: |
| 194 | """Run a latency test on a TRT-LLM engine.""" |
| 195 | logger.info("Preparing to run latency benchmark...") |
| 196 | |
| 197 | # Parameters from CLI |
| 198 | # Model, experiment, and engine params |
| 199 | options = get_general_cli_options(params, bench_env) |
| 200 | |
| 201 | # Speculative Decode Options |
| 202 | medusa_choices = params.get("medusa_choices") |
| 203 | # Initialize the HF tokenizer for the specified model. |
| 204 | tokenizer = initialize_tokenizer(options.checkpoint_path) |
| 205 | |
| 206 | # Dataset Loading and Preparation |
| 207 | with open(options.dataset_path, "r") as dataset: |
| 208 | metadata, requests = create_dataset_from_stream( |
| 209 | tokenizer, |
| 210 | dataset, |
| 211 | num_requests=options.num_requests, |
| 212 | model_dir=options.checkpoint_path, |
| 213 | model_type=options.model_type, |
| 214 | modality=options.modality, |
| 215 | max_input_seq_len_for_multimodal=options.max_input_len) |
| 216 | |
| 217 | metadata.dataset_path = options.dataset_path |
| 218 | |
| 219 | if options.modality is None: |
| 220 | # Log dataset info |
| 221 | # NOTE: This table is only accurate for non-multimodal models. |
| 222 | # The accurate table for multimodal models will be logged after the benchmark is done. |
| 223 | logger.info(metadata.get_summary_for_print()) |
| 224 | |
| 225 | # Engine configuration parsing for PyTorch backend |
| 226 | kwargs = {} |
| 227 | if options.backend and options.backend.lower( |
| 228 | ) in ALL_SUPPORTED_BACKENDS and options.backend.lower() != "tensorrt": |
| 229 | if bench_env.checkpoint_path is None: |
| 230 | snapshot_download(options.model, revision=bench_env.revision) |
| 231 | |
| 232 | exec_settings = get_settings(params, metadata, bench_env.model, |
| 233 | bench_env.checkpoint_path) |
| 234 | kwargs_max_sql = options.max_seq_len or metadata.max_sequence_length |
| 235 | logger.info(f"Setting PyTorch max sequence length to {kwargs_max_sql}") |
| 236 | kwargs["max_seq_len"] = kwargs_max_sql |
| 237 | elif options.backend.lower() == "tensorrt": |
| 238 | assert options.max_seq_len is None, ( |
| 239 | "max_seq_len is not a runtime parameter for C++ backend") |
| 240 | exec_settings, build_cfg = get_settings_from_engine(options.engine_dir) |
| 241 | engine_max_seq_len = build_cfg["max_seq_len"] |
| 242 | |
| 243 | if metadata.max_sequence_length > engine_max_seq_len: |
| 244 | raise RuntimeError( |
| 245 | f"Engine supports a max sequence of {engine_max_seq_len}. Provided " |
| 246 | "dataset contains a maximum sequence of " |
| 247 | f"{metadata.max_sequence_length}. Please rebuild a new engine to" |
nothing calls this directly
no test coverage detected