Skip to content

Conversation

tonibofarull
Copy link
Contributor

@tonibofarull tonibofarull commented Sep 26, 2022

Initial integration of WASI-NN based on #1225.

@tonibofarull
Copy link
Contributor Author

tonibofarull commented Sep 26, 2022

TODO

  • Specify limitations: only support of tflite, etc.
  • Improve safety checks. For example, using invalid formats.

@tonibofarull tonibofarull marked this pull request as ready for review September 27, 2022 09:23
@tonibofarull
Copy link
Contributor Author

My team is planning to continuously support WASI-NN by adding support to GPU, etc.
@wenyongh how do we proceed with this? I have several questions:

  • Right now we haven't added this to the CI.
  • We are supporting only a subset of WASI-NN features.

@wenyongh
Copy link
Contributor

wenyongh commented Sep 28, 2022

My team is planning to continuously support WASI-NN by adding support to GPU, etc. @wenyongh how do we proceed with this? I have several questions:

  • Right now we haven't added this to the CI.
  • We are supporting only a subset of WASI-NN features.

@tonibofarull Sounds like it is not a short term work and may take some time to implement all the features, right? Normally we will develop such features under a development branch (like dev/socket, dev/refactor_interp_module_inst), and periodically merge code from that branch into main branch when a milestone is reached. I have created a branch dev/wasi_nn, if there are more features to implement, how about submitting the PR to that branch? And if a milestone is reached and you want to merge it into main, please notify us. (Or merge this PR to main, and the next PRs to dev/wasi_nn?)
And could you help file an issue to describe the feature you want to implement, including motivation, changes, milestones and so on? Here are several samples:
#1336
#1384
#1468
Thanks.

Copy link
Contributor

@wenyongh wenyongh left a comment

Choose a reason for hiding this comment

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

Just comments about the scripts, license headers and so on, the C/Python source code logic isn't reviewed yet, will read it soon.

1. Build the dockre image,

