-
Notifications
You must be signed in to change notification settings - Fork 2k
[wasm] Add depthToSpace kernel. #3877
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
Conversation
lina128
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Ann, LGTM. I only left two minor comments.
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @annxingyuan, @lina128, @pyu10055, and @tafsiri)
tfjs-backend-wasm/src/kernels/DepthToSpace.ts, line 41 at r1 (raw file):
} function depthToSpace(args: {
export function.
So basically every kernel should export a function and a config. Other kernels can import the function directly without importing the config. The function has specific typing, whereas the KernelFunc in config has more generic typing (i.e. DepthToSpaceInputs vs. NamedTensorMap), so for other kernels that use this function, importing function instead of config.kernelFunc actually helps type check.
tfjs-backend-wasm/src/kernels/DepthToSpace.ts, line 57 at r1 (raw file):
const inputHeight = (dataFormat === 'NHWC') ? x.shape[1] : x.shape[2]; const inputWidth = (dataFormat === 'NHWC') ? x.shape[2] : x.shape[3]; const inputDepth = (dataFormat === 'NHWC') ? x.shape[3] : x.shape[1];
Can we add these validation check of the computed fields above? cpu and webgl also needs to add these once kernels are modularized, and then these check should be removed from the depthToSpace op.
util.assert(
inputHeight * blockSize >= 0,
() => Negative dimension size caused by overflow when multiplying ${inputHeight} and ${blockSize} for depthToSpace with input shape ${$x.shape});
util.assert(
inputWidth * blockSize >= 0,
() => Negative dimension size caused by overflow when multiplying ${inputWidth} and ${blockSize} for depthToSpace with input shape ${$x.shape});
util.assert(
(inputDepth % (blockSize * blockSize) === 0),
() => Dimension size must be evenly divisible by ${ blockSize * blockSize} but is ${ inputDepth} for depthToSpace with input shape ${$x.shape});
annxingyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @lina128, @pyu10055, and @tafsiri)
tfjs-backend-wasm/src/kernels/DepthToSpace.ts, line 41 at r1 (raw file):
Previously, lina128 (Na Li) wrote…
export function.
So basically every kernel should export a function and a config. Other kernels can import the function directly without importing the config. The function has specific typing, whereas the KernelFunc in config has more generic typing (i.e. DepthToSpaceInputs vs. NamedTensorMap), so for other kernels that use this function, importing function instead of config.kernelFunc actually helps type check.
Done
tfjs-backend-wasm/src/kernels/DepthToSpace.ts, line 57 at r1 (raw file):
Previously, lina128 (Na Li) wrote…
Can we add these validation check of the computed fields above? cpu and webgl also needs to add these once kernels are modularized, and then these check should be removed from the depthToSpace op.
util.assert(
inputHeight * blockSize >= 0,
() =>Negative dimension size caused by overflow when multiplying ${inputHeight} and ${blockSize} for depthToSpace with input shape ${$x.shape});util.assert(
inputWidth * blockSize >= 0,
() =>Negative dimension size caused by overflow when multiplying ${inputWidth} and ${blockSize} for depthToSpace with input shape ${$x.shape});util.assert(
(inputDepth % (blockSize * blockSize) === 0),
() =>Dimension size must be evenly divisible by ${ blockSize * blockSize} but is ${ inputDepth} for depthToSpace with input shape ${$x.shape});
Hi Na, sorry if we went through this already - did we decide that all of these validations should move to modularized kernels?
lina128
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @annxingyuan, @lina128, @pyu10055, and @tafsiri)
tfjs-backend-wasm/src/kernels/DepthToSpace.ts, line 57 at r1 (raw file):
Previously, annxingyuan (Ann Yuan) wrote…
Hi Na, sorry if we went through this already - did we decide that all of these validations should move to modularized kernels?
Ah, you are right, I thought it is validating transformed values, but it is actually validating raw value. Never mind. :)
This fixes #3357
To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.
This change is