Skip to content

[Regression] MKLDNN does not work at all anymore in version 3.0.2 #15782

Description

@timminator

🔎 Search before asking

  • I have searched the PaddleOCR Docs and found no similar bug report.
  • I have searched the PaddleOCR Issues and found no similar bug report.
  • I have searched the PaddleOCR Discussions and found no similar bug report.

🐛 Bug (问题描述)

When running the following command:

(venv-3.12) PS C:\Users\GPUVM\Desktop\New folder (13)> paddleocr ocr -i "Path\to\images" --lang ch --use_doc_orientation_classify False --use_doc_unwarping False --use_textline_orientation false --device cpu --enable_mkldnn true

MKLDNN is not enabled, it is falling back to the running mode "paddle". It does also not work when omitting the argument "--enable_mkldnn". This was tested also with the latest release branch of paddlex from today.

The issue is also pretty clear. In the code, the PaddleXPipelineWrapper calls prepare_common_init_args like this:

    def _create_paddlex_pipeline(self):
        kwargs = prepare_common_init_args(None, self._common_args)
        return create_pipeline(config=self._merged_paddlex_config, **kwargs)

This means that here:

def prepare_common_init_args(model_name, common_args):
    device = common_args["device"]
    if device is None:
        device = get_default_device()
    device_type, device_ids = parse_device(device)
    if device_ids is not None:
        device_id = device_ids[0]
    else:
        device_id = None

    init_kwargs = {}
    init_kwargs["use_hpip"] = common_args["enable_hpi"]
    init_kwargs["hpi_config"] = {
        "device_type": device_type,
        "device_id": device_id,
    }

    pp_option = PaddlePredictorOption(
        model_name, device_type=device_type, device_id=device_id
    )
...

the model_name is always None, as it is never populated in the Pipeline Wrapper. That means that in paddlex get_default_run_mode always returns paddle as the running mode:

def get_default_run_mode(model_name, device_type):
    if not model_name:
        return "paddle"
    if device_type != "cpu":
        return "paddle"
    if (
        ENABLE_MKLDNN_BYDEFAULT
        and is_mkldnn_available()
        and model_name not in MKLDNN_BLOCKLIST
    ):
        return "mkldnn"
    else:
        return "paddle"

And because PaddleOCR in prepare_common_init_args never sets the run_mode explicitly here:

elif device_type == "cpu":
        enable_mkldnn = common_args["enable_mkldnn"]
        if enable_mkldnn:
            pp_option.mkldnn_cache_capacity = common_args["mkldnn_cache_capacity"]
        else:
            pp_option.run_mode = "paddle"

MKLDNN can never be enabled. Adding a line like pp_option.run_mode = "mkldnn" in the if enable_mkldnn statement enables mkldnn again, but I dont think thats the proper solution to this issue.

🏃‍♂️ Environment (运行环境)

OS: Windows 11
PaddleOCR 3.0.2
PaddlePaddle 3.0.0 (CPU version)
16GB RAM
GPU: Nvidia GTX 1660 TI
Installed via pip in a venv with Python 3.12

🌰 Minimal Reproducible Example (最小可复现问题的Demo)

Explained above.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions