-
Notifications
You must be signed in to change notification settings - Fork 49
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
Specifies scalar values casted to match input type. #678
Comments
Relevant:
|
Here's one way this could be specified, using linear() as an example.
And then add a definition of cast like:
With caveats:
dictionary MLLinearFloat32Options {
float alpha = 1;
float beta = 1;
};
dictionary MLLinearFloat16Options {
half alpha = 1; // this type doesn't actually exist
half beta = 1; // this type doesn't actually exist
};
partial interface MLGraphBuilder {
MLOperand linearFloat32(MLOperand input, optional MLLinearFloat32Options options = {});
MLOperand linearFloat16(MLOperand input, optional MLLinearFloat16Options options = {});
}; ... which is probably more relevant for integer types, because IDL+JS have well defined if sometimes surprising behavior here. See #489 for discussion about casting within backends, but at least at the IDL/interface level we should behave predictably. |
More notes:
|
Also, what conversion options would we use for these? Specifically:
This sounds like #489 but that issue is specifically about the casting operator, which might depend on the underlying platform. This issue is talking about the JS interface which is going to be implemented by the user agent. |
- Introduce a "cast" definition that takes a number and a type, and returns the number cast to that type. - Invoke cast during MLOperand and MLActivation creation. TODO: - Passing restrictions - Floating point - allow Infinities/NaNs or not? - Integer - throw or clamp if out of range? - Simplify supported restrictions - resample2d sizes option - is this part of the op data or not?
And then a further note for consideration: if we're being explicit about casting everywhere, are there any places that are currently This is fairly moot as all of the relevant ops accept only floating point inputs, so whatever the developer supplies will be ultimately cast to a float32 or float16, and so specifying the input as |
Unsorted notes from internal discussion w/ @a-sully and @philloooo: For batchNorm's epsilon.
And:
So overall, the "cast parameters to the same data type as the input tensors" approach may be okay and likely the least surprising for developers even if the result gets upcast (e.g. fp16 to fp32) again, but there's a lot of nuance to investigate. |
- Introduce a "cast" definition that takes a number and a type, and returns the number cast to that type. - Invoke cast during MLOperand and MLActivation creation. TODO: - Passing restrictions - Floating point - allow Infinities/NaNs or not? - Integer - throw or clamp if out of range? - Simplify supported restrictions - resample2d sizes option - is this part of the op data or not?
Some of the operations have scalar parameters, e.g. linear, gemm's
alpha
andbeta
.These are passed as
float
numbers. I think we should specify in the processing algorithm that they get casted to match with the input type. So that if input is float16, they also get downcast to float16.Background is - in some cases, CoreML requires the parameter types to match. So we either downcast the scalar params to float16, or upcast input operands to float32, the latter is less ideal because on CoreML only float16 get executed on NPU.
Any concerns with adding this step in the algorithm?
The text was updated successfully, but these errors were encountered: