How to find the weights for weighted least squares regression?

When we are doing weighted least squares how do we find the weights? Where ever I see tutorials are just using $$w_i = \frac{1}{(sigma)i^2}$$ and doing it with basic data. But I want to know how to find the weights for real data. Is it always the inverse of the square of variance?

No, the weight does not always has to be equal to the inverse of the square of variance. There is no universally accepted scheme. Different weighting schemes are used, such as $$1/x$$, $$1/x^2$$, $$1/\sqrt{x}$$, where $$x$$ are your data. The weighting scheme depends on many things: the distribution of your data, their meaning, and in which regions you want to fit them more closely (whether small data values should have lower error), etc.