Thanks for your reply.
The code you wrote is very good.
But I have a question: When the optimizer is BGD, MBGD, can the above code run normally?
In the batches, there will be samples predicted as a, and samples predicted as b.
I don’t think optimizer.step() can run normally at that time.