HTTP/2 200
date: Fri, 25 Jul 2025 06:36:33 GMT
content-type: text/html; charset=utf-8
cache-control: no-cache
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
referrer-policy: no-referrer-when-downgrade
server-timing: pull_request_layout-fragment;desc="pull_request_layout fragment";dur=493.104008,conversation_content-fragment;desc="conversation_content fragment";dur=1556.936347,conversation_sidebar-fragment;desc="conversation_sidebar fragment";dur=442.189123,nginx;desc="NGINX";dur=1.548857,glb;desc="GLB";dur=101.550877
strict-transport-security: max-age=31536000; includeSubdomains; preload
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-content-type-options: nosniff
x-frame-options: deny
x-voltron-version: a2eb102
x-xss-protection: 0
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=XGahbNvYDeplu8DcGsUyP1y6D%2BZdRQeKuIfgurpGSBzwSAGcXS2ClUClCihxn%2Bl9yTWCwVbtGG6W3VRfLNKzyczi%2BKAGNYthnWSA6FbJ47OCA0Wn5dts9iOzEmlU0rOLvA1quNJ4z1uoIgaahoU1EJ58Vvwim%2FP3Lq52%2FdwJ9XNnSnPtkEtIzyV7Eo1fND9Tyo82%2FD8X5ScJWozYO0Ocx8v2fLAu%2F9z3%2FksswZ4v%2FkNq6h%2B%2F2ZZeXi6xnmhNSEnvJo2XBf5CmVtcnAII6eQp7Q%3D%3D--rvjLoGx5rSNWcl87--TidsR%2Fp10Ff62YDUt5K7Xw%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1555234926.1753425391; Path=/; Domain=github.com; Expires=Sat, 25 Jul 2026 06:36:31 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sat, 25 Jul 2026 06:36:31 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: EAF0:3FCB1:37F764:460984:688325EF
[Pir]Fix Value eq error when using set by 0x45f · Pull Request #58896 · PaddlePaddle/Paddle · GitHub
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.
PR types
Bug fixes
PR changes
Others
Description
Pcard-67164
1 背景
我们需要在python端给pir下的OpResult patch一些方法,以对齐老静态图的Variable,比如x.reshape、x.add等方法的调用,以及a == b,a != b等操作符也需要对齐。
但是在给OpResult patch __eq__方法的时候遇到了问题,相关PR:https://github.com/PaddlePaddle/Paddle/pull/5834 。在静态图下对于a == b 这样的操作(也就是OpResult的__eq__方法)的语义是在program中插入一个 equal op,这是__eq__的正确语义,请牢记。
2 具体问题
在python端给OpResult patch __eq__方法的时候(实现eq的正确语义,也就是插入一个equal op),发现pir backward的逻辑会有问题,发现之前在C++端的pir.cc中给OpResult和Value已经pybind了__eq__的方法,逻辑如下是通过impl来判断OpResult或者Value是否是同一个对象的。后面发现不止backward,pir optest、组合算子逻辑、pir单测等多个地方都有类似的用法

之前为什么会加这样的逻辑呢?
因为ir_backward.py中有类似set(Value)、set(OpResult)的用法,对于set来说需要去重那set是如何去重的呢?是通过item的__hash__,对象指针和__eq__来联合判断两个元素是否是同一个元素,所以为了能够正确的使用set,就在C++端pybind 了 __hash__和__eq__方法。
但是这里的__eq__的语义和上面提到的正确语义是相背的(正确语义是插入equal op)。
在PIR下我们主要的诉求就是:给Value patch上__eq__方法,该方法应该在program中插入equal op,同时已有的set、dict等代码能够正确work
3 Python集合说明
3.1 set和dict
set.add判断是否是同一个元素的步骤如下:
3.2 list
对于
if x in list
以及list.index(x)
这样的python代码,会调用PyObject_RichCompareBool。PyObject_RichCompareBool内Py_EQ的时候4 老静态图类似情况说明
老静态图下因为Variable有name,所以很多地方使用的都是类似set(name)这种形式,set(name)这种用法是没有问题的。
对于set(Variable),老静态图也可能会有问题,只是出问题的概率比较小:
a in set
这样的代码,如果 a 不在set里,那么只会进行第一步hash的比较,走不到第二三步的比较老静态图下对于
if x in list
这样的代码也不可用,基本用就会错。出错原因在3.2已经说明。5 PIR下如何解决
排查后目前框架中有多处set(Value)、dict[Value]以及
if value in list
这样的用法。目前可行且修改较小的一个方法方案如下,也是本PR进行的工作:if value in list
、list.index(x)
这样的代码,需要修改逻辑if x in list
这样的代码,但是目前没有想到办法能让这种代码raise error