Skip to content

Control flow operations: if, while #559

@philloooo

Description

@philloooo

Hi, currently WebNN doesn't support control flow operations like if and while, so I am creating this issue to open the discussion on whether WebNN should support control flows.

We have a where which could be used similar to if, but it requires both branches to be computed, then toss away the branch we don't need, this is much less efficient to use it as if.

I don't see anything in current spec that can be used for while.

Use case:
For transformer like models, for the decoder part, it's essentially a while loop that keep feeding the output token back to the decoder, until it reaches the end token. If WebNN doesn't have the while op, this loop will exist on the javascript side, meaning that you will have this round trip and synchronization to client side JS for each iteration, much less efficient then encapsulating the whole logic into a single WebNN computation.

Framework support:
ONNX: loop, if
tensorflow: while_loop, cond

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions