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

[WASI-NN] neural_speed: add backend structure #3303

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

grorge123
Copy link

No description provided.

Copy link
Member

juntao commented Mar 25, 2024

Hello, I am a code review bot on flows.network. Here are my reviews of code commits in this PR.


@github-actions github-actions bot added c-Plugin An issue related to WasmEdge Plugin c-WASI-NN c-CMake labels Mar 25, 2024
@grorge123 grorge123 force-pushed the neural_speed branch 4 times, most recently from f916aeb to af7d519 Compare March 25, 2024 11:53
@grorge123 grorge123 requested a review from q82419 as a code owner March 25, 2024 11:53
@github-actions github-actions bot added the c-Test An issue/PR to enhance the test suite label Mar 25, 2024
@github-actions github-actions bot removed the c-Test An issue/PR to enhance the test suite label Mar 25, 2024
Copy link

codecov bot commented Mar 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.84%. Comparing base (0f11476) to head (065fc95).
Report is 19 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3303      +/-   ##
==========================================
- Coverage   79.84%   79.84%   -0.01%     
==========================================
  Files         253      253              
  Lines       34945    34948       +3     
  Branches     6130     6143      +13     
==========================================
+ Hits        27903    27905       +2     
- Misses       5613     5623      +10     
+ Partials     1429     1420       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@grorge123 grorge123 marked this pull request as draft March 25, 2024 12:55
@grorge123 grorge123 marked this pull request as ready for review March 29, 2024 06:22
@grorge123 grorge123 changed the title [WIP] [WASI-NN] neural_speed: add backend struct [WASI-NN] neural_speed: add backend structure Mar 29, 2024
@grorge123 grorge123 requested a review from hydai as a code owner April 8, 2024 06:35
@github-actions github-actions bot added the c-Test An issue/PR to enhance the test suite label Apr 8, 2024
@github-actions github-actions bot added c-CLI An issue related to WasmEdge CLI tools c-Installer c-CI labels Apr 25, 2024
@github-actions github-actions bot removed c-CLI An issue related to WasmEdge CLI tools c-Installer c-CI labels Apr 25, 2024
@grorge123 grorge123 force-pushed the neural_speed branch 3 times, most recently from a60159f to 984d13a Compare April 25, 2024 04:06
@grorge123
Copy link
Author

@hydai
I have finished the basic implement that #3260 mentioned.
And I create a rust example.
second-state/WasmEdge-WASINN-examples#135

plugins/wasi_nn/neuralspeed.cpp Outdated Show resolved Hide resolved
plugins/wasi_nn/neuralspeed.cpp Outdated Show resolved Hide resolved
plugins/wasi_nn/neuralspeed.cpp Outdated Show resolved Hide resolved
plugins/wasi_nn/CMakeLists.txt Outdated Show resolved Hide resolved
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
Signed-off-by: grorge <g97116@yahoo.com>
@grorge123 grorge123 force-pushed the neural_speed branch 4 times, most recently from e136fdd to 1ffd3ac Compare May 8, 2024 09:28
Signed-off-by: grorge <g97116@yahoo.com>
@grorge123 grorge123 force-pushed the neural_speed branch 2 times, most recently from 5cc73fc to ef72299 Compare May 13, 2024 06:41
Signed-off-by: grorge <g97116@yahoo.com>
@@ -149,6 +149,64 @@ if(BACKEND STREQUAL "ggml")
endif()
endif()

if(BACKEND STREQUAL "neuralspeed")
find_package(simdjson QUIET)
Copy link
Member

Choose a reason for hiding this comment

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

We changed the way to find the simdjson package, please use the new way like this pr: #3426

#endif
void printImformation(Graph &GraphRef, Context &CxtRef) {
spdlog::info(
"[WASI-NN][Info] Neural speed backend: Number of input tokens: {}"sv,
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to add [Info] here, because the spdlog::info will do this for you.

"[WASI-NN][Debug] Neural speed: Model path not found in nn-preload, "
"write model into a tmpfile."sv);
}
// TODO: pass the model directly to ggml
Copy link
Member

Choose a reason for hiding this comment

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

I would like to know the details of this TODO item.

Copy link
Author

Choose a reason for hiding this comment

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

It refers to ggml backend. Although current implementation is enough. Should I remove it?

Copy link
Member

Choose a reason for hiding this comment

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

We can remove it.

auto &CxtRef = Env.NNContext[ContextId].get<Context>();
auto &GraphRef = Env.NNGraph[CxtRef.GraphId].get<Graph>();
if (!Py_IsInitialized()) {
spdlog::info(
Copy link
Member

Choose a reason for hiding this comment

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

We should use spdlog::error here.

Expect<WASINN::ErrNo> compute(WasiNNEnvironment &Env,
uint32_t ContextId) noexcept {
if (!Py_IsInitialized()) {
spdlog::info(
Copy link
Member

Choose a reason for hiding this comment

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

We should use spdlog::error here. This is a fatal error.

"[WASI-NN] neural speed backend: Input transfer tensor failed."sv);
return WASINN::ErrNo::InvalidArgument;
}
// PyObject *GenerateArgs = PyTuple_Pack(1, LongTensor);
Copy link
Member

Choose a reason for hiding this comment

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

Why does this line comment out?

}
}
Py_DECREF(Result);
// Py_DECREF(GenerateArgs);
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

elseif(BACKEND STREQUAL "neuralspeed")
message( STATUS "Download ML artifacts to ${CMAKE_CURRENT_BINARY_DIR}/wasinn_neural_speed_fixtures")
download(
https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_0.gguf
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to download this huge file if we would like to do the test?
Is it possible to have a small one instead?

uint32_t BuilderPtr = UINT32_C(0);
uint32_t LoadEntryPtr = UINT32_C(0);
uint32_t SetInputEntryPtr = UINT32_C(0);
uint32_t OutBoundPtr = UINT32_C(61000 * 65536);
Copy link
Member

Choose a reason for hiding this comment

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

Should we use UINT32_C(61000) * UINT32_C(65536)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-CMake c-Plugin An issue related to WasmEdge Plugin c-Test An issue/PR to enhance the test suite c-WASI-NN v-0.14.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants