Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化 PartialProgramLayer hash逻辑 #49752

Merged
merged 6 commits into from
Feb 4, 2023
Merged

Conversation

huajiao-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())

上述代码会报错

python/paddle/fluid/layers/utils.py Outdated Show resolved Hide resolved
python/paddle/fluid/layers/utils.py Outdated Show resolved Hide resolved
python/paddle/fluid/layers/utils.py Outdated Show resolved Hide resolved
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
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