-
Notifications
You must be signed in to change notification settings - Fork 48
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
Type of some parameters should match the input data type #442
Comments
Agreed. This may seem like an inconsequential matter because float32 has such a wide range, but float32 cannot accurately represent int32 values over 16 million (all odd numbers get dropped to nearest even), and it will be exacerbated if we extend to larger types like int64. There have already been cases in ONNX models where special sentinel values were used like INT32_MAX which when converted to float32 lose their representation. 🤔 I wonder what the IDL would look like though? (I'm not that familiar with the IDL syntax in its murkier corners)
Should it use an |
Re: "Is there any sort of multi-valued scalar in JS IDL, like C++ union?" WebIDL has union types For now, my best suggestion is to accept In the future, you can do a union of Other options include using |
Re: |
Josh: Definite yes for infinity. NaN is more arguable, but they have their use (and many libraries have dedicated NaN testing operators - |
And quite related to this is the "fill sequence" |
FYI, I have a local change for this, but will wait for the PR queue to drain. I went with this definition: typedef (bigint or unrestricted double) MLNumber; And then use MLNumber for constant(value, type), constant(start, end, step, type) (see #571 and #492), MLClampOptions and MLPadOptions.
Bikeshedding on the name is welcome. :) |
@inexorabletash Yeah, I suppose it makes sense to just have a common numeric scalar type (rather than repeated definitions in each of the function prototypes) if we're going to be sharing this across multiple operators - clamp, pad, fill constant, fill sequence, diagonal matrix... I originally thought including "scalar" in the name would make sense, but then JS has a "Number" type, and so |
looks good! |
For some MLGraphBuilder methods the type of a numeric input can vary - e.g. for constant() an explicit MLOperandDataType is provided; for clamp() and pad() the data type is implied by input operands. In these cases, specifying the numeric value as either a float/double or int64 type runs into accuracy or range issues - you can't accurately represent all int64 values as a double, and you can't represent the full range of floats as int64. (You also can't represent all int64 values as an long long either - over 2^53 things get wierd. But that's a digression.) Per discussion in whatwg/webidl#1388 this change introduces a union between a bigint type and unrestricted double called MLNumber. Callers can pass a JS number (1234, 1.1234e38) or a JS bigint (9007199254740993n), and the implementation will treat it properly based on the explicit or implicit MLOperandDataType. Usage of this type should be limited to only those cases. Fixes webmachinelearning#442 Note that webmachinelearning#492 proposes changes to the constant sequential filling operation; this just adds IDL to match the current spec prose. Some of the concerns raised in webmachinelearning#325 are addressed (e.g. clamp()'s options). However, several other options are still specified as "float", and should maybe be "double" - but MLNumber is likely not appropriate for those, so they are not updated here.
pad(),
MLPadOptions::value
is float in current spec, which is used as padded value if theMLPadOptions::mode
is "constant", its type should exactly match the input data type, otherwise this may cause precision loss.(ONNX Pad-18 requires the input data and constant value (a single scalar input tensor) to be the same type T.)
clamp(),
MLClampOptions::minValue
andMLClampOptions::maxValue
, current spec states them as a float scalar.And for the v2 ops, we will also have to consider these: (thanks @fdwr for providing the list)
The text was updated successfully, but these errors were encountered: