(args, config, batch_size)
| 118 | |
| 119 | |
| 120 | def run_benchmark(args, config, batch_size): |
| 121 | launcher_config = ProcessConfig(device_isolation=True, device_isolation_action="warn", start_method="spawn") |
| 122 | scenario_config = InferenceConfig( |
| 123 | latency=True, |
| 124 | memory=True, |
| 125 | input_shapes={"batch_size": batch_size, "sequence_length": args.input_length}, |
| 126 | iterations=args.iterations, |
| 127 | warmup_runs=args.warmup_runs, |
| 128 | # set duration to 0 to disable the duration-based stopping criterion |
| 129 | # this is IMPORTANT to ensure that all benchmarks run the same number of operations, regardless of hardware speed/bottlenecks |
| 130 | duration=0, |
| 131 | # for consistent results, set a fixed min and max for output tokens |
| 132 | generate_kwargs={"min_new_tokens": args.output_length, "max_new_tokens": args.output_length}, |
| 133 | forward_kwargs={"min_new_tokens": args.output_length, "max_new_tokens": args.output_length}, |
| 134 | ) |
| 135 | |
| 136 | backend_config = PyTorchConfig( |
| 137 | device="cuda", |
| 138 | device_ids="0", |
| 139 | device_map="auto", |
| 140 | no_weights=False, |
| 141 | model=args.model_id, |
| 142 | **WEIGHTS_CONFIGS[config], |
| 143 | ) |
| 144 | |
| 145 | test_name = ( |
| 146 | f"benchmark-{config}" |
| 147 | f"-bsz-{batch_size}" |
| 148 | f"-isz-{args.input_length}" |
| 149 | f"-osz-{args.output_length}" |
| 150 | f"-iter-{args.iterations}" |
| 151 | f"-wrmup-{args.warmup_runs}" |
| 152 | ) |
| 153 | benchmark_config = BenchmarkConfig( |
| 154 | name=test_name, |
| 155 | scenario=scenario_config, |
| 156 | launcher=launcher_config, |
| 157 | backend=backend_config, |
| 158 | ) |
| 159 | |
| 160 | out_path = out_dir / (test_name + ".json") |
| 161 | print(f"[{test_name}] Starting:") |
| 162 | benchmark_report = Benchmark.launch(benchmark_config) |
| 163 | benchmark_report.save_json(out_path) |
| 164 | |
| 165 | |
| 166 | if __name__ == "__main__": |
no outgoing calls
no test coverage detected