Implement my reduce function

I try to write a reduce function by myself. If it’s just execute a sum of dimensions , it will perform well. But when i try to input a variance it is broken(reduce(tensorx) = pow((tensorx.data - mean), 2) / n). It will overflow with the datatype of __half(16-bits). How is the pytorch function do to this phenomenon(I tried to find it, if you kown where the examples are, please tell me the exact location, thanks!!!)