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

NamedOutput mechanism clarification #140

Closed
anssiko opened this issue Feb 4, 2021 · 3 comments · Fixed by #147
Closed

NamedOutput mechanism clarification #140

anssiko opened this issue Feb 4, 2021 · 3 comments · Fixed by #147
Assignees
Labels
tag-tracker Group bringing to attention of the TAG, or tracked by the TAG but not needing response.

Comments

@anssiko
Copy link
Member

anssiko commented Feb 4, 2021

  1. I don't quite understand the NamedOutput mechanism. What if what is output just a feature?

via w3ctag/design-reviews#570 (comment)

@cynthia "What if what is output just a feature?" part needs a clarification?

@cynthia
Copy link

cynthia commented Feb 5, 2021

Yeah, sorry. "What if the output is just a feature?" is what I intended to write. (Not great at speaking and writing at the same time.)

@huningxin
Copy link
Contributor

huningxin commented Feb 8, 2021

Thanks for the clarification @cynthia !

I agree the NamedOutputs needs more details in the spec. We'll fix that.

Basically, the NamedOutputs is just used to index an Output by string-based name.

For the case that the output is just a feature, I suppose the feature can be represented by an Operand, then the developer might first need to bind a name to the operand when creating a model, e.g. the following sample code binds name "C" to operand C.

// 1. Create a model of the computational graph 'C = 0.2 * A + B'.
const constant = builder.constant(0.2);
const A = builder.input('A', operandType);
const B = builder.input('B', operandType);
const C = builder.add(builder.mul(A, constant), B);
const model = builder.createModel({'C': C});

So after computing, the developer can use name "C" to index the output, e.g. by following code

const outputs = await compilation.compute(inputs);
// The computed result of [[1, 1], [1, 1]] is in the buffer associated with
// the output operand.
console.log('Output shape: ' + outputs.C.dimensions);
console.log('Output value: ' + outputs.C.buffer);

You can try above code in WebNN code editor with webnn-polyfill.

Other usages of NamedOutputs include:

  1. support the pre-allocated buffer for compute, this might be useful for Wasm integration, see code example
  2. support optional output by specifying the output name when invoking compute, see code example

@dontcallmedom dontcallmedom added tag-tracker Group bringing to attention of the TAG, or tracked by the TAG but not needing response. and removed tag labels Feb 12, 2021
@huningxin huningxin self-assigned this Feb 19, 2021
@huningxin
Copy link
Contributor

As discussed in 18 Feb CG call, I'll craft a PR to add specific text into the spec and ask for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tag-tracker Group bringing to attention of the TAG, or tracked by the TAG but not needing response.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants