-
Notifications
You must be signed in to change notification settings - Fork 58
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
Xnnpack backend support #159
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
!!!Do not merge until xnnpack backend llama is runable!!!
How to use xnnpack backend in mllm
The
xnnpack
backend in MLLM offers a convenient wrapper function designed to convert a standard CPU-based MLLM module into one that utilizes thexnnpack
backend. This function,wrap2xnn
, accepts parameters such asinputs_nums
,outputs_nums
, and any other arguments required for the construction of aLinearModule
. For a clearer understanding, please refer to the example provided below:E.g.:
Unlike the dynamic graph mode in MLLM, xnnpack operates on a static graph. This necessitates a mechanism to convert from a dynamic graph to a static graph. The
xnnpack
backend wrapper in MLLM will add several layers on top of theLinearModule
to register input external and output external Tensors. The final wrapped module, as shown in the following pseudocode:You can find more use cases in https://github.com/chenghuaWang/mllm/blob/main/test/xnnpack/
How are the operators in MLLM's xnnpack backend implemented?
Take
XpAdd
operation as an example:The
XpAdd
‘s reshape function is identical to that ofCPUAdd
. The main differences lie in thesetUp
andexecute
functions.Upon calling
execute
,XpAdd
will integrate a static graph node into the xnnpack subgraph. However,XpAdd
performs no actions during thesetUp
phase. This is because, during thesetUp
stage, we need to allow theXpDirect
Op to determine whether the Tensor is an external input, external output, or a regular tensor.