Flexible Differentiable Optimization via Model Transformations