tcls[b][fg_index].scatter_(1, cls_index, 1) applies the scatter_ on the slice (which is apparently a copy in this case) so that the manipulation won’t be applied on the original tensor.
Could you post a small code snippet with some desired values so that we could have a look at it?
PS: you can post code snippets by wrapping them into three backticks ```, which would make debugging easier