Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Solving errors in AvgPool3d and Maxpool3d Implementations #119

Merged
merged 12 commits into from
May 19, 2019

Conversation

Shashi456
Copy link
Contributor

the error inherently is :

error: cannot convert value of type '(Int, Int, Int, Int, Int)' to expected argument type '(Int, Int, Int, Int)'
        return input.maxPooled(kernelSize: poolSize, strides: strides, padding: padding)

I'm still working on how to solve it, Any suggestions are welcome :).

@Shashi456
Copy link
Contributor Author

This should not have been merged because it does not compile. The self.init statement cannot appear on top level.

@rxwei solved this comment.

@Shashi456
Copy link
Contributor Author

@jekbradbury @dan-zheng you mentioned in these comments about how maxPooled should probably be changed to a more abstract implementation. This compilation does throw an error because maxPooled is defined in (int, int, int, int) . Should i try to add an additional definition for maxpooled3d or is there any way to abstract the main maxpooled vjp

@dan-zheng dan-zheng requested review from dan-zheng, rxwei and jekbradbury and removed request for dan-zheng May 10, 2019 00:04
Copy link
Member

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

Thank you for fixing the errors!

@dan-zheng
Copy link
Member

@jekbradbury @dan-zheng you mentioned in these comments about how maxPooled should probably be changed to a more abstract implementation. This compilation does throw an error because maxPooled is defined in (int, int, int, int) . Should i try to add an additional definition for maxpooled3d or is there any way to abstract the main maxpooled vjp

Good catch! I wouldn't worry about those comments for now, actually.

Eventually, we should probably change APIs liked maxPooled and convolved2D to take 2 less stride/size arguments (e.g. so that convolved2D takes strides as (Int, Int) instead of (Int, Int, Int, Int)).

It would be good to implement that in a separate dedicated patch.

@Shashi456
Copy link
Contributor Author

@dan-zheng, swift build still throws this error :

error: cannot convert value of type '(Int, Int, Int, Int, Int)' to expected argument type '(Int, Int, Int, Int)'
        return input.maxPooled(kernelSize: poolSize, strides: strides, padding: padding)

and I think we might have to create some sort of fix in this patch itself. I'm still wrapping my head around the error, but it makes sense since the vjp is written for (Int, Int, Int, Int) and not a higher dimension

@dan-zheng
Copy link
Member

@dan-zheng, swift build still throws this error :

error: cannot convert value of type '(Int, Int, Int, Int, Int)' to expected argument type '(Int, Int, Int, Int)'
        return input.maxPooled(kernelSize: poolSize, strides: strides, padding: padding)

and I think we might have to create some sort of fix in this patch itself.

Aha, I see. The current maxPooled method is really maxPooled2D, and averagePooled is really averagePooled2D. As you observed, to implement AvgPool3D and MaxPool3D layers, it's necessary to first implement averagePooled3D and maxPooled3D methods.

averagePooled3D and maxPooled3D should be defined in Operators.swift. They should respectively call Raw.avgPool3D and Raw.maxPool3D, and their VJPs should respectively call Raw.avgPool3DGrad and Raw.avgPool3DGrad. (Raw operators are defined here.) The current averagePooled and maxPooled should be renamed to averagePooled2D and maxPooled2D.

Would you like to take this on? 🙂

@Shashi456
Copy link
Contributor Author

@dan-zheng I will try, hope you help in debugging if i have doubts xD

@Shashi456
Copy link
Contributor Author

@dan-zheng can you please review? sorry for the delay!

Copy link
Member

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

The VJPs for averagePooled2D/3D and maxPooled2D/3D look good!

You also need to rename averagePooled and maxPooled to averagePooled2D and maxPooled2D and add averagePooled3D and maxPooled3D in the same file (Operators.swift). I don't believe the code currently compiles - could you please compile locally before committing code, to make sure it works?

Let us know if you have questions!

@Shashi456
Copy link
Contributor Author

@dan-zheng i'm just getting this final error in the build, i don't know what to make of it.
image

@dan-zheng
Copy link
Member

I'll take a look today Pawan. Thanks for your patience!

@Shashi456
Copy link
Contributor Author

@dan-zheng is there any sort of rough roadmap for swift-apis i could look at?

@rxwei
Copy link
Contributor

rxwei commented May 18, 2019

An ongoing plan is to finish #54, and the list of layers you provided there is great to follow!

API folks on the Swift for TensorFlow team (including @dan-zheng and myself) have been recently working on language/compiler enhancements (e.g. automatic differentiation). Once we finish the AD control flow work by the end of May, we'll be able to simplify this library by dropping most custom VJPs.

Meanwhile, @eaplatanios and @pschuh are driving #109, which is moving all tensor APIs from apple/swift into this repository. When that's finished, we will be able to iterate faster and improve the tensor library along with layers/optimizers that depend on them.

@Shashi456
Copy link
Contributor Author

@rxwei thats amazing! With this PR and #75 we will be done with pooling layer implementations, from a usage point of view I guess the recurrent layers are the ones remaining. hope to keep contributing more :)

Minor formatting fixes.
Copy link
Member

@dan-zheng dan-zheng left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you Pawan!

@dan-zheng dan-zheng merged commit 76f5ee6 into tensorflow:master May 19, 2019
@Shashi456 Shashi456 deleted the zero branch May 23, 2019 05:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants