Skip to content

Commit ece4d6d

Browse files
committed
contrib : add naming guidelines
1 parent ba8a1f9 commit ece4d6d

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

CONTRIBUTING.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,39 @@
2222
- Avoid fancy-looking modern STL constructs, use basic `for` loops, avoid templates, keep it simple
2323
- There are no strict rules for the code style, but try to follow the patterns in the code (indentation, spaces, etc.). Vertical alignment makes things more readable and easier to batch edit
2424
- Clean-up any trailing whitespaces, use 4 spaces for indentation, brackets on the same line, `void * ptr`, `int & a`
25-
- Naming usually optimizes for common prefix (see https://github.com/ggerganov/ggml/pull/302#discussion_r1243240963)
2625
- Tensors store data in row-major order. We refer to dimension 0 as columns, 1 as rows, 2 as matrices
2726
- Matrix multiplication is unconventional: [`C = ggml_mul_mat(ctx, A, B)`](https://github.com/ggerganov/llama.cpp/blob/880e352277fc017df4d5794f0c21c44e1eae2b84/ggml.h#L1058-L1064) means $C^T = A B^T \Leftrightarrow C = B A^T.$
2827

2928
![matmul](media/matmul.png)
3029

30+
# Naming convention
31+
32+
- Naming usually optimizes for common prefix (see https://github.com/ggerganov/ggml/pull/302#discussion_r1243240963)
33+
34+
```cpp
35+
// not OK
36+
int small_number;
37+
int big_number;
38+
39+
// OK
40+
int number_small;
41+
int number_big;
42+
```
43+
44+
- The general pattern is: `subject_verb_object`:
45+
46+
```cpp
47+
llama_model_init() // sub: "llama_model", vrb: "init", obj: ""
48+
llama_sampler_chain_remove() // sub: "llama_sampler_chain", vrb: "remove", obj: ""
49+
llama_sampler_get_seed() // sub: "llama_sampler", vrb: "get", obj: "seed"
50+
llama_set_embeddings() // sub: "llama_context", vrb: "set", obj: "embeddings"
51+
llama_n_threads() // sub: "llama_context", vrb: "", obj: "n_threads"
52+
llama_adapter_lora_free() // sub: "llama_adapter_lora", vrb: "free", obj: ""
53+
```
54+
55+
- The `get` verb is optional
56+
- The `_context` suffix of the subject is optional
57+
3158
# Resources
3259

3360
The Github issues, PRs and discussions contain a lot of information that can be useful to get familiar with the codebase. For convenience, some of the more important information is referenced from Github projects:

0 commit comments

Comments
 (0)