Thanks for your reply.

Do a  nn.LossFn(reduction='none') , weigh the different samples to your liking

If the method above is correct (In fact, I think that’s correct),
but why I need to do reduction (e.g. mean)?
If I don’t do that, what will happen?
From mathematical theory


Batch Gradient Descent
When the number of samples is large, the training process will be slow.


Stochastic Gradient Descent
Decreased accuracy, not globally optimal.


Mini-batch Gradient Descen
Use a subset of samples to update each parameter.


Usually we use Mini-batch Gradient Descen-like to update the parameters. Which means we get the average value of the loss function to update parameters.
Is the process of averaging (do reduction (e.g. mean)) equivalent to this process?
Or the process of averaging (do reduction (e.g. mean)) is just for PyTorch operating mechanism?