From bbf62c7dac9d203b94a3d7c96b3d5d6d40c1ff2b Mon Sep 17 00:00:00 2001 From: hvaria Date: Fri, 15 Mar 2024 01:00:28 -0700 Subject: [PATCH] Fix for Bug #313: Ensure Graceful Interruption of Benchmark Process This pull request addresses bug #313, where users were unable to interrupt the benchmarking process using Ctrl+C, leading to a scenario where the benchmark would continue running indefinitely, ignoring interruption requests. The core of the issue was the absence of a proper signal handling mechanism for keyboard interrupts during the execution of the benchmarking commands. Added a try-except block around the benchmarking execution commands in benchmark.py. This ensures that a KeyboardInterrupt (e.g., through Ctrl+C) is caught, and a graceful shutdown sequence can be initiated. Upon catching a KeyboardInterrupt, the script now calls stop_inference_containers() from container_adapter.py. This function halts all running inference containers, ensuring that no orphaned resources are left consuming system resources post-interruption. Enhanced stop_inference_containers() to handle both interactive and automated environments gracefully. --- inference_cli/benchmark.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/inference_cli/benchmark.py b/inference_cli/benchmark.py index 8bb23e122..b321be4c9 100644 --- a/inference_cli/benchmark.py +++ b/inference_cli/benchmark.py @@ -182,16 +182,23 @@ def python_package_speed( ), ] = None, ): - run_python_package_speed_benchmark( - model_id=model_id, - dataset_reference=dataset_reference, - warm_up_inferences=warm_up_inferences, - benchmark_inferences=benchmark_inferences, - batch_size=batch_size, - api_key=api_key, - model_configuration=model_configuration, - output_location=output_location, - ) + try: + run_python_package_speed_benchmark( + model_id=model_id, + dataset_reference=dataset_reference, + warm_up_inferences=warm_up_inferences, + benchmark_inferences=benchmark_inferences, + batch_size=batch_size, + api_key=api_key, + model_configuration=model_configuration, + output_location=output_location, + ) + except KeyboardInterrupt: + print("Benchmark interrupted. Cleaning up...") + stop_inference_containers() + print("Cleanup completed. Exiting.") + return + if __name__ == "__main__":