Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix to PD3O with stochastic gradient optimisers #2043

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

MargaretDuff
Copy link
Member

@MargaretDuff MargaretDuff commented Jan 20, 2025

Changes

  • The algorithm will use the same approximate gradient in each iteration for SG, SAG and SAGA functions, f, in PD3O.
  • For SVRG and LSVRG functions in the second gradient calculation in each iteration, the code checks the data passes indices to see if a full gradient or an approximate gradient was used for the first gradient calculation. It then repeats the previous gradient calculation for the second gradient approximation (saving to a snapshot if a full gradient is calculated). It then pops the end of the stored data passes indices.
  • For other functions, there is no change to the PD3O behaviour.

Testing you performed

Please add any demo scripts to https://github.com/TomographicImaging/CIL-Demos/tree/main/misc

  • New unit tests added, checking data passes and data passes indices after a couple of iterations

Related issues/links

Closes #2021

Checklist

  • I have performed a self-review of my code
  • I have added docstrings in line with the guidance in the developer guide
  • I have updated the relevant documentation
  • I have implemented unit tests that cover any new or modified functionality
  • CHANGELOG.md has been updated with any functionality change
  • Request review from all relevant developers
  • Change pull request label to 'Waiting for review'

Contribution Notes

Please read and adhere to the developer guide and local patterns and conventions.

  • The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in CIL (the Work) under the terms and conditions of the Apache-2.0 License
  • I confirm that the contribution does not violate any intellectual property rights of third parties

@MargaretDuff MargaretDuff changed the title Bug fix to PD3O with SG, SAG and SAGA Bug fix to PD3O with stochastic gradient optimisers Jan 21, 2025
@MargaretDuff
Copy link
Member Author

@epapoutsellis - In SVRG/LSVRG if we calculate a full gradient snapshot, the results are stored and reused in future approximations. Do we want to store the results of the first or second gradient calculation in a PD3O loop? I presume the second?

@@ -125,7 +125,19 @@ def update(self):
self.g.proximal(self.x_old, self.gamma, out = self.x)

# update step
self.f.gradient(self.x, out=self.x_old)

if isinstance(self.f, (SVRGFunction, LSVRGFunction)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is strange that we need this only for SVRG/LSVRG. All the stochastic functions implement an approximate_gradient method which is called by the gradient method of the parent class. At least this is how I implemented. I do not think that gradient method is needed in LSVRG/SVRG.

Also, these lines can be moved in the parent gradient method.

At the end you will have an if/else statatement for ApproximateGradientSumFunction and Function classes to compute the approximate_gradient and the gradient respectively

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Vaggelis - I think we wrote SVRG and LSVRG like that, overwriting the gradient method of the parent class so that the sampler is not called if a full gradient snapshot is calculated. For example, if you are taking a full gradient every 2n iterations in SVRG and you are using a sequential sampler then the 0th subset will be used half as much as any other subset. By rewriting the parent class gradient method we ensure that the sampler is only ever called if an approximate gradient, not a snapshot, is needed.

Copy link
Contributor

@epapoutsellis epapoutsellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment about the methods in SVRG/LSVRG. No need to have both gradient and approximate_gradient methods in these functions.
For PD3O and stochastic functions is absolutely fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PD3O formulations and Stochastic Optimisation
2 participants