openvinotoolkit/openvino

[Good First Issue]: enable PIR format for PDPD FE

Open

#29,325 opened on Mar 7, 2025

View on GitHub
 (33 comments) (0 reactions) (1 assignee)C++ (3,229 forks)auto 404
category: PDPD FEgood first issueno_stale

Repository metrics

Stars
 (10,286 stars)
PR merge metrics
 (Avg merge 14d 3h) (305 merged PRs in 30d)

Description

Context

PaddlePaddle has enabled a new MLIR based format named PIR since 3.0 version. It is a new feature published on https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/paddle_v3_features/paddle_ir_cn.html [Chinese only].

Currently, OpenVINO has supported PDPD model by protobuf format models. New PIR format models should also be enabled in OpenVINO PDPD FE.

What needs to be done?

  • read new PIR model(json)
  • deserialize PIR model
  • map the model description with weights
  • translate the PIR model into node_context.
  • add PIR tests

Example Pull Requests

Maybe you can refer to the draft PR https://github.com/openvinotoolkit/openvino/pull/29323.

  • register the json for paddle
  • import json.hpp header
  • search TODO PIR string and try to implement or modify the relate functions.

Resources

  1. save PIR model from PDPD currently, PIR feature needs PaddlePaddle 3.0 and beyond. You can install by pip install paddlepaddle==3.0.0b2. You can turn on the PIR by export FLAGS_enable_pir_api=1. This is a sample.
import paddle
import os

from paddle.vision.models import ResNet
from paddle.vision.models.resnet import BottleneckBlock

net = ResNet(BottleneckBlock, 50)
net = paddle.jit.to_static(net, full_graph=True)

# Check if FLAGS_enable_pir_api environment variable is set to 1
if os.getenv('FLAGS_enable_pir_api') == '1':
    save_json = "./irs/resnet"
else:
    save_json = "./pds/resnet"

input_spec = [paddle.static.InputSpec(shape=[1,3,224,224], dtype='float32')]

paddle.jit.save(net, save_json, input_spec)

loaded_model = paddle.jit.load(save_json)
program = loaded_model.program()
print("program is like:\n", program)

for block in program.keys:
    for op in block.ops:
        print("op type is {}.".format(op.name()))
  1. infer by OpenVINO.
import os
from openvino.runtime import Core

import pdb

if os.getenv('FLAGS_enable_pir_api') == '1':
    paddle_model = "./irs/resnet.json"
else:
    paddle_model = "./pds/resnet.pdmodel"

ie = Core()

print("paddle_model: {}".format(paddle_model))
pdb.set_trace()

ov_model = ie.read_model(paddle_model)
compiled_model = ie.compile_model(ov_model)
  1. PDPD reference
  1. OpenVINO PDPD FE reference

Contact points

@xczhai @liubo-intel @yuxu42

Ticket

No response

Contributor guide