Decoration or redefining torch.mm(...) to be used inside torch

Hi, I was curious, Is it possible to define a custom function like

def myMM(...):
  return something

and assign its pointer to torch.mm() or some of other implicitly defined functions in torch(like torch.dot, torch.matmul or …), then instead of defining new Function for nn.linear or …; make nn.linear to perform matrix multiplication using myMM function inside its source code?

I just want to give a new definition to dot product in pytorch but I don’t want to redefine all nn modules like (conv, linear, lstm, …) as a customized function for my simulations.

I would be appreciated it if you could help me
TNX

Maybe the Extending torch docs might be useful as they describe how to create a custom tensor class and make it work via overriding built-in methods.

1 Like

Thank you for your answer, I have already studied them. But they are not what I am looking for.

let me be precise, how can I edit torch.mm() or torch.matmul() source code inside pytorch? what files should I look into that? I already looked at ATen source file for cuda,… also torch directory in github but I couldn’t figure out where is the definition of torch.mm() to edit