LPGD: A General Framework for Backpropagation through Embedded Optimization Layers