How to calculate the weights for the CrossEntropy loss function?

I saw you completely changed your question by editing it.
I almost missed that, it might have been better to post your new question below.

As it is now you are not doing anything inherently wrong. As long as the all_samples value is correct.
Take a look at this.

What reduction='none' changes compared to reduction='mean' (which is default), is that instead of getting the weighted mean of the output you will now get the output without any reduction applied, meaning you will get an output of the same size as the target size.
But keep in mind that, if you want to use the weight parameter of CELoss and set reduction to none, you would have to manually normalize your loss. See here.