How to make a virtual step without truly updating weights and use the loss after the virtual step to update the original weights?

Assume that the original weight is w1 and the loss is L1. After a virtual step, the updated (not truly updated) weight is w2 and the according loss is L2. How to calculate d(L2)/d(w1) and use this to update w1? I think it might be something like this (d(L2)/d(w2)) * (d(w2)/d(w1)), but don’t know how to implement it.

Thanks a lot!