Skip to content

Conversation

@Fancy-hjyp
Copy link
Contributor

PR types

Bug fixes

PR changes

APIs

Describe

改变Program hash 逻辑,解决id复用问题

@paddle-bot
Copy link

paddle-bot bot commented Jan 11, 2023

你的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 contributor External developers status: proposed labels Jan 11, 2023
@0x45f
Copy link
Contributor

0x45f commented Jan 11, 2023

from weakref import WeakKeyDictionary
from collections import defaultdict
from uuid import uuid4

class UniqueIdMap(WeakKeyDictionary):
    def __init__(self, dict=None):
        super().__init__(self)
        self.data = defaultdict(uuid4)
        if dict is not None:
            self.update(dict)


uniqueidmap = UniqueIdMap()


def uniqueid(obj):
    return uniqueidmap[obj].int



class A:
    def __init__(self) -> None:
        self.x = 0

a = A()

x = [a]
uniqueid(x)
print(uniqueidmap.keyrefs())
del x
print(uniqueidmap.keyrefs())

上述代码会报错

for v in obj:
t = t + uniqueid(v)
return t
return (uniqueidmap[obj].int,)
Copy link
Contributor

Choose a reason for hiding this comment

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

CUDA 单测里这里的obj会存在为str对象,而str对象似乎不可以被weakref

@luotao1 luotao1 merged commit 3e5a6df into PaddlePaddle:develop Feb 4, 2023
@Fancy-hjyp Fancy-hjyp deleted the id branch November 2, 2023 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants