Skip to content

JS Operator overloading for Machine Learning #73

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

Open
dontcallmedom opened this issue Aug 20, 2020 · 3 comments
Open

JS Operator overloading for Machine Learning #73

dontcallmedom opened this issue Aug 20, 2020 · 3 comments
Labels
Developer's Perspective Machine Learning Experiences on the Web: A Developer's Perspective Discussion topic Topic discussed at the workshop

Comments

@dontcallmedom
Copy link
Member

@cynthia raises in his presentation a limitation of JavaScript for ML processing:

Due to the current limitations of JavaScript such as the lack of operator overloading it makes it challenging to implement an ergonomic API for vector matrix or tensor operations on the web platform.

There is an active Stage 1 proposal in TC39 around operator overload, including for matrix computations.

Can the various ML frameworks people comment on how important this is for the ergonomics of their APIs? @jasonmayes @teropa @EmmaNingMS @shiffman @annxingyuan @wangqunbaidu

I also wonder whether taking into account operator overloading has impact on how WebNN should be designed given that it itself provides multiple hardware-accelerated operators which would be useful well beyond the pure ML context. @huningxin has this been discussed at all in the context of WebNN design?

@huningxin
Copy link
Contributor

huningxin commented Aug 21, 2020

I also wonder whether taking into account operator overloading has impact on how WebNN should be designed

I understand the JS operator overloading would simply WebNN graph building code. For instance, the code of today's WebNN example

// intermediateOutput1 is the output of the first Add operation.
const intermediateOutput1 = nn.add(constant1, input1);

// intermediateOutput2 is the output of the second Add operation.
const intermediateOutput2 = nn.add(constant2, input2);

// output is the output tensor of the Mul operation.
const output = nn.mul(intermediateOutput1, intermediateOutput2);

could be simplified into

const output = (constant1 + input1) * (constant2 + input2)

adding @wchao1115 @gramalingam @RafaelCintron @pyu10055 @dsmilkov @nsthorat and @anssiko for thoughts and visibility.

@pyu10055
Copy link

In tensorflow.js we use chained API to improve usability of the API, with @huningxin example, it would look like this:

constant1.add(input1).mul(constant2.add(input2))

Obviously this does not look as elegant as the operator overloaded version, but from users point of view, they want to have a consistent API. IMO Operator overload can solve simple use cases, but you will still need some functions to represent more complex ops, as well as additional parameters.

@anssiko anssiko added the Developer's Perspective Machine Learning Experiences on the Web: A Developer's Perspective label Sep 3, 2020
@anssiko anssiko added this to the 2020-09-23 Live Session #3 milestone Sep 21, 2020
@cynthia
Copy link
Member

cynthia commented Sep 23, 2020

I'd be willing to help with bridging TC39 folks to see what can be done to progress the proposal further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer's Perspective Machine Learning Experiences on the Web: A Developer's Perspective Discussion topic Topic discussed at the workshop
Projects
None yet
Development

No branches or pull requests

5 participants