You can use torch.where(mask_for_update, updated_tensor, original_tensor) to only apply the update to updated_tensor. If you want to update given elements in the batch, you could use a mask of shape batch x 1 with the to-be-masked items set to True.
Best regards
Thomas