Where does it happen?
Note that I assume in the code above the x is 1D. You might need to update that.
For example, if x is 2D:

If you want beta to be the same for all elements for a given sample, you can simply add a beta = beta.unsqueeze(-1) to add a new dimension of size 1 in beta and the broadcasting logic will take care to expand it.
If you want a different beta for every element of every sample, then just update the size given to torch.empty() to reflect the full size of x.