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

feat: fix mulmat #2

Merged
merged 47 commits into from
Oct 28, 2024
Merged

feat: fix mulmat #2

merged 47 commits into from
Oct 28, 2024

Conversation

chraac
Copy link
Owner

@chraac chraac commented Sep 9, 2024

Summary

In latest dev-refactoring, the test-backend-ops runs well on ADD operator, but failed on MUL_MAT.
After investigation, we found that the input tensor should be transposed (see: 63dc587).

Here's how we fix it:

  1. Add tensor types INTERMEDIATE and PARAMETER. These types are graph-private and invisible to other graphs.
    1. The INTERMEDIATE tensor is used for connecting multiple operations within a single graph.
    2. The PARAMETER tensor is used for setting the parameters of certain operators, such as transpose.
  2. Add ggml_qnn_matmul_op_config class, for creating necessary nodes to matmul graph
    1. At function ggml_qnn_matmul_op_config::create_tensors, we will add several nodes, and finally make a graph like this:
     graph TD;
          i1>input_tensor_a] --src0--> mat_mul0;
          i2>input_tensor_b] --src1--> transpose0;
          transpose0 --intermediate0--> mat_mul0;
          mat_mul0 --intermediate1--> transpose1;
          transpose1 --dst0--> o1>output_tensor_c];
    
    Loading

Log

Backend 4/4: CPU
  Skipping CPU backend
4/4 backends passed
�[1;32mOK�[0m

test-backend-ops_MUL_MAT.log

Changes

  • Modify the ggml_qnn_op_config, to manage the rensors, and support multi-op
  • Add transpose op before mulmat

Self-check

@chraac chraac added enhancement New feature or request wip work in progress labels Sep 9, 2024
@chraac chraac self-assigned this Sep 9, 2024
@chraac chraac marked this pull request as draft September 9, 2024 06:22
@chraac chraac force-pushed the dev-multi-op-in-one-graph branch from c34eecb to d55b067 Compare September 10, 2024 15:28
@chraac chraac force-pushed the dev-multi-op-in-one-graph branch from 14283fa to 74d5016 Compare September 18, 2024 05:31
@chraac chraac force-pushed the dev-multi-op-in-one-graph branch from 7933c79 to ed181a1 Compare September 19, 2024 14:03
chraac pushed a commit that referenced this pull request Oct 3, 2024
* vulkan : do not use tensor->extra

This patch allows using the Vulkan backend with the RPC backend as
tensor->extra is no longer used.

Ref: ggerganov#8536

* Adapt GGML_VULKAN_CHECK_RESULTS to extra removal (#2)

---------

Co-authored-by: 0cc4m <[email protected]>
@chraac chraac force-pushed the dev-multi-op-in-one-graph branch from 8e55942 to a6deb22 Compare October 3, 2024 16:27
* src1 -> | transpose0 | -> intermediate0 -> | mat_mul0 |
*/

const auto tensor_rank = get_rank(tensor_inputs, tensor_outputs);
Copy link
Owner Author

@chraac chraac Oct 6, 2024

Choose a reason for hiding this comment

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

Here we add nodes to the mat_mul graph, after this function ,the graph will be like:

 graph TD;
      i1>input_tensor_a] --src0--> mat_mul0;
      i2>input_tensor_b] --src1--> transpose0;
      transpose0 --intermediate0--> mat_mul0;
      mat_mul0 --intermediate1--> transpose1;
      transpose1 --dst0--> o1>output_tensor_c];
Loading

@chraac chraac force-pushed the dev-multi-op-in-one-graph branch from 14f2205 to 327b3db Compare October 28, 2024 03:59
@chraac chraac marked this pull request as ready for review October 28, 2024 04:47
@chraac chraac changed the title [WIP] feat: fix mulmat feat: fix mulmat Oct 28, 2024
@chraac chraac merged commit 4abaf7d into dev-refactoring Oct 28, 2024
@chraac chraac deleted the dev-multi-op-in-one-graph branch October 28, 2024 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wip work in progress
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant