mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08: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.
|
|
"""Provides isolated namespace of skip tensors."""
|
|
import abc
|
|
from functools import total_ordering
|
|
from typing import Any
|
|
import uuid
|
|
|
|
__all__ = ["Namespace"]
|
|
|
|
|
|
@total_ordering
|
|
class Namespace(metaclass=abc.ABCMeta):
|
|
"""Namespace for isolating skip tensors used by :meth:`isolate()
|
|
<torchpipe.skip.skippable.Skippable.isolate>`.
|
|
"""
|
|
|
|
__slots__ = ("id",)
|
|
|
|
def __init__(self) -> None:
|
|
self.id = uuid.uuid4()
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Namespace '{self.id}'>"
|
|
|
|
def __hash__(self) -> int:
|
|
return hash(self.id)
|
|
|
|
# Namespaces should support ordering, since SkipLayout will sort tuples
|
|
# including a namespace. But actual order between namespaces is not
|
|
# important. That's why they are ordered by version 4 UUID which generates
|
|
# random numbers.
|
|
def __lt__(self, other: Any) -> bool:
|
|
if isinstance(other, Namespace):
|
|
return self.id < other.id
|
|
return False
|
|
|
|
def __eq__(self, other: Any) -> bool:
|
|
if isinstance(other, Namespace):
|
|
return self.id == other.id
|
|
return False
|
|
|
|
|
|
# 'None' is the default namespace,
|
|
# which means that 'isinstance(None, Namespace)' is 'True'.
|
|
Namespace.register(type(None))
|