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

Add a Nevergrad Sweeper plugin #430

Merged
merged 72 commits into from
Mar 10, 2020
Merged

Conversation

jrapin
Copy link
Contributor

@jrapin jrapin commented Feb 20, 2020

Motivation

This is a proof of concept for a Nevergrad sweeper pluging.

I won't have time to work much on it so if anyone is willing to take it from there, feel free :D
The current concerns I have:

  • the documentation should be improved, in particular how to choose an optimizer. The simplest solution is "OnePlusOne" for now. It's incredibly simple and very robust, so I made it the default optimizer.
  • I don't have ideas for a nice commandline syntax. There are a lot of possible ways to define the parametrization of a problem in nevergrad (probably too many, then again, it's a research framework so we need some flexibility for now :s). I've included a hack to be able to use the full nevergrad syntax, but that won't be very robust :D . For now only choices and standard bounded scalars are supported without the hack, we would at least need a way to define log-distributed scalars.
  • the launchers seem to only support batches, I suppose there is no way to check if some evaluations have finished so that we could make use of the free workers and launch more evaluations without waiting? That could make the sweep faster, and as far as I know with close to no performance loss.
  • Minimizing on integers is probably not as robust as minimizing on floats, I'm a bit concerned that anyone writting 0:10 in the commandline would get integers only and may not realize it, maybe the default should be float, and we'd need another way to cast to integers.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Unit tests are included, as well as a runnable example

Related Issues and PRs

Closes #330

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 20, 2020
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Feb 20, 2020

This pull request introduces 1 alert when merging c5c92df into 4106845 - view on LGTM.com

new alerts:

  • 1 for Unused import

@omry
Copy link
Collaborator

omry commented Feb 20, 2020

This is awesome, thanks for taking the time to do this.
I will comment inline, but a few high level comments:

  1. Does nevergrad support maximization as well? it would be better to call this hydra_nevergrad_sweeper and add a configuration option allowing the user to maximize if they choose to.
  2. You have some left over mentions of Example (from example plugin in the docs and the code).
  3. CI is failing. looks like a simple lint issue (you can run ci lint locally with nox -s lint)
  4. I see some deprecation warnings I did not see before from cma

I did not take a close look at the rest of it, but overall it looks good and a great start.

cc @shagunsodhani, when you get some energy after the long Ax stretch - you might want to take this plugin on and polish it a bit.

@jrapin
Copy link
Contributor Author

jrapin commented Feb 21, 2020

  1. for maximizing you only need to inverse the output. In nevergrad I tend to limit the number of options so I do not include it directly there. In a configuration tool like this it however makes sense to allow both indeed, so it's now added.
  2. Should be gone now
  3. The lint error is gone, but isort and black are fighting each other on whether to add a skipped line or not when there is a comment within the imports... if you have a good solution against this I am curious, because this is a problem I've stumbled upon several time when trying this combination.
  4. the deprecation warning is from CMA https://github.com/CMA-ES/pycma (our CMA version is just a wrapper around this one), so not directly from nevergrad. Can't do much about it except submit a PR (which I will probably do soon) and encourage them to push a new version.

@omry
Copy link
Collaborator

omry commented Feb 21, 2020

  1. add nevergrad to .isort.cfg as a known third party.
    I need to do something about it, it's a repeating problem.
    Oh, and the released isort has an issue. can't remember if this one.
    I am using a version from the repo in my pre-commit:
repos:
  - repo: https://github.com/timothycrosley/isort
    rev: 'c54b3dd'
    hooks:
      - id: isort
  1. sounds good.

By the way, check this up:
omry/omegaconf#152

Coming to OmegaConf 2.0 near you soon. :)

@jrapin
Copy link
Contributor Author

jrapin commented Feb 21, 2020

The simplified syntax is more readable and less error prone so that will be nice ;)

  1. I've moved the comment to the top, I think that did the trick (I don't test locally because i'm on a mobile connection and I fear nox is redownloading everything, but it's probably cleverer and has some cache?)

  2. actually CMA is already patched, they just need to provide a new release

@omry
Copy link
Collaborator

omry commented Feb 21, 2020

Looking at your config reminded me of that idea.
I liked it so much that I couldn't resist and implemented already.
this is a breaking compatibility for people with dot in their keys, but there is an escape hatch (hehe).
I think it's very much worth it.

Re-download:
Not sure, I suspect it does have some cache.
I don't think you need the comment. (unless I am misunderstanding the purpose).
Once you add nevergrad as an known third party it black and isort should agree on it.

By the way: generally I use typing in Hydra by importing specific things:

from typing import Dict, Any, List

@jrapin
Copy link
Contributor Author

jrapin commented Feb 21, 2020

I don't think you need the comment. (unless I am misunderstanding the purpose).

it was there before so I did not dare remove it (google it it seemed it removes some checks)

