Skip to content

Commit 0ad1d34

Browse files
ikawrakowIwan Kawrakow
andauthored
Enable and clean up compiler warnings in src (ikawrakow#824)
* WIP: enable and clean up warnings in src * All warnings handled --------- Co-authored-by: Iwan Kawrakow <[email protected]>
1 parent 335a1f9 commit 0ad1d34

File tree

6 files changed

+76
-317
lines changed

6 files changed

+76
-317
lines changed

src/CMakeLists.txt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@ endif()
1111

1212
# llama
1313

14+
if (LLAMA_ALL_WARNINGS)
15+
if (NOT MSVC)
16+
list(APPEND WARNING_FLAGS -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wno-sign-compare)
17+
if (APPLE)
18+
# shut up c99 extensions warning I get on my system due to arm_neon.h
19+
list(APPEND WARNING_FLAGS -Wno-c99-extensions)
20+
endif()
21+
list(APPEND C_FLAGS -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes
22+
-Werror=implicit-int -Werror=implicit-function-declaration)
23+
list(APPEND CXX_FLAGS -Wmissing-declarations -Wmissing-noreturn)
24+
25+
list(APPEND C_FLAGS ${WARNING_FLAGS})
26+
list(APPEND CXX_FLAGS ${WARNING_FLAGS})
27+
28+
get_flags(${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION})
29+
30+
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${C_FLAGS};${GF_C_FLAGS}>"
31+
"$<$<COMPILE_LANGUAGE:CXX>:${CXX_FLAGS};${GF_CXX_FLAGS}>")
32+
else()
33+
# todo : msvc
34+
set(C_FLAGS "")
35+
set(CXX_FLAGS "")
36+
endif()
37+
endif()
38+
39+
1440
add_library(llama
1541
../include/llama.h
1642
llama.cpp
@@ -34,9 +60,9 @@ add_library(llama
3460
unicode-data.cpp
3561
)
3662

37-
target_include_directories(llama PUBLIC . ../include ../common)
63+
target_include_directories(llama PUBLIC . ../include)
3864
target_include_directories(llama PRIVATE ../ggml/src)
39-
target_compile_features (llama PUBLIC cxx_std_11) # don't bump
65+
target_compile_features (llama PUBLIC cxx_std_17)
4066

4167
target_link_libraries(llama PUBLIC ggml)
4268

src/llama-build-context.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,11 @@ void llm_build_context::llm_build_kv_store(
455455
int64_t il) {
456456
const int64_t n_ctx = cparams.n_ctx;
457457

458-
const int64_t n_embd_k_gqa = hparams.n_embd_k_gqa(il);
458+
//const int64_t n_embd_k_gqa = hparams.n_embd_k_gqa(il);
459459
const int64_t n_embd_v_gqa = hparams.n_embd_v_gqa(il);
460460

461-
const int64_t n_head = hparams.n_head(il);
462461
const int64_t n_head_kv = hparams.n_head_kv(il);
463462
const int64_t n_embd_head_k = hparams.n_embd_head_k;
464-
const int64_t n_embd_head_v = hparams.n_embd_head_v;
465463

466464
GGML_ASSERT(kv.size == n_ctx);
467465

@@ -957,7 +955,7 @@ static ggml_tensor * llm_build_kqv(
957955
const int64_t n_head = hparams.n_head(il);
958956
const int64_t n_head_kv = hparams.n_head_kv(il);
959957
const int64_t n_embd_head_k = hparams.n_embd_head_k;
960-
const int64_t n_embd_k_gqa = hparams.n_embd_k_gqa(il);
958+
//const int64_t n_embd_k_gqa = hparams.n_embd_k_gqa(il);
961959
const int64_t n_embd_head_v = hparams.n_embd_head_v;
962960
const int64_t n_embd_v_gqa = hparams.n_embd_v_gqa(il);
963961

@@ -1082,7 +1080,7 @@ static ggml_tensor * llm_build_kqv(
10821080
auto r2v = q->ne[2] / v->ne[2];
10831081
n_step = q->ne[2];
10841082
n_per_step = 1;
1085-
ggml_tensor * kqv;
1083+
ggml_tensor * kqv = nullptr;
10861084
for (int i12 = 0; i12 < q->ne[2]; i12 += n_per_step) {
10871085
int this_ne12 = i12 + n_per_step <= q->ne[2] ? n_per_step : q->ne[2] - i12;
10881086
int i02 = i12/r2k;
@@ -5889,7 +5887,7 @@ ggml_cgraph * llm_build_context::build_deepseek2() {
58895887

58905888
if (lctx.cparams.mla_attn) {
58915889

5892-
ggml_tensor * kv_cache_trans;
5890+
ggml_tensor * kv_cache_trans = nullptr;
58935891

58945892
if (lctx.cparams.mla_attn == 1 && !lctx.cparams.flash_attn) {
58955893
ggml_tensor * kv_cache_trans_view = ggml_view_2d(ctx0, kv_self.v_l[il], n_tokens, kv_lora_rank,
@@ -6018,9 +6016,9 @@ ggml_cgraph * llm_build_context::build_deepseek2() {
60186016
}
60196017
else {
60206018

6021-
ggml_tensor * kqv_compressed;
6019+
ggml_tensor * kqv_compressed = nullptr;
60226020

6023-
auto wkv_b = model.layers[il].wkv_b;
6021+
//auto wkv_b = model.layers[il].wkv_b;
60246022
auto wk_b = model.layers[il].wk_b->ne[1] == kv_lora_rank ? model.layers[il].wk_b
60256023
: ggml_reshape_3d(ctx0, model.layers[il].wk_b, n_embd_head_qk_nope, kv_lora_rank, n_head);
60266024

src/llama-load-tensors.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,23 +216,23 @@ ggml_context * create_tensors_helper::ctx_for_layer_split(int i) const {
216216
}
217217

218218
#define LOADING_PRELUDE \
219-
const auto & hparams = model.hparams; \
220-
const int64_t n_layer = hparams.n_layer; \
221-
const int64_t n_head = hparams.n_head(); \
222-
const int64_t n_head_kv = hparams.n_head_kv(); \
223-
const int64_t n_embd = hparams.n_embd; \
224-
const int64_t n_embd_k_gqa = hparams.n_embd_k_gqa(); \
225-
const int64_t n_embd_v_gqa = hparams.n_embd_v_gqa(); \
226-
const int64_t n_embd_head_k = hparams.n_embd_head_k; \
227-
const int64_t n_embd_head_v = hparams.n_embd_head_v; \
228-
const int64_t n_ff = hparams.n_ff(); \
229-
const int64_t n_embd_gqa = n_embd_v_gqa; \
230-
const int64_t n_vocab = hparams.n_vocab; \
231-
const int64_t n_vocab_type = hparams.n_vocab_type; \
232-
const int64_t n_rot = hparams.n_rot; \
233-
const int64_t n_expert = hparams.n_expert; \
234-
const int64_t n_expert_used = hparams.n_expert_used; \
235-
const int64_t n_ctx_train = hparams.n_ctx_train; \
219+
[[maybe_unused]] const auto & hparams = model.hparams; \
220+
[[maybe_unused]] const int64_t n_layer = hparams.n_layer; \
221+
[[maybe_unused]] const int64_t n_head = hparams.n_head(); \
222+
[[maybe_unused]] const int64_t n_head_kv = hparams.n_head_kv(); \
223+
[[maybe_unused]] const int64_t n_embd = hparams.n_embd; \
224+
[[maybe_unused]] const int64_t n_embd_k_gqa = hparams.n_embd_k_gqa(); \
225+
[[maybe_unused]] const int64_t n_embd_v_gqa = hparams.n_embd_v_gqa(); \
226+
[[maybe_unused]] const int64_t n_embd_head_k = hparams.n_embd_head_k; \
227+
[[maybe_unused]] const int64_t n_embd_head_v = hparams.n_embd_head_v; \
228+
[[maybe_unused]] const int64_t n_ff = hparams.n_ff(); \
229+
[[maybe_unused]] const int64_t n_embd_gqa = n_embd_v_gqa; \
230+
[[maybe_unused]] const int64_t n_vocab = hparams.n_vocab; \
231+
[[maybe_unused]] const int64_t n_vocab_type = hparams.n_vocab_type; \
232+
[[maybe_unused]] const int64_t n_rot = hparams.n_rot; \
233+
[[maybe_unused]] const int64_t n_expert = hparams.n_expert; \
234+
[[maybe_unused]] const int64_t n_expert_used = hparams.n_expert_used; \
235+
[[maybe_unused]] const int64_t n_ctx_train = hparams.n_ctx_train; \
236236
if (n_expert > 0 && hparams.n_expert_used == 0) { \
237237
throw std::runtime_error("model has expert layers but no expert layers are used"); \
238238
} \

src/llama-sampling.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,6 @@ void llama_sample_xtc_impl(struct llama_sampling * smpl, llama_token_data_array
450450

451451
llama_sample_softmax_impl(nullptr, candidates);
452452

453-
auto cur_size = candidates->size;
454-
455453
int pos_last = 0;
456454

457455
for (size_t i = 0; i < candidates->size; ++i) {
@@ -471,7 +469,7 @@ void llama_sample_xtc_impl(struct llama_sampling * smpl, llama_token_data_array
471469
}
472470

473471
void llama_sample_top_n_sigma_impl(struct llama_sampling * smpl, llama_token_data_array * candidates, float top_n_sigma) {
474-
472+
475473
if (top_n_sigma <= 0.0f || candidates->size < 4) {
476474
// top_n_sigma <= 0: disabled
477475
// candidates->size < 4: no point in applying the transformation for fewer than 4 logits.
@@ -1132,14 +1130,15 @@ static void llama_sampler_grammar_free(struct llama_sampler* smpl) {
11321130
delete ctx;
11331131
}
11341132

1135-
static struct llama_sampler_i llama_sampler_grammar_i = {
1136-
/* .name = */ llama_sampler_grammar_name,
1137-
/* .accept = */ llama_sampler_grammar_accept_impl,
1138-
/* .apply = */ llama_sampler_grammar_apply,
1139-
/* .reset = */ llama_sampler_grammar_reset,
1140-
/* .clone = */ NULL,
1141-
/* .free = */ llama_sampler_grammar_free,
1142-
};
1133+
// ?
1134+
//static struct llama_sampler_i llama_sampler_grammar_i = {
1135+
// /* .name = */ llama_sampler_grammar_name,
1136+
// /* .accept = */ llama_sampler_grammar_accept_impl,
1137+
// /* .apply = */ llama_sampler_grammar_apply,
1138+
// /* .reset = */ llama_sampler_grammar_reset,
1139+
// /* .clone = */ NULL,
1140+
// /* .free = */ llama_sampler_grammar_free,
1141+
//};
11431142

11441143
struct llama_grammar* llama_sampler_init_grammar_impl(
11451144
const struct llama_vocab* vocab,
@@ -1152,7 +1151,7 @@ struct llama_grammar* llama_sampler_init_grammar_impl(
11521151
size_t num_trigger_tokens,
11531152
const char** trigger_patterns,
11541153
size_t num_trigger_patterns) {
1155-
auto* ctx = new llama_sampler_grammar;
1154+
// Huh? this is not used and leaks. auto* ctx = new llama_sampler_grammar;
11561155
struct llama_grammar* grammar;
11571156
if (grammar_str != nullptr && grammar_str[0] != '\0') {
11581157
// TODO: remove trigger_words support.

0 commit comments

Comments
 (0)