fix: force-disable oneDNN via paddle.set_flags and enable_mkldnn=False
All checks were successful
CI / go-lint (push) Has been skipped
CI / test-go-consent (push) Successful in 34s
CI / test-python-voice (push) Successful in 32s
CI / test-bqas (push) Successful in 32s
CI / Deploy (push) Successful in 2s
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped

Previous FLAGS_use_mkldnn env var was ignored by PaddlePaddle 3.x.
Now using paddle.set_flags() API and PaddleOCR enable_mkldnn param.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-13 19:01:46 +01:00
parent eaba087d11
commit 3fd3336f6c

View File

@@ -8,8 +8,16 @@ import threading
# Disable oneDNN/MKLDNN before importing paddle — avoids # Disable oneDNN/MKLDNN before importing paddle — avoids
# ConvertPirAttribute2RuntimeAttribute errors on PaddlePaddle 3.x # ConvertPirAttribute2RuntimeAttribute errors on PaddlePaddle 3.x
os.environ["FLAGS_use_mkldnn"] = "0" os.environ["FLAGS_use_mkldnn"] = "0"
os.environ["FLAGS_use_onednn"] = "0"
os.environ["PADDLE_PDX_DISABLE_MODEL_SOURCE_CHECK"] = "1" os.environ["PADDLE_PDX_DISABLE_MODEL_SOURCE_CHECK"] = "1"
# Must set paddle flags before import
try:
import paddle
paddle.set_flags({"FLAGS_use_mkldnn": False})
except Exception:
pass
import numpy as np import numpy as np
from fastapi import FastAPI, File, Header, HTTPException, UploadFile from fastapi import FastAPI, File, Header, HTTPException, UploadFile
from PIL import Image from PIL import Image
@@ -35,7 +43,9 @@ def _load_model():
logger.info("Import done. Loading PaddleOCR model...") logger.info("Import done. Loading PaddleOCR model...")
# Try multiple init strategies for different PaddleOCR versions # Try multiple init strategies for different PaddleOCR versions
inits = [ inits = [
# PaddleOCR 3.x — use_textline_orientation replaces use_angle_cls # PaddleOCR 3.x — disable MKLDNN via enable_mkldnn=False
dict(lang="en", ocr_version="PP-OCRv5", use_textline_orientation=True, enable_mkldnn=False),
# PaddleOCR 3.x without enable_mkldnn param
dict(lang="en", ocr_version="PP-OCRv5", use_textline_orientation=True), dict(lang="en", ocr_version="PP-OCRv5", use_textline_orientation=True),
# PaddleOCR 3.x with deprecated param # PaddleOCR 3.x with deprecated param
dict(lang="en", ocr_version="PP-OCRv5", use_angle_cls=True), dict(lang="en", ocr_version="PP-OCRv5", use_angle_cls=True),