ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / examples / simple / README.md
| 1 | ## Simple |
| 2 | |
| 3 | This example simply performs a matrix multiplication, solely for the purpose of demonstrating a basic usage of ggml and backend handling. The code is commented to help understand what each part does. |
| 4 | |
| 5 | Traditional matrix multiplication goes like this (multiply row-by-column): |
| 6 | |
| 7 | $$ |
| 8 | A \times B = C |
| 9 | $$ |
| 10 | |
| 11 | $$ |
| 12 | \begin{bmatrix} |
| 13 | 2 & 8 \\ |
| 14 | 5 & 1 \\ |
| 15 | 4 & 2 \\ |
| 16 | 8 & 6 \\ |
| 17 | \end{bmatrix} |
| 18 | \times |
| 19 | \begin{bmatrix} |
| 20 | 10 & 9 & 5 \\ |
| 21 | 5 & 9 & 4 \\ |
| 22 | \end{bmatrix} |
| 23 | \= |
| 24 | \begin{bmatrix} |
| 25 | 60 & 90 & 42 \\ |
| 26 | 55 & 54 & 29 \\ |
| 27 | 50 & 54 & 28 \\ |
| 28 | 110 & 126 & 64 \\ |
| 29 | \end{bmatrix} |
| 30 | $$ |
| 31 | |
| 32 | In `ggml`, we pass the matrix $B$ in transposed form and multiply row-by-row. The result $C$ is also transposed: |
| 33 | |
| 34 | $$ |
| 35 | ggml\\_mul\\_mat(A, B^T) = C^T |
| 36 | $$ |
| 37 | |
| 38 | $$ |
| 39 | ggml\\_mul\\_mat( |
| 40 | \begin{bmatrix} |
| 41 | 2 & 8 \\ |
| 42 | 5 & 1 \\ |
| 43 | 4 & 2 \\ |
| 44 | 8 & 6 \\ |
| 45 | \end{bmatrix} |
| 46 | , |
| 47 | \begin{bmatrix} |
| 48 | 10 & 5 \\ |
| 49 | 9 & 9 \\ |
| 50 | 5 & 4 \\ |
| 51 | \end{bmatrix} |
| 52 | ) |
| 53 | \= |
| 54 | \begin{bmatrix} |
| 55 | 60 & 55 & 50 & 110 \\ |
| 56 | 90 & 54 & 54 & 126 \\ |
| 57 | 42 & 29 & 28 & 64 \\ |
| 58 | \end{bmatrix} |
| 59 | $$ |
| 60 | |
| 61 | The `simple-ctx` doesn't support gpu acceleration. `simple-backend` demonstrates how to use other backends like CUDA and Metal. |