mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-05 22:57:40 +03:00
fix: set onnxruntime thread options to avoid LXC pthread_setaffinity_np errors
When running inside LXC containers (e.g. Proxmox), onnxruntime's thread pool tries to call pthread_setaffinity_np() which fails with EINVAL (error 22). Setting intra/inter_op_num_threads=1 when OMP_NUM_THREADS=1 is set prevents this error and stabilizes ML inference (face_recognition, semantic_search, classification) in containerized environments. Document OMP_NUM_THREADS=1 in docker-compose.yml as a commented option for LXC deployments. Fixes #22620
This commit is contained in:
parent
416a9b7692
commit
749d749334
@ -24,6 +24,10 @@ services:
|
|||||||
# capabilities: [gpu]
|
# capabilities: [gpu]
|
||||||
environment:
|
environment:
|
||||||
YOLO_MODELS: ""
|
YOLO_MODELS: ""
|
||||||
|
# Set OMP_NUM_THREADS=1 when running in LXC containers (e.g. Proxmox) to prevent
|
||||||
|
# onnxruntime from calling pthread_setaffinity_np(), which fails in LXC with EINVAL.
|
||||||
|
# This affects face_recognition, semantic_search, and classification features.
|
||||||
|
# OMP_NUM_THREADS: "1"
|
||||||
# devices:
|
# devices:
|
||||||
# - /dev/bus/usb:/dev/bus/usb # Uncomment for Google Coral USB
|
# - /dev/bus/usb:/dev/bus/usb # Uncomment for Google Coral USB
|
||||||
# - /dev/dri:/dev/dri # for intel hwaccel, needs to be updated for your hardware
|
# - /dev/dri:/dev/dri # for intel hwaccel, needs to be updated for your hardware
|
||||||
|
|||||||
@ -24,23 +24,36 @@ def is_arm64_platform() -> bool:
|
|||||||
|
|
||||||
def get_ort_session_options(
|
def get_ort_session_options(
|
||||||
is_complex_model: bool = False,
|
is_complex_model: bool = False,
|
||||||
) -> ort.SessionOptions | None:
|
) -> ort.SessionOptions:
|
||||||
"""Get ONNX Runtime session options with appropriate settings.
|
"""Get ONNX Runtime session options with appropriate settings.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
is_complex_model: Whether the model needs basic optimization to avoid graph fusion issues.
|
is_complex_model: Whether the model needs basic optimization to avoid graph fusion issues.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
SessionOptions with appropriate optimization level, or None for default settings.
|
SessionOptions with appropriate optimization level and thread settings.
|
||||||
"""
|
"""
|
||||||
|
sess_options = ort.SessionOptions()
|
||||||
|
|
||||||
|
# When OMP_NUM_THREADS=1 is set (recommended for LXC/container environments),
|
||||||
|
# or when running in a container where pthread_setaffinity_np is blocked,
|
||||||
|
# onnxruntime logs repeated errors like:
|
||||||
|
# "pthread_setaffinity_np failed ... error code: 22 ... Invalid argument"
|
||||||
|
# Setting intra/inter_op_num_threads=1 prevents the thread pool from trying
|
||||||
|
# to set CPU affinity, eliminating the error spam in LXC containers (Proxmox, etc.).
|
||||||
|
import os
|
||||||
|
|
||||||
|
omp_threads = int(os.environ.get("OMP_NUM_THREADS", "0"))
|
||||||
|
if omp_threads == 1:
|
||||||
|
sess_options.intra_op_num_threads = 1
|
||||||
|
sess_options.inter_op_num_threads = 1
|
||||||
|
|
||||||
if is_complex_model:
|
if is_complex_model:
|
||||||
sess_options = ort.SessionOptions()
|
|
||||||
sess_options.graph_optimization_level = (
|
sess_options.graph_optimization_level = (
|
||||||
ort.GraphOptimizationLevel.ORT_ENABLE_BASIC
|
ort.GraphOptimizationLevel.ORT_ENABLE_BASIC
|
||||||
)
|
)
|
||||||
return sess_options
|
|
||||||
|
|
||||||
return None
|
return sess_options
|
||||||
|
|
||||||
|
|
||||||
# Import OpenVINO only when needed to avoid circular dependencies
|
# Import OpenVINO only when needed to avoid circular dependencies
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user