That is a trait of ADHD. Hyperfocus until you find the next thing to hyperfocus on and then completely forget about the previous one. The best way to deal with it* IMHO is to have a long term goal - and a reason why you want to achieve it. The reason should be chosen so that it motivates you to continue with the project. If you cannot think of a good one that will meet that requirement, then consider switching to a p…
What is a really good reason that has motivated you? Can you give some examples? This is the place where I get stuck.
An example is "implement XYZ paper" -> when you get off track, think about the algorithm running on your computer, how much faster it would be than the previous one, etc.