Skip to content

Conversation

@annxingyuan
Copy link
Contributor

@annxingyuan annxingyuan commented Sep 3, 2020

This fixes #3357

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

@annxingyuan annxingyuan self-assigned this Sep 3, 2020
Copy link
Collaborator

@lina128 lina128 left a 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: :shipit: 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});

Copy link
Contributor Author

@annxingyuan annxingyuan left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: 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?

Copy link
Collaborator

@lina128 lina128 left a comment

Choose a reason for hiding this comment

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

LGTM!

Reviewable status: :shipit: 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. :)

@annxingyuan annxingyuan merged commit 4f4c2d3 into master Sep 4, 2020
@annxingyuan annxingyuan deleted the wasm_dts branch September 4, 2020 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsupported WASM kernel: DepthToSpace

3 participants