|
1 | 1 | # Pull requests (for contributors) |
2 | 2 |
|
3 | 3 | - Test your changes: |
4 | | - - Execute [the full CI locally on your machine](ci/README.md) before publishing |
5 | | - - Verify that the perplexity and the performance are not affected negatively by your changes (use `llama-perplexity` and `llama-bench`) |
6 | | - - If you modified the `ggml` source, run the `test-backend-ops` tool to check whether different backend implementations of the `ggml` operators produce consistent results (this requires access to at least two different `ggml` backends) |
7 | | - - If you modified a `ggml` operator or added a new one, add the corresponding test cases to `test-backend-ops` |
| 4 | + - Execute [the full CI locally on your machine](ci/README.md) before publishing |
| 5 | + - Verify that the perplexity and the performance are not affected negatively by your changes (use `llama-perplexity` and `llama-bench`) |
| 6 | + - If you modified the `ggml` source, run the `test-backend-ops` tool to check whether different backend implementations of the `ggml` operators produce consistent results (this requires access to at least two different `ggml` backends) |
| 7 | + - If you modified a `ggml` operator or added a new one, add the corresponding test cases to `test-backend-ops` |
8 | 8 | - Consider allowing write access to your branch for faster reviews, as reviewers can push commits directly |
9 | 9 | - If your PR becomes stale, don't hesitate to ping the maintainers in the comments |
10 | 10 |
|
|
29 | 29 |
|
30 | 30 | # Naming convention |
31 | 31 |
|
| 32 | +- Use `snake_case` for function, variable and type names |
| 33 | +- Use sized integer types in the public API |
32 | 34 | - Naming usually optimizes for common prefix (see https://github.com/ggerganov/ggml/pull/302#discussion_r1243240963) |
33 | 35 |
|
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 |
| 36 | + ```cpp |
| 37 | + // not OK |
| 38 | + int small_number; |
| 39 | + int big_number; |
| 40 | + |
| 41 | + // OK |
| 42 | + int number_small; |
| 43 | + int number_big; |
| 44 | + ``` |
| 45 | + |
| 46 | +- Enum values are always in upper case and prefixed with the enum name |
| 47 | + |
| 48 | + ```cpp |
| 49 | + enum llama_vocab_type { |
| 50 | + LLAMA_VOCAB_TYPE_NONE = 0, |
| 51 | + LLAMA_VOCAB_TYPE_SPM = 1, |
| 52 | + LLAMA_VOCAB_TYPE_BPE = 2, |
| 53 | + LLAMA_VOCAB_TYPE_WPM = 3, |
| 54 | + LLAMA_VOCAB_TYPE_UGM = 4, |
| 55 | + LLAMA_VOCAB_TYPE_RWKV = 5, |
| 56 | + }; |
| 57 | + ``` |
| 58 | + |
| 59 | +- The general naming pattern is `<class>_<method>`, with `<method>` being `<action>_<noun>` |
| 60 | + |
| 61 | + ```cpp |
| 62 | + llama_model_init(); // class: "llama_model", method: "init" |
| 63 | + llama_sampler_chain_remove(); // class: "llama_sampler_chain", method: "remove" |
| 64 | + llama_sampler_get_seed(); // class: "llama_sampler", method: "get_seed" |
| 65 | + llama_set_embeddings(); // class: "llama_context", method: "set_embeddings" |
| 66 | + llama_n_threads(); // class: "llama_context", method: "n_threads" |
| 67 | + llama_adapter_lora_free(); // class: "llama_adapter_lora", method: "free" |
| 68 | + ``` |
| 69 | + |
| 70 | + - The `get` `<action>` can be omitted |
| 71 | + - The `<noun>` can be omitted if not necessary |
| 72 | + - The `_context` suffix of the subject is optional |
| 73 | + - Use `init`/`free` for constructor/destructor `<action>` |
| 74 | + |
| 75 | +- Declare structs with `struct x {}` instead of `typedef struct x {} x` |
| 76 | + - In C++ code omit the `struct` keyword whenever it is not necessary |
| 77 | + - Use `_t` suffix when ... |
| 78 | + |
| 79 | +- Avoid using abbreviations in type names. Can be used in function and variable names |
| 80 | + |
| 81 | + ```cpp |
| 82 | + struct llama_context { ... }; |
| 83 | + |
| 84 | + llama_context * ctx = state->get_ctx(); |
| 85 | + ``` |
| 86 | + |
| 87 | +- Follow the existing code style, in case of doubt use `clang-format` to format the added code |
57 | 88 |
|
58 | 89 | # Resources |
59 | 90 |
|
|
0 commit comments