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

Parameter Optimization #433

Merged
merged 11 commits into from
May 21, 2019
Merged

Parameter Optimization #433

merged 11 commits into from
May 21, 2019

Conversation

ctrl-z-9000-times
Copy link
Collaborator

This program finds good parameters for an HTM system.

I wrote this program a while ago, and now I'd like to contribute it.

This is a large addition, and it is not ready yet. I do not recommend reviewing the code, instead just read the documentation at the top of the file.

This program finds good parameters for an HTM system.
@breznak
Copy link
Member

breznak commented May 8, 2019

This program finds good parameters for an HTM system.

hey, this is a huge and much welcome contribution! 💯
It's neeeded for everyday practical usecases, #391 , and Hotgym, where our TM has insufficient representation (I don't know if there's an issue for that).

Sorry, I'll get later to review, even just to read the doc.

Some high-level thoughts about parameter optimization/tuning:

  • I don't know if this should be in this repo, or rather stand-alone nupic.swarming ?
    • that way, other projects can also benefit
    • we'd still ensure OUR API is supported.
  • can we properly transform/describe our model parameters and leave the optimization to 3rd party tools (scikitlearn,...)?
  • see Numenta Anomaly Benchmark #205 for my comment about OPF support, that does the same thing.
    • I guess your code has cleaner implementation
    • but OPF has a popular (?) API which we said to support?
  • if the code is working, I'd like to merge it ASAP, with potential future rework/obsoletion.

py/src/nupic/optimization/ae.py Show resolved Hide resolved
ExperimentModule.main(parameters=default_parameters, argv=None, verbose=True)
Returns (float) performance of parameters, to be maximized.

Usage: $ ae.py [ae-arguments] ExperimentModule.py [experiment-arguments]
Copy link
Member

Choose a reason for hiding this comment

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

can you provide a runnable demo example? That would be worth 1000 words for first-timers wishing to use the code.
MNIST would be an ideal candidate and you've already optimized that code for me once, so you should have the "experiment" files ready.

return best.parameters


class GridSearch(object):
Copy link
Member

Choose a reason for hiding this comment

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

do you need to write the hyper param optimization code yourself? It is available in many toolkits?
https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html

import tempfile
import multiprocessing
import resource
import signal # Probably not X-platform ...
Copy link
Member

Choose a reason for hiding this comment

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

would this be a problem? but hey..worst case, the feature will be avail only for certain OSs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I looked this up, This use of signal can be replaced with multithreading.timer which is X-platform.


from .nupic.optimization.parameter_set import ParameterSet

class ParticleSwarmOptimizations:
Copy link
Member

Choose a reason for hiding this comment

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

I do really like the recent changes! 👏 , extracting the particular search mechanism away, and adding the new PSO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

extracting the particular search mechanism away

This turned out to be more problematic than I expected. Each search method needs:

  1. Command line arguments
  2. Queue experiments
  3. Collect results, asynchronously from the queuing them

Currently it can only queue experiments. I'm thinking about how to do all of this in a sane way that allows for new methods to plug-in. I might make a new interface class to help with this.

Copy link
Member

Choose a reason for hiding this comment

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

have you considered the 3rd party for param optimization, model selection? And "just" write enabling interface for our params & constructors?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://www.khronos.org/nnef

I don't think this framework is useful, it's all about sharing trained deep learning networks.

https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html

Scikit learn appears very limited.

  • The only search method it has is GridSearch. It does not do swarming.
  • I also want the parameter optimization code to save all of the outputs of the program. Which scikitlearn doesn't do.

Copy link
Member

Choose a reason for hiding this comment

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

agreed on NNEF

Scikit learn appears very limited.

it was only a first hit I got from memory, these "python parameter optimization frameworks" look interesting:
https://hyperopt.github.io/hyperopt/
https://optuna.org/
I do like your solution, but in the longrun I hope we'll have an interface to a 3rd party project, as there's lots of details which are out of scope for us (same as Serialization, ..)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

have an interface to a 3rd party project, as there's lots of details which are out of scope for us

I understand, I will do some more research into existing solutions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

3rd party solutions

I found a great project, it's called nni. It is a framework for optimizing artificial neural networks (the non-biological kind). I read through it and attempted (but ultimately failed) to run the MNIST example with it.

  • Its open source (MIT license) so we could easily incorporate it into our project.
  • It's run by microsoft, and they appear to be actively developing it. They accept external PR's and they might even fix issues we have with it.
  • It is well designed. It's got some neat features too.

All that praise said, I don't think it's ready for mainstream use. It's rough at the edges. The project is about a year old. In a year this could be the defacto standard tool, but today I'd rather keep using my tools which I'm familiar with.

Copy link
Member

Choose a reason for hiding this comment

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

I found a great project, it's called nni.

I like NNI! although the whole AutoML seems overkill for us (we don't need network architecture "evolution", as we have HTM, we "just" need a way for param optimization.

I read through it and attempted (but ultimately failed) to run the MNIST example with it.

ok, let's go with what you have now. I would suggest not "wasting" time developing too many features, as long term we'd like to switch over to an external framework to do the work for us.

The current will be a great improvement, so let's 👍

PS: what have failed running their mnist? Do you think it's not ready yet, or should I try in some later PR?

Ideally, if you can take their (NNI or other suitable) design in mind, and develop the format for "experiment description" what you call it, similar/same, so we can later easily switch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PS: what have failed running their mnist?

I tried running our MNIST in their framework.

the format for "experiment description"

This is highly dependent on the specifics of the optimization framework.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will push the work i did for NNI in a branch so that you can play with it.

I think the problem i had is that NNI does not start by trying the default parameters. It spent a considerable amount of time trying parameters which obviously wont work. Swarming has an advantage over TPE (the search method nni defaults to) in that it starts near the default parameter values which are at least sane. The NNI framework has a way to end trials/experiments early if they obviously arent working, but i didnt use it.

@dkeeney
Copy link

dkeeney commented May 13, 2019

This is really cool. 🥇

@ctrl-z-9000-times
Copy link
Collaborator Author

I don't know if this should be in this repo, or rather stand-alone nupic.swarming ?
that way, other projects can also benefit

While i think thats a good idea, i dont want to deal with the logistics of having two repos and a depenency. Maybe for now we can keep this here, and reconsider the location later when we also reconsider the alternatives?

@ctrl-z-9000-times
Copy link
Collaborator Author

ctrl-z-9000-times commented May 17, 2019

I finished my review. The documentation still needs work before this can merge.
EDIT: I added some more documentation.
I added a lot of TODO notes for issues/bugs and feature requests.

@ctrl-z-9000-times ctrl-z-9000-times marked this pull request as ready for review May 18, 2019 05:28
The process pool that comes with python standard library does not
always work very well, and does not give the caller enough control
to fix problems with it.
Copy link
Member

@breznak breznak left a comment

Choose a reason for hiding this comment

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

This looks very good now! 👍
I'm looking forward to using this new feature.

One TODO: I'd like to see an example how this is used on either of hotgym/mnist, if that is not already part of #480 ?

'synPermConnected': 0.422,
'synPermInactiveDec': 0.005
'boostStrength': 7.80643753517375,
'columnDimensions': (35415,),
Copy link
Member

Choose a reason for hiding this comment

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

OT: I wonder how much the scores differ? It's said HTM is/should be more resistant to param changes. These seem like a rather big difference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IIRC accuracy improved from about 90% to 96%.

self.save() # Write the updated Lab Report to file.


class Worker(Process):
Copy link
Member

Choose a reason for hiding this comment

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

nit, do you want to split some of these to separate classes?

@breznak breznak merged commit b5e6d95 into master May 21, 2019
@breznak breznak deleted the ae branch May 21, 2019 12:25
@ctrl-z-9000-times
Copy link
Collaborator Author

Thanks for reviewing this!

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

Successfully merging this pull request may close these issues.

3 participants