mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/44090 This is an initial commit pulling in the torchgpipe fork at https://github.com/facebookresearch/fairscale. The purpose of this commit is to just pull in the code and ensure all tests and builds work fine. We will slowly modify this to match our intended API mentioned in https://fb.quip.com/txurAV3zIFox#RPZACAfAKMq. Follow up PRs would address further changes needed on top of the initial commit.. We're pulling the code into the `torch.distributed._pipeline.sync` package. The package is private on purpose since there is a lot of work (ex: docs, API changes etc.) that needs to go in before we can actually officially support this. ghstack-source-id: 114864254 Test Plan: 1) waitforbuildbot 2) Ran all tests on my devgpu Reviewed By: mrshenli Differential Revision: D23493316 fbshipit-source-id: fe3c8b7dadeeb86abdc00e8a8652491b0b16743a
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
# Copyright 2019 Kakao Brain
|
|
#
|
|
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
|
|
#
|
|
# This source code is licensed under the BSD license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
import torch
|
|
|
|
from torch.distributed._pipeline.sync.phony import get_phony
|
|
|
|
|
|
def test_phony_size():
|
|
p = get_phony(torch.device("cpu"), requires_grad=False)
|
|
assert p.size() == (0,)
|
|
|
|
|
|
def test_phony_requires_grad():
|
|
p1 = get_phony(torch.device("cpu"), requires_grad=True)
|
|
p2 = get_phony(torch.device("cpu"), requires_grad=False)
|
|
assert p1.requires_grad
|
|
assert not p2.requires_grad
|
|
|
|
|
|
def test_cached_phony():
|
|
p1 = get_phony(torch.device("cpu"), requires_grad=True)
|
|
p2 = get_phony(torch.device("cpu"), requires_grad=True)
|
|
assert p1 is p2
|
|
|
|
p3 = get_phony(torch.device("cpu"), requires_grad=False)
|
|
p4 = get_phony(torch.device("cpu"), requires_grad=False)
|
|
assert p3 is p4
|
|
|
|
assert p1 is not p3
|
|
|
|
|
|
def test_phony_in_autograd_function():
|
|
class Phonify(torch.autograd.Function):
|
|
@staticmethod
|
|
def forward(ctx, input):
|
|
phony = get_phony(input.device, requires_grad=False)
|
|
return phony.detach()
|
|
|
|
x = torch.rand(1, requires_grad=True)
|
|
|
|
p1 = Phonify.apply(x)
|
|
p2 = get_phony(torch.device("cpu"), requires_grad=True)
|
|
|
|
assert p1 is not p2
|
|
assert p1.grad_fn is not None
|
|
assert p2.grad_fn is None
|