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 polynomial_decay and piecewise_decay #8013

Merged

Conversation

jacquesqiao
Copy link
Member

@jacquesqiao jacquesqiao commented Jan 31, 2018

project: #7769
This PR will go on after switch_op #8031 is done.

@jacquesqiao jacquesqiao changed the title [wip]Add piecewise constant decay [wip]Add polynomial_decay Jan 31, 2018
@jacquesqiao jacquesqiao changed the title [wip]Add polynomial_decay Add polynomial_decay Jan 31, 2018
end_learning_rate=0.0001,
power=1.0,
cycle=False):
"""Applies inverse time decay to the initial learning rate.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be Applies polynomial decay to the initial learning rate.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok~

@jacquesqiao jacquesqiao changed the title Add polynomial_decay Add polynomial_decay and piecewise_decay Feb 6, 2018
zero_var = layers.fill_constant(shape=[1], dtype='float32', value=0.0)
one_var = layers.fill_constant(shape=[1], dtype='float32', value=1.0)

with layers.Switch() as switch:
Copy link
Member

Choose a reason for hiding this comment

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

So, our switch operator only support scalar condition now? And our if-else operator support vector condition.

Copy link
Member Author

@jacquesqiao jacquesqiao Feb 8, 2018

Choose a reason for hiding this comment

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

yes, the current switch operator only supports scalar condition. because it uses conditional_block, it's easy to support tensor as input in the future.

Args:
learning_rate: A scalar float32 value or a Variable. This
will be the initial learning rate during training
global_step: A Variable that record the training step.
Copy link
Member

Choose a reason for hiding this comment

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

So, where is the global_step variable created?

Copy link
Member Author

Choose a reason for hiding this comment

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

should be create outside optimizer. like

    global_step = fluid.layers.create_global_var(shape=[1], value=0, dtype='float32', force_cpu=True)
    sgd_optimizer = fluid.optimizer.SGD(
        learning_rate=fluid.learning_rate_decay.exponential_decay(
            learning_rate=0.0001,
            global_step=global_step,
            decay_steps=100000,
            decay_rate=0.5,
            staircase=True),
        global_step=global_step)

Copy link
Member

Choose a reason for hiding this comment

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

If global_step variable is force cpu, does decay_steps also force cpu?

@@ -975,6 +976,36 @@ def less_than(x, y, cond=None, **ignored):
return cond


def equal(x, y, cond=None, **ignored):
Copy link
Member

Choose a reason for hiding this comment

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

Equal is a element-wise operator. And it also can be override in Python.

def __eq__(self):
    ...

Copy link
Member

@QiJune QiJune Feb 8, 2018

Choose a reason for hiding this comment

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

I find that our equal is not like python eq. Python eq will return a bool, but our equal will return a vector.

Copy link
Member

@QiJune QiJune left a comment

Choose a reason for hiding this comment

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

LGTM!

@jacquesqiao jacquesqiao merged commit 5cc2f0b into PaddlePaddle:develop Feb 8, 2018
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.

3 participants