I use typing in Hydra by importing specific things

I can change that if you want. FYI I was doing the same before in nevergrad, and I'm currently in the process of moving to import typing as tp after I had so many lines with 10 different typing imports, and I was spending a lot of time adding and removing from those lines whenever I was changing code :D

There seems to be some mypy errors. Some are not related to the plugin, but some do, including not finding nevergrad which I should investigate. I never actually checked that the the typing was packaged properly (supposedly it does since there is a py.typed file, but didnt verify).

@jrapin
Copy link
Contributor Author

jrapin commented Feb 21, 2020

So, the mypy issue is a bit weird to me. It does look like the py.typed file is correctly packaged (I have a hydra venv where I installed nevergrad from pypi, and the file is in the site-package), and my version of mypy seems to identify it well (I tried to include some non-existing import of nevergrad and it flagged it directly).

Can you see any reason why it would fail to find nevergrad in the CI?

@omry
Copy link
Collaborator

omry commented Feb 21, 2020

Comment:
We are talking about # noinspection PyUnresolvedReferences right?
It's for PyCharm. it's supposed to be above this block:

# noinspection PyUnresolvedReferences
from hydra.test_utils.test_utils import TSweepRunner, sweep_runner  # noqa: F401

Import typing as tp:
See what you are saying, let's keep it consistent with the rest of Hydra. I will consider your suggestion to do it this way.

py.typed:
did you try a local repro with nox -s lint?

Looking at the lint in the noxfile, it does not install the plugins (so the dependencies are not installed as well).
I am a bit confused as to why other plugins like joblib are also not facing the same issue.

@jrapin
Copy link
Contributor Author

jrapin commented Feb 21, 2020

did you try a local repro with nox -s lint?

I'm still avoiding it given the mobile connection

I am a bit confused as to why other plugins like joblib are also not facing the same issue.

Got it :D from joblib import Parallel, delayed # type: ignore
Basically, I suppose this imports them as Any and then everything works. I can do the same trick but that's probably not an effective typing :D Plugins (or at least their dependencies) should be installed (or use mypy --ignore-missing-imports or whitelist ignored imports in mypy.ini). Let me know what you prefer.

See what you are saying, let's keep it consistent with the rest of Hydra. I will consider your suggestion to do it this way.

That's your call, I'll update it (took me a year to change to import typing as tp, let's talk about it in a year :D)

We are talking about # noinspection PyUnresolvedReferences right? It's for PyCharm. it's supposed to be above this block.

Yes. Does it have to be exactly the line above? If so then I'm stuck with the isort/black incompatibility. If not I keep it on the very top and everything is fine

@jrapin
Copy link
Contributor Author

jrapin commented Mar 6, 2020

While testing the mac situation, I ran into this failure which seems logical:
https://app.circleci.com/jobs/github/facebookresearch/hydra/10892

I've added a seed to avoid flakiness. I would have expected this should not happen often at all (I hoped never), too bad :(

@omry
Copy link
Collaborator

omry commented Mar 6, 2020

While testing the mac situation, I ran into this failure which seems logical:
https://app.circleci.com/jobs/github/facebookresearch/hydra/10892

I've added a seed to avoid flakiness. I would have expected this should not happen often at all (I hoped never), too bad :(

It's not too bad. I think some randomness is those algorithms by default is actually a good thing. locking the test with a seed seems like a good solution to me.

Comment on lines 89 to 90
The output of a run looks like:
The initialization of the sweep and the first 5 evaluations (out of 100) look like this:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two lines with:
colon seems weird:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed one of them which should not have been there

```

The application `main` returns a float which we want to minimimize, the minimum is 0 and reached for:
The the function decorated with `@hydra.main()` returns a float which we want to minimize, the minimum is 0 and reached for:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should mention how to maximize somewhere in the readme.
Maybe as a commented out line in the config node above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added to the conf

Copy link
Contributor Author

@jrapin jrapin left a comment

Choose a reason for hiding this comment

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

I feel it's mostly done now.
There must be some corner cases but I expect that will be solved when we agree on the inputs

```

The application `main` returns a float which we want to minimimize, the minimum is 0 and reached for:
The the function decorated with `@hydra.main()` returns a float which we want to minimize, the minimum is 0 and reached for:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added to the conf

@yangshun yangshun requested review from yangshun and removed request for yangshun March 10, 2020 09:08
@omry
Copy link
Collaborator

omry commented Mar 10, 2020

Landing it (without even taking final final look).
We will continue to evolve and update it as the common interface is maturing.

Thanks for all your work on this @jrapin.

@omry omry merged commit 0bfb4f4 into facebookresearch:master Mar 10, 2020
@jrapin jrapin deleted the minimizer branch March 11, 2020 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nevergrad sweeper plugin
5 participants