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

[tune] Tweak/allow nested pbt mutations #3455

Merged

Conversation

hartikainen
Copy link
Contributor

@hartikainen hartikainen commented Dec 2, 2018

What do these changes do?

Changes the population-based training exploration to allow nested mutations

Related issue number

Closes #3412

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/9697/
Test FAILed.

new_config.update({
key: explore(
config[key], mutations[key],
resample_probability, custom_explore_fn)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we pass a no-op custom_explore_fn here? It might be weird to be invoking that at multiple levels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense not to invoke the custom preturbation function at every level. But instead of passing a no-op, I believe we should pass the custom_explore_fn as is but only invoke it at the last level? What do you think?

@ericl
Copy link
Contributor

ericl commented Dec 4, 2018 via email

@hartikainen
Copy link
Contributor Author

hartikainen commented Dec 4, 2018 via email

@hartikainen
Copy link
Contributor Author

Changed. I still need to test this in practice.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/9789/
Test FAILed.

Copy link
Contributor

@ericl ericl left a comment

Choose a reason for hiding this comment

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

LGTM!

@richardliaw
Copy link
Contributor

Hey @hartikainen, just ping us when you get the chance to try this out and remove the wip, so we can merge it.

@ericl
Copy link
Contributor

ericl commented Dec 13, 2018

Looks like a py2 failure:


=================================== FAILURES ===================================
______________ PopulationBasedTestingSuite.testPerturbationValues ______________
self = <trial_scheduler_test.PopulationBasedTestingSuite testMethod=testPerturbationValues>
    def testPerturbationValues(self):
        def assertProduces(fn, values):
            random.seed(0)
            seen = set()
            for _ in range(100):
                seen.add(fn()["v"])
            self.assertEqual(seen, values)
    
        # Categorical case
        assertProduces(
            lambda: explore({"v": 4}, {"v": [3, 4, 8, 10]}, 0.0, lambda x: x),
            {3, 8})
        assertProduces(
            lambda: explore({"v": 3}, {"v": [3, 4, 8, 10]}, 0.0, lambda x: x),
            {3, 4})
        assertProduces(
            lambda: explore({"v": 10}, {"v": [3, 4, 8, 10]}, 0.0, lambda x: x),
            {8, 10})
        assertProduces(
            lambda: explore({"v": 7}, {"v": [3, 4, 8, 10]}, 0.0, lambda x: x),
            {3, 4, 8, 10})
        assertProduces(
            lambda: explore({"v": 4}, {"v": [3, 4, 8, 10]}, 1.0, lambda x: x),
            {3, 4, 8, 10})
    
        # Continuous case
        assertProduces(
            lambda: explore(
                {"v": 100}, {"v": lambda: random.choice([10, 100])}, 0.0,
                lambda x: x),
            {80, 120})
        assertProduces(
            lambda: explore(
                {"v": 100.0}, {"v": lambda: random.choice([10, 100])}, 0.0,
                lambda x: x),
            {80.0, 120.0})
        assertProduces(
            lambda: explore(
                {"v": 100.0}, {"v": lambda: random.choice([10, 100])}, 1.0,
                lambda x: x),
            {10.0, 100.0})
    
        def deep_add(seen, new_values):
            for k, new_value in new_values.items():
                if isinstance(new_value, dict):
                    if k not in seen:
                        seen[k] = {}
                    seen[k].update(deep_add(seen[k], new_value))
                else:
                    if k not in seen:
                        seen[k] = set()
                    seen[k].add(new_value)
    
            return seen
    
        def assertNestedProduces(fn, values):
            random.seed(0)
            seen = {}
            for _ in range(100):
                new_config = fn()
                seen = deep_add(seen, new_config)
            self.assertEqual(seen, values)
    
        # Nested mutation and spec
        assertNestedProduces(
            lambda: explore(
                {
                    "a": {
                        "b": 4
                    },
                    "1": {
                        "2": {
                            "3": 100
                        }
                    },
                },
                {
                    "a": {
                        "b": [3, 4, 8, 10]
                    },
                    "1": {
                        "2": {
                            "3": lambda: random.choice([10, 100])
                        }
                    },
                },
                0.0,
                lambda x: x),
            {
                "a": {
                    "b": {3, 8}
                },
                "1": {
                    "2": {
                        "3": {80, 120}
                    }
                },
            })
    
>       custom_explore_fn = unittest.mock.MagicMock(side_effect=lambda x: x)
E       AttributeError: 'module' object has no attribute 'mock'
python/ray/tune/test/trial_scheduler_test.py:806: AttributeError

@richardliaw richardliaw changed the title [WIP] Tweak/allow nested pbt mutations [tune] Tweak/allow nested pbt mutations Dec 20, 2018
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10193/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10194/
Test FAILed.

@hartikainen hartikainen force-pushed the tweak/allow-nested-pbt-mutations branch 2 times, most recently from 93f491b to c8ab02a Compare December 22, 2018 00:12
@hartikainen hartikainen force-pushed the tweak/allow-nested-pbt-mutations branch from c8ab02a to 5eef7eb Compare December 22, 2018 00:13
@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10277/
Test FAILed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/10278/
Test FAILed.

@hartikainen
Copy link
Contributor Author

Sorry for the delay with this one. I tested this on my end, and the nesting works fine!

@hartikainen
Copy link
Contributor Author

@richardliaw thanks for updating the test mocks!

@richardliaw
Copy link
Contributor

Oops, this fell off the radar.

No problem; thanks for the contribution!

@richardliaw richardliaw merged commit 747b117 into ray-project:master Jan 4, 2019
@hartikainen hartikainen deleted the tweak/allow-nested-pbt-mutations branch January 4, 2019 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants