Repository navigation
ggml-cpu : implement Kronecker and clean up SYCL test special-casing - #28490
philip-jingxin wants to merge 1 commit into
Conversation
|
@philip-jingxin Thank you! |
@arthw Resolved. Thanks for reviewing! |
|
@ggerganov Restored the missing Hadamard matrix definitions dropped during the recent merge. Cleaned up and ready for review again. Thanks! |
|
Note: The CI failures in gpu-rocm and gpu-vulkan appear to be unrelated to this PR (could be some existing issues in ARGSORT) |
|
@ggerganov @arthw Detailsphilip@dev:llama.cpp$ ./build_cpu/bin/test-backend-ops test -o MUL_MAT_HADAMARD -b CPU Testing 1 devicesBackend 1/1: CPU MUL_MAT_HADAMARD(type_a=f32,type_b=f32,m=128,n=1,k=128,bs=[1,1],nr=[1,1],per=[0,1,2,3],k_v=0,o=1,src_overlap=0): OK |
|
@philip-jingxin Thank you! |
Resolved, thanks for your review! |
|
Seems this PR fell through the cracks. @philip-jingxin can you rebase and make sure this PR is still relevant? |
d3a3030 to
d3cbd21
Compare
Hi! Thanks for the reminder. I've rebased the branch to the latest master. Also confirmed the PR is still relevant, as it extends the existing power-of-two path to 12×2^k and 20×2^k dimensions. I rebuilt the code from a clean build directory and ran the CPU tests; all 40 tests passed. |
|
I tested and all related UT cases are passed. Thank you! |
| #define P 1.0f | ||
| #define N -1.0f | ||
|
|
||
| // constant Hadamard matrix via Paley I construction | ||
| static constexpr float H12[12][12] = { | ||
| { P, P, P, P, P, P, P, P, P, P, P, P }, | ||
| { P, N, P, N, P, P, P, N, N, N, P, N }, | ||
| { P, N, N, P, N, P, P, P, N, N, N, P }, | ||
| { P, P, N, N, P, N, P, P, P, N, N, N }, | ||
| { P, N, P, N, N, P, N, P, P, P, N, N }, | ||
| { P, N, N, P, N, N, P, N, P, P, P, N }, | ||
| { P, N, N, N, P, N, N, P, N, P, P, P }, | ||
| { P, P, N, N, N, P, N, N, P, N, P, P }, | ||
| { P, P, P, N, N, N, P, N, N, P, N, P }, | ||
| { P, P, P, P, N, N, N, P, N, N, P, N }, | ||
| { P, N, P, P, P, N, N, N, P, N, N, P }, | ||
| { P, P, N, P, P, P, N, N, N, P, N, N } | ||
| }; | ||
|
|
||
| static constexpr float H20[20][20] = { | ||
| { P, P, P, P, P, P, P, P, P, P, P, P, P, P, P, P, P, P, P, P }, | ||
| { P, N, P, N, N, P, P, P, P, N, P, N, P, N, N, N, N, P, P, N }, | ||
| { P, N, N, P, N, N, P, P, P, P, N, P, N, P, N, N, N, N, P, P }, | ||
| { P, P, N, N, P, N, N, P, P, P, P, N, P, N, P, N, N, N, N, P }, | ||
| { P, P, P, N, N, P, N, N, P, P, P, P, N, P, N, P, N, N, N, N }, | ||
| { P, N, P, P, N, N, P, N, N, P, P, P, P, N, P, N, P, N, N, N }, | ||
| { P, N, N, P, P, N, N, P, N, N, P, P, P, P, N, P, N, P, N, N }, | ||
| { P, N, N, N, P, P, N, N, P, N, N, P, P, P, P, N, P, N, P, N }, | ||
| { P, N, N, N, N, P, P, N, N, P, N, N, P, P, P, P, N, P, N, P }, | ||
| { P, P, N, N, N, N, P, P, N, N, P, N, N, P, P, P, P, N, P, N }, | ||
| { P, N, P, N, N, N, N, P, P, N, N, P, N, N, P, P, P, P, N, P }, | ||
| { P, P, N, P, N, N, N, N, P, P, N, N, P, N, N, P, P, P, P, N }, | ||
| { P, N, P, N, P, N, N, N, N, P, P, N, N, P, N, N, P, P, P, P }, | ||
| { P, P, N, P, N, P, N, N, N, N, P, P, N, N, P, N, N, P, P, P }, | ||
| { P, P, P, N, P, N, P, N, N, N, N, P, P, N, N, P, N, N, P, P }, | ||
| { P, P, P, P, N, P, N, P, N, N, N, N, P, P, N, N, P, N, N, P }, | ||
| { P, P, P, P, P, N, P, N, P, N, N, N, N, P, P, N, N, P, N, N }, | ||
| { P, N, P, P, P, P, N, P, N, P, N, N, N, N, P, P, N, N, P, N }, | ||
| { P, N, N, P, P, P, P, N, P, N, P, N, N, N, N, P, P, N, N, P }, | ||
| { P, P, N, N, P, P, P, P, N, P, N, P, N, N, N, N, P, P, N, N } | ||
| }; | ||
|
|
||
| #undef P | ||
| #undef N | ||
|
|
There was a problem hiding this comment.
I'm not sure I understand why we need to replicate these matrices in the test-backend-ops?
There was a problem hiding this comment.
The test needs to use the same matrices to validate the implementation.
test-backend-ops.cpp is separate from ops.cpp. Put implementations in a shared header doesn't seem to fit the current design.
I did consider putting the matrices in ggml.h. But changing a public header would have a wider impact, especially since these matrices are only used in one place in the implementation. That's why I kept separate copies.
Another option would be generating the matrices in the test using the Paley I construction. However, we still need to make sure the generated matrices exactly match the matrices in the implementation. With small matrices, I think checking two copies of constants is easier than checking the constant against the code.
If we run into more cases like this, we could move the shared numerical constants into a separate header.
There was a problem hiding this comment.
The purpose of the test-backend-ops tests is to compare reference CPU implementation with the backend implementation. It should not require these matrices (unless I am missing something?).
There was a problem hiding this comment.
There's no known general construction that covers every order where a Hadamard matrix exists. The current master test code only constructs Hadamard matrices of order 2^k. I added H12 and H20 to cover orders 12*2^k and 20*2^k.
This allows the tests to construct reference matrices for all dimension cases currently supported by the CPU and SYCL backends. There's also a CUDA implementation PR in progress.
There was a problem hiding this comment.
@ggerganov
Yes, I understand.
Could you guide how to handle such case?
Like:
When add new OP in CPU, where to save the test code?
When/who should add UT case in test-backend-ops.cpp?
Thank you!
There was a problem hiding this comment.
Hi @ggerganov, just following up on the discussion above. Could you take another look and advise on the preferred approach for the Hadamard reference tests? Happy to make any necessary changes. Thanks!
Overview
Follow-up to #28254.
Implemented Kronecker product to support non-power-of-two dimensions on cpu.
Additional information
Changes
#ifdefdirectives intests/test-backend-ops.cpp. All non power-of-two tests now run on CPU.Testing & Verification
Environment
Correctness Test
Tested with the following commands:
Passed 16/16 verification tests, including non-power-of-two sizes (m= 384, 640, 768, 1280) across various configurations:
Performance Benchmarks
Measured on 13th Gen Intel(R) Core(TM) i9-13900K:
Requirements