Please do not implement those functions by yourself, they are already implemented in pytorch, search the documentation for their respective functions.
In order to match up the sizes, I would recommend you debug your program and take caution of tensor.shape and the broadcasting rule