Hi,
Few things

You don’t need to .detach() inside the forward.
You don’t need to use Variable. They don’t exist anymore.
You should not use .data. The forward runs in no_grad mode, so nothing is tracked wrt the autograd
What is b_tensor?
You should not use torch.nn.Parameter outside of a nn.Module's __init__() function in general.
Why do you use torch.as_tensor?

For the backward, grad_output contains the derivative of your loss wrt the output of the forward.
You should compute the derivative of your loss wrt the inputs of the forward (x, weight and bias) using the chain rule. So you should write it down mathematically and implement it.
You can use torch.autograd.gradcheck() to check your implementation afterwards.