I think your gut has it right. The grass is not always greener. You've been doing your PhD and know its pros/cons and you very much enjoy the aspects of continuing and becoming an expert in machine learning. There will be no shortage of demand for this. By asking the question, it seems that you are financially capable of passing the SWE offer and continuing your research. The missing out on income in a position easily filled my many others is FOMO, as mentioned in by others. Note that the F is fear, and you should decide by passion rather than avoidance. Fear is only good for planning and if financially viable to continue should already have been addressed. If you're comparing with others who are taking these well paying positions, look at it from the point of view from the future as you have outlined: what area would you like to be actively working in?