question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimizers improvement: Move preprocessing to initialization

See original GitHub issue

Feature details

The implementation of optimization methods via classes offers more advantages than are currently being used in PennyLane. The proposed refactor is to reduce the step and step_and_cost methods to their absolute minimum, as they are the part that is called repeatedly in optimizations. Other parts like preprocessing and validation of hyperparameters or the function to be optimized can be moved into the instantiation of the optimizer, if we move task-specific hyperparameters and the function input from step to __init__. The main restriction would be that an optimizer instance can not be reused for several cost functions. This is not too severe, however, as we can implement a method to allow for easy copying of an instance. The overhead in (rather rare) cases where this reusing for multiple cost functions is required seems to be much smaller than the overhead currently affecting all users by performing validation and similar steps at every iteration.

This refactor moved optimizers closer to stateful entities, which seems like a good fit to me, in particular for optimizers that use data from previous steps as bias/surrogate data (think reusing the metric tensor in QNGOptimizer) or inherently have a memory (like BFGS-type optimizers).

Implementation

Move validation steps and cost function input from step/step_and_cost to __init__ of optimizers.

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

Happy to work on this.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dwierichscommented, Aug 20, 2021

Yes, exactly. Accounting for the fact that the several steps should update the last parameters, change the last line to

    params = opt.step(params, **cost_kwargs)

Note that if we give a num_steps hyperparameter to GradientDescentOptimizer we also could do

params = np.random([2, 3], requires_grad=True)
opt = qml.GradientDescentOptimizer(cost_fn, lr=0.1, num_steps=100, **hyperparameters)
new_params = opt.optimize(params, **cost_kwargs)

making a full optimization readily available without users having to write a loop.

0reactions
mariaschuldcommented, Aug 25, 2021

Great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Neural Network Optimization - Towards Data Science
Pre-Initialization​​ The technique involves importing the weights of an already trained network (such as VGG16) and using these as the initial ...
Read more >
Transfer learning and fine-tuning | TensorFlow Core
This can potentially achieve meaningful improvements, by incrementally adapting the pretrained features to the new data.
Read more >
Lecture 7 | Training Neural Networks II - YouTube
We also discuss transfer learning and finetuning. Keywords: Optimization, momentum, Nesterov momentum, AdaGrad, RMSProp, Adam, second-order ...
Read more >
Best Tools for Model Tuning and Hyperparameter Optimization
All your tools in one place, so you can move easily from data preprocessing, to model building and model deployment, all in one...
Read more >
Initializing Bayesian Hyperparameter Optimization via Meta ...
initialization procedure yields mild improvements for low- ... algorithm selection and hyperparameter optimization problem. ... preprocessing method.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found