Skip to content

【PIR API adaptor No.19】Migrate paddle.incubate.ModelAverage into pir - #59615

Closed
ooooo-create wants to merge 3 commits into
PaddlePaddle:developfrom
ooooo-create:ooooo/pir19
Closed

ooooo-create wants to merge 3 commits into
PaddlePaddle:developfrom
ooooo-create:ooooo/pir19

Conversation

@ooooo-create

@ooooo-create ooooo-create commented Dec 2, 2023 •

Copy link
Copy Markdown
Collaborator

PR types

Others

PR changes

APIs

Description

link #58067
PIR API 推全升级
将 paddle.incubate.ModelAverage 迁移升级至 pir,并更新单测
单测覆盖率: 1/1

@paddle-bot

paddle-bot Bot commented Dec 2, 2023

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot Bot added the contributor External developers label Dec 2, 2023
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Dec 4, 2023
@MarioLulab

Copy link
Copy Markdown
Collaborator

paddle.static.nn.fc 是静态图专用 api,可以使用 paddle.nn.Linear 来代替

@ooooo-create

Copy link
Copy Markdown
Collaborator Author

paddle.static.nn.fc 是静态图专用 api,可以使用 paddle.nn.Linear 来代替

done

238:     test_program = train_program.clone()
1238: AttributeError: 'paddle.base.libpaddle.pir.Program' object has no attribute 'clone'

这个要怎么解决呢~

Comment thread test/legacy_test/test_modelaverage.py Resolved

@MarioLulab MarioLulab left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pir下的 fetch 可能比较麻烦,辛苦修改一下吧

Comment on lines +69 to +75
'linear_0.b_0',
'linear_0.b_0_sum_1_0',
'linear_0.b_0_sum_2_0',
'linear_0.b_0_sum_3_0',
'linear_0.b_0_num_accumulates_0',
'linear_0.b_0_old_num_accumulates_0',
'linear_0.b_0_num_updates_0',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pir 模式下的 fetch_list 目前还不支持传入 value 的 name。需要通过打印pir的program,然后根据单测含义找到需要fetch的value是哪个op下的,通过program索引到对应的op,再通过op的result方法将op的输出传入到fetch_list中

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
打印出来了,还是不会😂,大佬举个例子嘛,通过program索引到对应的op,再通过op的result方法将op的输出传入到fetch_list中 不懂哎

@MarioLulab MarioLulab Dec 18, 2023 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pir 模式下的 fetch_list 目前还不支持传入 value 的 name,所以只能构造内容是 pir.Value 或 pir.OpResult 的 fetch_list。
比方说根据上图打印出来的 program,'linear_0.w_0' 是 train_program 中第一个 op 的输出,那么拿到这个 OpResult 的办法如下:

block = train_program.global_block()
linear_0_b_0 = block.ops[1].result(0)

# 那么 fetch_list 可写为
fetch_list = [linear_0_b_0]
# 以此类推

还可以写一个工具函数,遍历 program 下所有 op,判断其 name 是否是想要的 name,并返回 op 的 OpResult。比方说:

def get_pir_value_by_name(program, fetch_name):
    block = program.global_block()
    for op in block.ops:
        if op.name == "pd_op.data" and op.attrs()['name'] == fetch_name:
            return op.result(0)
        elif op.name == "builtin.parameter" and op.attrs()['parameter_name'] == fetch_name:
            return op.result(0)
    return None

则使用该工具函数可以改写为:

fetch_list=[
    get_pir_value_by_name(train_program, 'linear_0.b_0'),
    get_pir_value_by_name(train_program, 'linear_0.b_0_sum_1_0'),
    ...
],

@ooooo-create ooooo-create Dec 18, 2023 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢感谢,理解了,但是 ·linear_0.b_0_sum_1_0 好像是内部的,program里我找不到~

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已记录该问题,正在复现并尝试 fix

program=test_program,
feed={'X': x},
fetch_list=[loss.name, 'fc_0.b_0'],
fetch_list=[loss.name, 'linear_0.b_0'],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

program=test_program,
feed={'X': x},
fetch_list=[loss.name, 'fc_0.b_0'],
fetch_list=[loss.name, 'linear_0.b_0'],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@paddle-ci-bot

paddle-ci-bot Bot commented Dec 29, 2023

Copy link
Copy Markdown

Sorry to inform you that 8c9c3d8's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@luotao1 luotao1 closed this Mar 7, 2024
@ooooo-create
ooooo-create deleted the ooooo/pir19 branch March 8, 2025 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers HappyOpenSource 快乐开源活动issue与PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants