# Buggy code
def _hook_variable(self):
    # Overload 'special' methods here
    self._hook_var___new__()
    self._hook_var_contents()

    for attr in dir(torch.autograd.variable.Variable):
        # Conditions for inclusion/exclusion
        if attr in self.exclude + self.var_exclude:
            continue
        lit = getattr(torch.autograd.variable.Variable, attr)
        is_base = attr in dir(object)
        is_desc = inspect.ismethoddescriptor(lit)
        # is_func = isinstance(type(lit), types.FunctionType)
        is_func = isinstance(lit, types.FunctionType)
        try:
            is_service_func = "HookService" in lit.__qualname__
        except:
            is_service_func = False
        is_old = re.match("old*", attr) is not None

        # Where the overloading happens
        if (
            (is_desc or (is_func and not is_service_func))
            and not is_base
            and not is_old
        ):
            passer = self._pass_method_args(lit)
            new_attr = self._overload_method(passer)
            setattr(torch.autograd.variable.Variable, "old_{}".format(attr), lit)
            setattr(torch.autograd.variable.Variable, attr, new_attr)

    self._hook_var_send_()
    self._hook_get_(torch.autograd.variable.Variable)
    self._hook_var_ser()


# Traceback (RuntimeError)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-14-4207de4e45fd> in <module>()
10 loss.backward()
11
---> 12 model.send_(remote)

/Users/atrask/anaconda/lib/python3.6/site-packages/syft-0.1.0-py3.6.egg/syft/core/hooks.py in send_(self, workers)
907                                                    owners=self.owners, is_pointer=True)
908
--> 909             return hook_self._var_to_pointer(self, hook_self)
910
911         setattr(torch.autograd.variable.Variable, 'send_', send_)

/Users/atrask/anaconda/lib/python3.6/site-packages/syft-0.1.0-py3.6.egg/syft/core/hooks.py in _var_to_pointer(self, var, hook_self)
982         print("_var_to_pointer:" + str(var.data.id))
983         if var.grad is not None:
--> 984             self._var_to_pointer(var.grad, hook_self)
985
986         var.data.old_set_(var.data.__class__(0))

/Users/atrask/anaconda/lib/python3.6/site-packages/syft-0.1.0-py3.6.egg/syft/core/hooks.py in _var_to_pointer(self, var, hook_self)
989                                           id=var.data.id,
990                                           owners=var.owners,
--> 991                                           is_pointer=True)
992         return var
993

/Users/atrask/anaconda/lib/python3.6/site-packages/syft-0.1.0-py3.6.egg/syft/core/workers.py in register_object(self, worker, obj, force_attach_to_worker, temporary, **kwargs)
508             raise RuntimeError(
509                 'Invalid registry: is_pointer is {} but owners is {} on tensor {}'.format(
--> 510                     obj.is_pointer, obj.owners, obj.id))
511         # print("setting object:" + str(obj.id))
512         self.set_obj(obj.id, obj, force=force_attach_to_worker, tmp=temporary)

RuntimeError: Invalid registry: is_pointer is True but owners is [0] on tensor 2841986768

# Fixed code
def _hook_variable(self):
    # Overload 'special' methods here
    self._hook_var___new__()
    self._hook_var_contents()
    self._hook_var_owners()

    for attr in dir(torch.autograd.variable.Variable):
        # Conditions for inclusion/exclusion
        if attr in self.exclude + self.var_exclude:
            continue
        lit = getattr(torch.autograd.variable.Variable, attr)
        is_base = attr in dir(object)
        is_desc = inspect.ismethoddescriptor(lit)
        # is_func = isinstance(type(lit), types.FunctionType)
        is_func = isinstance(lit, types.FunctionType)
        try:
            is_service_func = "HookService" in lit.__qualname__
        except:
            is_service_func = False
        is_old = re.match("old*", attr) is not None

        # Where the overloading happens
        if (
            (is_desc or (is_func and not is_service_func))
            and not is_base
            and not is_old
        ):
            passer = self._pass_method_args(lit)
            new_attr = self._overload_method(passer)
            setattr(torch.autograd.variable.Variable, "old_{}".format(attr), lit)
            setattr(torch.autograd.variable.Variable, attr, new_attr)

    self._hook_var_send_()
    self._hook_get_(torch.autograd.variable.Variable)
    self._hook_var_ser()