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

Web Machine Learning Model Loader API #759

Closed
1 task done
wacky6 opened this issue Jul 20, 2022 · 8 comments
Closed
1 task done

Web Machine Learning Model Loader API #759

wacky6 opened this issue Jul 20, 2022 · 8 comments
Assignees
Labels
Progress: in progress Review type: CG early review An early review of general direction from a Community Group

Comments

@wacky6
Copy link

wacky6 commented Jul 20, 2022

Wotcher TAG!

I'm requesting a TAG review of Web Machine Learning (WebML) Model Loader API.

The WebML Model Loader API is a proposed web API to take a custom, pre-trained machine learning (ML) model in a standard format, and apply it to some data in JavaScript to perform inference, like classification, regression, or ranking. The idea is to make it easy and performant to use a custom, pre-built machine learning model in web apps, across devices and browsers.

Further details:

We'd prefer the TAG provide feedback as (please delete all but the desired option):
🐛 open issues in our GitHub repo for each point of feedback

@cynthia
Copy link
Member

cynthia commented Jul 20, 2022

Quick skim, this looks fine. Assuming there is no path to agree on a standard format, two questions:

  1. how does the caller know what kind of format they can .load()? What happens when .load() fails due to an unsupported format?
  2. why is tensor creation a factory and not a constructor? Would a tensor be usable in other (non-ML) contexts as well?

@hadleybeeman hadleybeeman self-assigned this Jul 20, 2022
@torgo torgo assigned torgo and cynthia and unassigned torgo Jul 21, 2022
@torgo torgo added this to the 2022-07-25-F2F-London milestone Jul 21, 2022
@wacky6
Copy link
Author

wacky6 commented Jul 22, 2022

  1. how does the caller know what kind of format they can .load()? What happens when .load() fails due to an unsupported format?

Caller can pass in modelFormat when they create context:
ml.createContext({modelFormat: "tflite" }}).

If the backend doesn't support the format, it rejects the promise on createContext() and load().

  1. Why is tensor creation a factory and not a constructor?

Model Loader shares the same tensor definition with Neural Network API. Currently, tensor is duck-typed (fixed type array + shape).

Discussions on whether tensor should be strongly typed: webmachinelearning/webnn#275 .

  1. Would a tensor be usable in other (non-ML) contexts as well?

As a general concept, a tensor is a fixed-size fixed-type arbitrary-dimensional array. Tensor computations are usually expressed using specialized methods (for performance reasons), instead of combining for-loops and basic arithmeric operations.

For Model Loader and Neural Network API (and perhaps future ML-related Web API), we aim to share the basic classes (like MLContext and tensor definition).

For non-ML context, I'm not sure if Tensor concept is widely used.

For non-ML Web API, I'm not sure if Tensor is more advantageous than TypedArray. To get the performance benefit, JavaScript probably needs to express computations using Tensor specific compute methods (instead of doing element-wise computation using loops), this requires further standardizations for each computation type.

For example, matrix multiplication, dot product, element-wise add, element-wise multiply need to be 4 methods.

@maxpassion maxpassion self-assigned this Aug 26, 2022
@torgo
Copy link
Member

torgo commented Aug 30, 2022

Hi @wacky6 we're just reviewing today and one thing that came up was your mention of the idea of a "DRM-like solution". We appreciate that you're seeing this might be an issue - protecting models - however if you're going to seriously work on this we'd appreciate being involved because there are a lot of issues and complications with DRM, the differences between its use case and this one, and the web's security model. We suggest to leaving this for future work.

@jbingham
Copy link

Thanks, @torgo ! Agree that DRM is a very futuristic idea for ML models. It will be a crazy huge amount of work, and we definitely will need your help (and many others as well). Let's focus on the more immediate steps to get the API ready for an origin trial.

@wacky6
Copy link
Author

wacky6 commented Aug 31, 2022

Thanks @torgo.

DRM in ML models is a novel topic, we'll definately work with TAG and wider industrial groups to work on that in the future.

We'll file dedicated TAG review requests (or propose as a saperate spec) considering the complexity and impact.

For now, let's focused on non-DRM, "open-source" format (e.g. Tensorflow / Torch / ONNX) use cases for this API.

@cynthia
Copy link
Member

cynthia commented Aug 31, 2022

For the record, I am anything but pro-DRM.

The word "DRM" likely spooked people here, but unlike conventional DRM where you are 1) running mystery meat code for decryption (see: CDM) or 2) mystery meat code (which could be potentially malicious) that is protected (see: DRM protected executables which prevent inspection) - this (as of today) would mostly be a form of protected transport from an origin to the compute backend. As it would mostly be coefficients for known operations (e.g. dot products) it won't have the same level of implications as conventional DRM.

(There is the question of obstruction of interpretability in the context of ethics, W3C likely does not have the right expertise for that discussion.)

@yuhonglin
Copy link

Hi all, just want to point out that "Intellectual Property protection" is a super important topic in practice because lots of ML models cost a lot to train. If we want commercial companies to use their best ml models on the web, we have to figure out a solution for this.

And the model loader API is possibly the most possible candidate to have "IP protection". Comparatively, it is almost impossible for WASM/WebGPU/WebGL based ML solutions to have this. So if we can achieve it, it will be a killer feature for the model loader API.

I am not an expert on these topics (yet). But I suggest to investigate this whenever possible.

@cynthia
Copy link
Member

cynthia commented Oct 12, 2022

We discussed this in our breakout yesterday - and our conclusion is that overall we are happy with this proposal. We still have some concerns around the factory vs constructor pattern - as it is not a pattern we encourage on the platform. See: https://www.w3.org/TR/design-principles/#constructors for more context.

That said, we don't feel particularly strongly about enforcing a change in the paradigm. Thank you for bringing this to our attention.

@cynthia cynthia closed this as completed Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Progress: in progress Review type: CG early review An early review of general direction from a Community Group
Projects
None yet
Development

No branches or pull requests

8 participants