It depends a lot on what sort of layers the data has already been through so there is no simple answer. You just have to figure it out by checking the docs for similar existing functions.

A Conv2D 1 layer takes data of shape (batches, color_channels, x_coords, y_coords), and outputs data of shape (batches, filters, x_coords, y_coords).

LSTMs take data of shape (timesteps, batches, features) unless you specify batch_first=True.
A Linear layer takes data of shape (batches, *, features), where * represents zero or more additional dimensions and returns data of shape (batches, *, number_of_units_in_linear_layer).

In your example, I think forward() should take tensors of shape (batches, n), and (batches, m) and should return something of shape (batches, k).
In most cases you don’t actually have to code the backward() function, pytorch will figure it out.  That said, the grad_input would be of shape (batches, k) and backward should return tensors of shape (batches, n) and (batches, m). But that part ought to be obvious once you know what shapes forward() takes and returns.