Resetting connection in neural networks

Hello
i have a code that it is subclassing nn.module

class Connection(torch.nn.module):
    super().__init__()
    
    def reset_(self) -> None:
   
    """
    Contains resetting logic for the connection.
    """
    super().reset_()

i don’t know what exactly reset_() does
and i did not find any reset_() function in nn.module source code
So how can i figure out what reset_() exactly does???

As you said, the nn.Module does not have the reset_ method implemented.
Where did you find the code?

Also, there are a few issues regardless of the unknown reset_ method:

  • nn.module does not exist and should probably be nn.Module
  • the super().__init__() call is outside of the class’ __init__ method
  • the indentation of super().reset_() doesn’t match the def reset indent.

Hey …thanks for your response
this is the full code almost:

class AbstractConnection(ABC, Module):

    def __init__(
    self,
    source: Nodes,
    target: Nodes,
    nu: Optional[Union[float, Sequence[float]]] = None,
    reduction: Optional[callable] = None,
    weight_decay: float = 0.0,
    **kwargs
) -> None:
 
    super().__init__()



class Connection(AbstractConnection):

    def __init__(
    self,
    source: Nodes,
    target: Nodes,
    nu: Optional[Union[float, Sequence[float]]] = None,
    reduction: Optional[callable] = None,
    weight_decay: float = 0.0,
    **kwargs
) -> None:


def reset_(self) -> None:
    # language=rst
    """
    Contains resetting logic for the connection.
    """
    super().reset_()

Thanks for code.
I tried to create a small reproducible code snippet and it just seems the base class’ reset_ is called, which does nothing, since it’s implemented as a pass:

class AbstractConnection(ABC, nn.Module):
    def __init__(self):
        super(AbstractConnection, self).__init__()
        
    @abstractmethod
    def reset_(self):
        print("base class called")
    
class Connection(AbstractConnection):
    def reset_(self):
        super().reset_()


con = Connection()
con.reset_()
> base class called

Is this method implemented in another using other options than the super().reset_() call?

1 Like

thank you @ptrblck very much … Just why we have to write that when we are not using this function reset_() ?
I just saw in another module , that reset_() has been defined there , but it was not calling by this module…that’s why i don’t know what this functions does…

I’m not familiar with the complete code, but I would assume this function is somewhere implemented and used.
Did another class derive from the class containing the implemented reset_ method?

1 Like

yeah there is another class that is subclassing the class which reset_ method is defined into … but that object is not calling in this class that i sent the code … is that reasonable that we use a method that it has defined in another object and i’m not calling that module/object?

I’m really not sure, what the complete code is doing, so either the author had something in mind and didn’t implement it or some other code parts are using the implemented logic and you are missing them.
Could you post a link to the original implementation, so that we could have a look?

@ptrblck your questions helped me find my answer …i found this function reset_() in another module that was imported to this module … really very very thank you to all of time u gave me and i appreciate your help :))))))))))))

1 Like