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

Fix JacobianTest and CustomJacobianTest (Resolves #3470) #3471

Merged
merged 1 commit into from
Apr 28, 2023

Conversation

mrdaybird
Copy link
Contributor

@mrdaybird mrdaybird commented Apr 10, 2023

Use output of the Forward method instead of input. Fixes #3470 (See issue for more details).

Copy link
Member

@rcurtin rcurtin left a comment

Choose a reason for hiding this comment

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

I think this is correct. At least, it passes all the tests, but, all layers tested with the Jacobian test do not use the first argument to Backward(). So what is needed is an audit: just need to look at all the layers, and see if they all use the convention that the first parameter to Backward() is the output from Forward(), not the input to Forward().

I'm not yet sure if this makes the Jacobian test succeed for the updated LogSoftMax implementation.

Copy link
Member

@rcurtin rcurtin left a comment

Choose a reason for hiding this comment

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

Went through and audited everything visually (quicker than I thought!).

  • With this change the Jacobian test for the updated LogSoftMax layer passes.
  • Many layers simply ignore the first parameter to Backward().
  • Several layers use the first parameter just to get the batch size (.n_cols).
  • A couple layers (HardTanH, LeakyReLU, PReLU) are such that Baclward() is correct regardless of whether the output from or input to Foward() is passed.
  • I'm not 100% sure of Softmax but it looks like it takes the output. A test will tell us, I guess.
  • The same is true of Softmin, but just glancing at the backward expression, I think it might be wrong. We'll find out when we apply a test, I guess.

I would definitely like to get these tests applied to all layers. I was surprised to see when I went through the tests that only Linear3D and LinearNoBias are tested with the Jacobian test in the tests/ann/layer/ directory

It could be useful in a follow-up PR to either clearly document what the first parameter to Backward() is, or change its name throughout the codebase, or both. I'm not sure what the best way forward there is.

@mrdaybird
Copy link
Contributor Author

Also to be noted, many activation functions incorrectly implement the Deriv(x, y) method, having the same mistake as the Backward method, consequently corresponding layers also have the incorrect Backward method.

I think I will make a list of all layers/functions which maybe have been incorrectly implemented, so that they can be fixed and additional tests(including the Jacobian test) be added along with the fix.

Copy link

@mlpack-bot mlpack-bot bot left a comment

Choose a reason for hiding this comment

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

Second approval provided automatically after 24 hours. 👍

@rcurtin
Copy link
Member

rcurtin commented Apr 28, 2023

Thanks again for finding this!

@rcurtin rcurtin merged commit a7cc156 into mlpack:master Apr 28, 2023
15 checks passed
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.

Incorrect usage of Backward method in JacobianTest
2 participants