```
docker build -t wasi-nn -f core/iwasm/libraries/wasi-nn/test/Dockerfile .
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure whether the test is just a simple interface test (like unit test), or a sample? If it is a sample, please put it under <wamr_root>/samples, for example, samples/wasi-nn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm testing multiple neural network models. Once it's ready for a release we can add a real sample!


if (buffer == NULL) {
fputs("Memory error\n", stderr);
exit(2);
Copy link
Contributor

Choose a reason for hiding this comment

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

how about changing to return with an error id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because here I'm doing the test of WASI-NN. As soon as there is an error I want to exit the program.

@tonibofarull
Copy link
Contributor Author

Thank you, I'll take a look!

@tonibofarull
Copy link
Contributor Author

And could you help file an issue to describe the feature you want to implement, including motivation, changes, milestones and so on? Here are several samples:

Let me address your comments before we discuss this 🙇

tonibofarull and others added 20 commits October 4, 2022 16:12
* feat: "load module done"

* fix: "pr fixes"

* fix: "pr fixes"
* feat: "set input"

* feat: "formatted files"

* fix: "PR changes"

* fix: renaming files
* feat: "set input"

* feat: "formatted files"

* feat: ouptut and compute functions

* PR fixes

* fix: PR fixes
* feat: draft opening file

* feat: ongoing progress tflite

* feat: working test

* fix: setting wasi_nn flag

* Remove legacy cmake and clean build file

* max sum and average models tested and working

* multiple outputs begining

* refractor saving model

* pr fixes

* pr fixes

* pr fixes

* pr fixes

* Fix dockerfile

* Fix unnecesary modified files

* Working inferencer and tests passing

* Assert in all tests

* Generation of models in the build

* Formatting python scripts

Co-authored-by: tonibofarull <[email protected]>
@tonibofarull
Copy link
Contributor Author

tonibofarull commented Oct 10, 2022

I've fixed all the previous comments!

And could you help file an issue to describe the feature you want to implement, including motivation, changes, milestones and so on?

I've created the issue here.

I have created a branch dev/wasi_nn, if there are more features to implement, how about submitting the PR to that branch? And if a milestone is reached and you want to merge it into main, please notify us. (Or merge this PR to main, and the next PRs to dev/wasi_nn?)

As stated in the issue, the first milestone corresponds to support TensorFlow in CPU and FP32, which are the features implemented in this PR.

Having the dev branch makes sense for having the future intermediate results!

@wenyongh
Copy link
Contributor

I've fixed all the previous comments!

And could you help file an issue to describe the feature you want to implement, including motivation, changes, milestones and so on?

I've created the issue here.

I have created a branch dev/wasi_nn, if there are more features to implement, how about submitting the PR to that branch? And if a milestone is reached and you want to merge it into main, please notify us. (Or merge this PR to main, and the next PRs to dev/wasi_nn?)

As stated in the issue, the first milestone corresponds to support TensorFlow in CPU and FP32, which are the features implemented in this PR.

Having the dev branch makes sense for having the future intermediate results!

Great! We will read the code again, many thanks!

@tonibofarull tonibofarull requested a review from wenyongh October 11, 2022 15:23
Copy link
Collaborator

@xujuntwt95329 xujuntwt95329 left a comment

Choose a reason for hiding this comment

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

LGTM

@wenyongh wenyongh merged commit e53ab91 into bytecodealliance:main Oct 12, 2022
@wenyongh
Copy link
Contributor

@tonibofarull Many thanks for the fixing, I have merged the PR.
And I tried to compile the source code, and found that there are many compile warnings, could you help clear them?
And will you add a sample/wasi-nn in the next stage? Thanks.

[ 8%] Building C object CMakeFiles/libiwasm.dir/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/random.c.o
In file included from /home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c:16:
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:77:5: warning: ‘export_module’ attribute directive ignored [-Wattributes]
77 | attribute((import_module("wasi_nn")));
| ^~~~~~~~~~~~~
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:77:5: warning: ‘import_module’ attribute directive ignored [-Wattributes]
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:89:5: warning: ‘export_module’ attribute directive ignored [-Wattributes]
89 | attribute((import_module("wasi_nn")));
| ^~~~~~~~~~~~~
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:89:5: warning: ‘import_module’ attribute directive ignored [-Wattributes]
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:102:5: warning: ‘export_module’ attribute directive ignored [-Wattributes]
102 | attribute((import_module("wasi_nn")));
| ^~~~~~~~~~~~~
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:102:5: warning: ‘import_module’ attribute directive ignored [-Wattributes]
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:112:1: warning: ‘export_module’ attribute directive ignored [-Wattributes]
112 | attribute((import_module("wasi_nn")));
| ^~~~~~~~~~~~~
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:112:1: warning: ‘import_module’ attribute directive ignored [-Wattributes]
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:130:5: warning: ‘export_module’ attribute directive ignored [-Wattributes]
130 | attribute((import_module("wasi_nn")));
| ^~~~~~~~~~~~~
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:130:5: warning: ‘import_module’ attribute directive ignored [-Wattributes]
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c: In function ‘wasi_nn_load’:
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c:68:71: warning: declaration of ‘graph’ shadows a global declaration [-Wshadow]
68 | graph_encoding encoding, execution_target target, graph *graph)
| ~~~~~~~^~~~~
In file included from /home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c:12:
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_common.h:39:18: note: shadowed declaration is here
39 | typedef uint32_t graph;
| ^~~~~
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c:95:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
95 | for (int i = 0; i < builder->size; ++i) {
| ^
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c: In function ‘wasi_nn_init_execution_context’:
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c:140:64: warning: declaration of ‘graph’ shadows a global declaration [-Wshadow]
140 | wasi_nn_init_execution_context(wasm_exec_env_t exec_env, graph graph,
| ~~~~~~^~~~~
In file included from /home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c:12:
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_common.h:39:18: note: shadowed declaration is here
39 | typedef uint32_t graph;
| ^~~~~
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c: In function ‘wasi_nn_set_input’:
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c:194:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
194 | for (int i = 0; i < dimensions.size; ++i) {
| ^
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c:204:12: warning: declaration of ‘tensor’ shadows a global declaration [-Wshadow]
204 | tensor tensor = { .type = input_tensor->type,
| ^~~~~~
In file included from /home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn_native.c:16:
/home/agent/WASM/wamr-internal-test/wamr-ba/core/iwasm/libraries/wasi-nn/wasi_nn.h:62:3: note: shadowed declaration is here
62 | } tensor;

@tonibofarull
Copy link
Contributor Author

Yes, of course! Thank you very much 🥳

@tonibofarull tonibofarull deleted the WASI-NN branch December 20, 2022 11:29
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
Initial integration of WASI-NN based on bytecodealliance#1225:
- Implement the library core/iwasm/libraries/wasi-nn
- Support TensorFlow, CPU, F32 at the first stage
- Add cmake variable `-DWAMR_BUILD_WASI_NN`
- Add test case based on Docker image and update document

Refer to bytecodealliance#1573
@@ -425,6 +428,13 @@ wasm_native_init()
goto fail;
#endif /* WASM_ENABLE_LIB_RATS */

#if WASM_ENABLE_WASI_NN != 0
n_native_symbols = get_wasi_nn_export_apis(&native_symbols);
if (!wasm_native_register_natives("wasi_nn", native_symbols,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tonibofarull where did this "wasi_nn" module name come from?
can you give me a reference to an exact version of the spec this was based on?
eg. commit id of wasi-nn repo
as far as i researched wasi-nn has always been using "wasi_ephemeral_nn".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was an arbitrary name as I couldn't get an API list based on witx/wit.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok. so this is not compatible with any versions of wasi-nn. right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Compatibility is not guaranteed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, there will be no harm if we replace wasi-nn with wasi_ephemeral_nn in the repo?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Compatibility is not guaranteed.

well, actually incompatibility is guaranteed because of the different module name, isn't it?

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.

6 participants