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

Fix tensor deepcopy bug #7490

Merged
merged 9 commits into from
Feb 15, 2022
Merged

Fix tensor deepcopy bug #7490

merged 9 commits into from
Feb 15, 2022

Conversation

lixiang007666
Copy link
Contributor

@lixiang007666 lixiang007666 commented Feb 14, 2022

This PR is done:

@strint
Copy link
Contributor

strint commented Feb 14, 2022

deepcopy的协议:

def _deepcopy_inst(x, memo):
    if hasattr(x, '__deepcopy__'):
        return x.__deepcopy__(memo)
    if hasattr(x, '__getinitargs__'):
        args = x.__getinitargs__()
        args = deepcopy(args, memo)
        y = x.__class__(*args)
    else:
        y = _EmptyClass()
        y.__class__ = x.__class__
    memo[id(x)] = y
    if hasattr(x, '__getstate__'):
        state = x.__getstate__()
    else:
        state = x.__dict__
    state = deepcopy(state, memo)
    if hasattr(y, '__setstate__'):
        y.__setstate__(state)
    else:
        y.__dict__.update(state)
    return y

Ref:
copy实现:https://svn.python.org/projects/python/trunk/Lib/copy.py
stackoverflow答案:https://stackoverflow.com/questions/22388854/relationship-between-pickle-and-deepcopy

@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot February 14, 2022 10:57
@oneflow-ci-bot oneflow-ci-bot removed their request for review February 14, 2022 12:14
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot February 14, 2022 12:41
@github-actions
Copy link
Contributor

CI failed when running job: cpu-module. PR label automerge has been removed

@oneflow-ci-bot oneflow-ci-bot removed their request for review February 14, 2022 14:44
@oneflow-ci-bot oneflow-ci-bot removed their request for review February 14, 2022 15:08
@github-actions
Copy link
Contributor

CI failed when running job: cpu-module. PR label automerge has been removed

@oneflow-ci-bot oneflow-ci-bot removed their request for review February 15, 2022 00:01
@github-actions
Copy link
Contributor

Speed stats:
GPU Name: GeForce GTX 1080 

✔️ OneFlow resnet50 time: 128.7ms (= 12868.5ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 142.1ms (= 14214.8ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.10 (= 142.1ms / 128.7ms)

✔️ OneFlow resnet50 time: 78.6ms (= 7860.8ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 84.9ms (= 8486.4ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.08 (= 84.9ms / 78.6ms)

OneFlow resnet50 time: 52.3ms (= 10464.4ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 57.9ms (= 11578.8ms / 200, input_shape=[4, 3, 224, 224])
✔️ Relative speed: 1.11 (= 57.9ms / 52.3ms)

OneFlow resnet50 time: 44.6ms (= 8922.7ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 48.5ms (= 9693.0ms / 200, input_shape=[2, 3, 224, 224])
✔️ Relative speed: 1.09 (= 48.5ms / 44.6ms)

OneFlow resnet50 time: 39.4ms (= 7872.3ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 39.4ms (= 7885.2ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.00 (= 39.4ms / 39.4ms)

✔️ OneFlow resnet50 time: 140.5ms (= 14053.9ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 158.8ms (= 15876.7ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.13 (= 158.8ms / 140.5ms)

OneFlow resnet50 time: 89.2ms (= 8921.1ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 103.0ms (= 10300.6ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.15 (= 103.0ms / 89.2ms)

OneFlow resnet50 time: 63.3ms (= 12665.3ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 78.0ms (= 15594.9ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.23 (= 78.0ms / 63.3ms)

OneFlow resnet50 time: 53.3ms (= 10656.4ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 63.2ms (= 12635.9ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.19 (= 63.2ms / 53.3ms)

OneFlow resnet50 time: 47.0ms (= 9392.4ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 58.8ms (= 11756.8ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.25 (= 58.8ms / 47.0ms)

@lixiang007666 lixiang007666 merged commit a416374 into master Feb 15, 2022
@lixiang007666 lixiang007666 deleted the Fix_tensor_deepcopy_bug branch February 15, 2022 01:54
marigoold pushed a commit that referenced this pull request Mar 15, 2022
* Fix tensor deepcopy bug

* Remove TODO and check graph

* Fix bug

Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]Incorrect device of oneflow tensor after deepcopy [BUG] NLLLoss打开Graph测试报错
4 participants