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

Default axis being 1 of batchNormalization operation is invalid for 1D input tensor #307

Open
BruceDai opened this issue Dec 8, 2022 · 5 comments

Comments

@BruceDai
Copy link
Contributor

BruceDai commented Dec 8, 2022

The input of batchNormalization operation would be ND tensor, when it's 1D tensor, the axis as a long scalar would be 0 or -1, it couldn't be 1, right?

And current three operations use axis which are of the same long type, but explanations for axis value are not enough clear, and could axis of concat be negative value?

Op Axis Type Value description
batchNormalization axis is an option of the optional options parameter long When it’s not specified, the default value is 1.When input is a 4-D tensor of the "nchw" or "nhwc" layout, options.axis should be set to 1 or 3 respectively.
concat axis is the second parameter long with the value in the interval [0, N) where N is the rank of all the inputs
split axis is an option of the optional options parameter long Default to 0. A negative value is interpreted as counting back from the end

@huningxin @wchao1115 PTAL, thanks.

@fdwr
Copy link
Collaborator

fdwr commented Dec 9, 2022

Yeah, a default axis = 1 value would be invalid for a 1D input tensor.

@wchao1115
Copy link
Collaborator

I don't understand how a batchNormalization input can be 1D. I think the wording can probably be improved to be more explicit but ND generally implies not 1D in most other specs.

@fdwr
Copy link
Collaborator

fdwr commented Dec 9, 2022

1D tensors are valid in ONNX BatchNormalization-15. "The op also accepts single dimension input of size N in which case C is assumed to be 1". In 1D, elements are normalized across batches (no spatial dimensions), applying Y = (X - input_mean) / sqrt(input_var + epsilon) * scale + B for each 1D element. I think we should just treat it the same way here, and require an explicit axis (0 or -1) since the default value of 1 is in inappropriate.

huningxin added a commit to huningxin/webnn that referenced this issue Mar 4, 2023
1. Leave the fix of webmachinelearning#307 to a separate PR
2. Refine MLTransposeOptions.permutation and MLSliceOptions.axes with examples
dontcallmedom pushed a commit that referenced this issue Mar 27, 2023
1. Leave the fix of #307 to a separate PR
2. Refine MLTransposeOptions.permutation and MLSliceOptions.axes with examples
@inexorabletash
Copy link
Member

Enumerating options:

  1. Leave [EnforceRange] unsigned long axis = 1; in the IDL; if the input's rank is 1 then implicitly {axis: 0} must be specified by the caller, otherwise it's an error. This is the behavior specified today, so no spec change needed.
  2. Change the IDL to [EnforceRange] unsigned long axis; removing the default value in the IDL, and add a default via prose e.g. "If options.axis does not exist, then set options.axis to 1 if input's rank is 2 or greater, or 0 otherwise"
  3. Change the IDL to make axis a positional argument instead of an option; caller must specify.

Any preferences?

@zolkis
Copy link
Collaborator

zolkis commented Apr 29, 2024

Option 2 sounds like the best way to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants