If you want to change the class weights based on the current class distribution, you could use a non-reduced loss via reduction='none' and multiply with your created weight tensor.
Otherwise, the passed weights will be applied to the corresponding class samples.