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

'clipping_threshold' LSTM parameter same at 'clip_gradient' Caffe parameter? #18

Closed
aurotripathy opened this issue Aug 15, 2016 · 7 comments

Comments

@aurotripathy
Copy link

aurotripathy commented Aug 15, 2016

@junhyukoh

I'm porting your simple LSTM example to the Caffe mainline tree. As expected some keywords and parameters are different as the implementations were independently developed.

My question is about the clipping_threshold parameter.
In your lstm implementation, I see (in the backward lstm computation):

      // Clip deriviates before nonlinearity
      if (clipping_threshold_ > Dtype(0.)) {
        caffe_bound(4*H_, pre_gate_diff_t, -clipping_threshold_,
            clipping_threshold_, pre_gate_diff_t);
      }

I don't see this in the caffe mainline code. Here, the clip_gradient is converted into a scale_factor.

Dtype scale_factor = clip_gradients / l2norm_diff;

Is it the same parameter? Does it have the same effect? Is one the scaled version of the other?

Could you help with your insight?

Thank you
Auro

@aurotripathy aurotripathy changed the title 'clipping_threshold' lstm parameter same at 'clip_gradient' LSTM parameter? 'clipping_threshold' LSTM parameter same at 'clip_gradient' caffe parameter? Aug 15, 2016
@aurotripathy aurotripathy changed the title 'clipping_threshold' LSTM parameter same at 'clip_gradient' caffe parameter? 'clipping_threshold' LSTM parameter same at 'clip_gradient' Caffe parameter? Aug 15, 2016
@junhyukoh
Copy link
Owner

I think they are different.
I followed Alex Graves' paper for gradient clipping.
The idea is to clip the individual dimension of the gradient separately.

As far as I know, the Caffe main code scales the whole gradient based on L2-norm.
In this case, the gradient direction is preserved.
I think this (scaling) is more widely used these days.

@aurotripathy
Copy link
Author

aurotripathy commented Aug 18, 2016

@junhyukoh
Thank you for the clarification.

I have yet to find the right 'clip_gradient' value with caffe mainline. I have tried values between 1 and 10 but they do not reproduce the signal as faithfully as your 'clipping_threshold' value (of 0.1).

Any guidance would be very valuable. I'm using the simple single-stack lstm signal following example.

Thank you.

p.s. do you think gradient bounding should be an option in addition to gradient scaling?

@junhyukoh
Copy link
Owner

Are you initializing the bias of the forget gate to some large positive value (say 5)?
This trick was very important to train RNNs for my toy experiments.

@aurotripathy
Copy link
Author

aurotripathy commented Aug 20, 2016

Thank you for looking into this.

Yes, that was very clear from the clockwork rnn paper (and your code). I've attached my entire python script. Kindly take a look.

solver.net.params['lstm'][1].data[15:30] = 5.0

train_toy_lstm.txt

The prototxt file below inputs the data in the 'proper' Caffe way. (T x N x 1)

toy_lstm.txt

@soulslicer
Copy link

soulslicer commented Mar 6, 2018

Did you solve this? What do I use in place of clip_gradients: 0.1 ? Are you able to share the code which you used?

Also could you share your test solver for the toy example?

@aurotripathy

@aurotripathy
Copy link
Author

aurotripathy commented Mar 6, 2018 via email

@soulslicer
Copy link

soulslicer commented Mar 6, 2018

Ic, I have implemented the test model as well following your example. The training loss looks to be reducing as well. However, when I run it, the prediction always gives the same output. I am not sure why this is the case.

If you have any ideas why that might occur, I would like to know. The the lstm_deploy model, I merely changed the shape from 320 to 2

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

No branches or pull requests

3 participants