Example #1
0
        def new___init__(cls,
                         *args,
                         owner=None,
                         id=None,
                         skip_register=False,
                         **kwargs):

            if owner is None:
                owner = hook_self.local_worker

            if register_child_instead:
                cls.native___init__()
                cls._child = _LocalTensor(child=cls,
                                          parent=cls,
                                          torch_type=type(cls).__name__)
            else:
                kwargs["owner"] = owner
                kwargs["id"] = id
                kwargs["skip_register"] = skip_register
                cls.native___init__(*args, **kwargs)
                if id is None:
                    id = int(10e10 * random.random())
                cls.id = id
                cls.owner = owner

                if not skip_register:
                    owner.register_object(cls, id=id)
Example #2
0
        def child(self):
            try:
                try:
                    assert self._child is not None
                    return self._child
                except (AttributeError, AssertionError):
                    self._child = _LocalTensor(child=self,
                                               parent=self,
                                               torch_type=type(self).__name__)
                    return self._child
            except TypeError:
                # for some reason, hasattr(self, '_child') returns a TypeError saying
                # "TypeError: 'NoneType' object is not callable". It's supposed to only
                # return False and I can't get to the bottom of it. So, for now, I'm
                # going to break a personal rule and use try/catch for logic, but
                # this is merely supposed to evaluate whether self has ._child as an
                # attribute. Note this only seems to happen when self is a
                # torch.autograd.Variable

                self._child = _LocalTensor(child=self,
                                           parent=self,
                                           torch_type=type(self).__name__)
                return self._child