Skip to content

Comments

Update WebNN architecture diagram SVG#871

Merged
anssiko merged 3 commits intomainfrom
arch-diagram-svg
Jun 25, 2025
Merged

Update WebNN architecture diagram SVG#871
anssiko merged 3 commits intomainfrom
arch-diagram-svg

Conversation

@anssiko
Copy link
Member

@anssiko anssiko commented Jun 24, 2025

Issue #870 reminded me we'd need a new SVG export for the architecture diagram too, so I took a plunge into the world of SVG.

It seems GH diff UI (below) does not render the SVG properly, but it does render with all major browser after applying the patch (see the commit message): https://raw.githubusercontent.com/webmachinelearning/webnn/arch-diagram-svg/content/webnn_arch.svg

I kept the Mermaid in the explainer for now, and put a note in there so we remember this SVG exists.

PTAL @tomayac for cross-checking if there's a better way to export this without errors.

FYI @matatk, here's another diagram we want to make screen reader friendly.

Mermaid Live Editor export produces an invalid SVG.
To fix this, we apply the following patch:

perl -pi -e 's/ / /g' webnn_arch.png

This replaces all non-breaking space   character entity
references with numeric entity references  

Mermaid syntax does not support numeric entity references,
so we need to rely on this patch if we want to be white
space perfect.

Consider:
Core ML => Core ML

Mermaid source used to produce this SVG:

```mermaid
%%{ init : { "look" : "handDrawn", "theme" : "neo-dark" }}%%
flowchart TD
  subgraph Models
    Model[ONNX, TensorFlow, PyTorch]
  end

  subgraph Frameworks
    Framework(ONNX Runtime Web, LiteRT)
  end

  subgraph Browser_APIs[Browser APIs]
    Wasm
    WebNN
    WebGPU
  end

  subgraph Native_ML_APIs[Native ML APIs]
    MLAPI[DirectML / LiteRT / Core ML]
  end

  subgraph Hardware
    CPU
    NPU
    GPU
  end

  Model --> Framework

  Framework --> Wasm
  Framework ==> WebNN
  Framework --> WebGPU

  Wasm --> CPU
  WebNN ==> MLAPI
  WebGPU --> GPU

  MLAPI ==> CPU
  MLAPI ==> NPU
  MLAPI ==> GPU
  ```
@tomayac
Copy link

tomayac commented Jun 24, 2025

Those labels are a bit hard to see.

Screenshot 2025-06-24 at 17 44 02

FWIW, my flow in #870 (comment) was to paste the existing diagram in ChatGPT, ask it to create a Mermaid diagram out of it, and then fact-check it and polish it in the online editor.

@anssiko
Copy link
Member Author

anssiko commented Jun 24, 2025

Those subgraph labels were also bugging me. IIRC we found out positioning them was not possible without CSS hacks that come with side effects. Please check with your favourite LLM to see if there's indeed a non-hacky solution :-)

@tomayac
Copy link

tomayac commented Jun 24, 2025

Your diagram looks like drawn with Excalidraw. Maybe just move the labels up so they are between boxes next to the arrows?

@anssiko
Copy link
Member Author

anssiko commented Jun 24, 2025

It's drawn with Mermaid, the source code is in the commit message 1bc34db and if you drop that source into https://mermaid.live/ it should render as in https://github.com/webmachinelearning/webnn/blob/main/explainer.md

I'd like to have clean Mermaid source without hacks that either as is could be used as an alt text, or used as input to LLM to produce a good quality alt text.

Place its source inside a disclosure widget
@anssiko anssiko requested a review from Copilot June 25, 2025 17:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the WebNN architecture diagram by adding an SVG export of the diagram alongside the existing Mermaid version.

  • Adds an SVG image link for the WebNN architecture diagram.
  • Wraps the SVG source in a collapsible
    Details block for additional information.

Co-authored-by: Copilot <[email protected]>
@anssiko
Copy link
Member Author

anssiko commented Jun 25, 2025

I updated this PR to make this a clean drop-in replacement from the current script-generated graph to an identical SVG, retaining the source. To be iterated further to improve accessibility. Copilot suggested an alt text that I adopted for now.

It looks like we cannot test this without deploying to production, so I'll hit the green button. 🤞

@anssiko anssiko merged commit 77be999 into main Jun 25, 2025
2 checks passed
@anssiko
Copy link
Member Author

anssiko commented Jun 25, 2025

It appears embedding SVG into Markdown did not work as expected, so I deployed a hotfix 093be92 to revert back to the script-generated graph. Sorry for the noise.

@anssiko anssiko deleted the arch-diagram-svg branch June 25, 2025 17:29
anssiko added a commit that referenced this pull request Aug 8, 2025
Mermaid Live Editor export produces an invalid SVG.
To fix this, we apply the following patch:

perl -pi -e 's/&nbsp;/&#160;/g' webnn_arch.png

This replaces all non-breaking space &nbsp; character entity
references with numeric entity references &#160;

Mermaid syntax does not support numeric entity references,
so we need to rely on this patch if we want to be white
space perfect.

Consider:
Core&nbsp;ML => Core&#160;ML

Mermaid source used to produce this SVG:

```mermaid
%%{ init : { "look" : "handDrawn", "theme" : "neo-dark" }}%%
flowchart TD
  subgraph Models
    Model[ONNX, TensorFlow, PyTorch]
  end

  subgraph Frameworks
    Framework(ONNX Runtime Web, LiteRT)
  end

  subgraph Browser_APIs[Browser APIs]
    Wasm
    WebNN
    WebGPU
  end

  subgraph Native_ML_APIs[Native ML APIs]
    MLAPI[DirectML / LiteRT / Core&nbsp;ML]
  end

  subgraph Hardware
    CPU
    NPU
    GPU
  end

  Model --> Framework

  Framework --> Wasm
  Framework ==> WebNN
  Framework --> WebGPU

  Wasm --> CPU
  WebNN ==> MLAPI
  WebGPU --> GPU

  MLAPI ==> CPU
  MLAPI ==> NPU
  MLAPI ==> GPU
  ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants