From 4e346c0322127b8bd99fdbf8f255e9919c638036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Monnom?= Date: Sat, 3 Aug 2024 03:20:54 +0200 Subject: [PATCH] silero: fix high cpu usage (#569) --- .changeset/red-numbers-complain.md | 5 +++++ .../livekit/plugins/silero/onnx_model.py | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/red-numbers-complain.md diff --git a/.changeset/red-numbers-complain.md b/.changeset/red-numbers-complain.md new file mode 100644 index 000000000..d5675a6bc --- /dev/null +++ b/.changeset/red-numbers-complain.md @@ -0,0 +1,5 @@ +--- +"livekit-plugins-silero": patch +--- + +silero: fix high cpu usage diff --git a/livekit-plugins/livekit-plugins-silero/livekit/plugins/silero/onnx_model.py b/livekit-plugins/livekit-plugins-silero/livekit/plugins/silero/onnx_model.py index b0f24e564..a67b659a3 100644 --- a/livekit-plugins/livekit-plugins-silero/livekit/plugins/silero/onnx_model.py +++ b/livekit-plugins/livekit-plugins-silero/livekit/plugins/silero/onnx_model.py @@ -21,13 +21,15 @@ def new_inference_session(force_cpu: bool) -> onnxruntime.InferenceSession: path = str(_resource_files.enter_context(ctx)) opts = onnxruntime.SessionOptions() + opts.add_session_config_entry("session.intra_op.allow_spinning", "0") + opts.add_session_config_entry("session.inter_op.allow_spinning", "0") opts.inter_op_num_threads = 1 opts.intra_op_num_threads = 1 - opts.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_ALL + opts.execution_mode = onnxruntime.ExecutionMode.ORT_SEQUENTIAL if force_cpu and "CPUExecutionProvider" in onnxruntime.get_available_providers(): session = onnxruntime.InferenceSession( - path, providers=["CPUExecutionProvider"], ess_options=opts + path, providers=["CPUExecutionProvider"], sess_options=opts ) else: session = onnxruntime.InferenceSession(path, sess_options=opts)