fix some warnings from gcc and clang-tidy#3038
Merged
cebtenzzre merged 14 commits intoggml-org:masterfrom Sep 7, 2023
Merged
Conversation
There is a -Warray-bounds warning from g++ 13.2.1 in
test-llama-grammar.cpp that is a false-positive because there is a
ternary that special-cases zero in the std::vector code.
/usr/include/c++/13.2.1/bits/stl_algobase.h:398:17: warning: array subscript 0 is outside array bounds of ‘const llama_grammar_element* [0]’ [-Warray-bounds=]
398 | { *__to = *__from; }
| ~~~~~~^~~~~~~~~
bugprone-misplaced-widening-cast doesn't get along with casts needed for -Wsign-compare, and the 'misc' category has a few useful checks.
These are recommended by the 'readability-container-size-empty' and 'readability-simplify-boolean-expr' checks.
This is recommended by the 'performance-unnecessary-value-param' check.
According to the 'performance-no-automatic-move' check, this allows an automatic move of the return value (std::move) instead of a copy.
This is recommended by the 'clang-analyzer-deadcode.DeadStores' check.
This operator overload is not used anyway - explicitly deleting it seems
to have no effect on compilation.
train-text-from-scratch.cpp:174:16: warning: comparing object representation of type 'my_llama_hparams' which does not have a unique object representation; consider comparing the members of the object manually [bugprone-suspicious-memory-comparison]
return memcmp(this, &other, sizeof(my_llama_hparams));
^
This is recommended by the 'bugprone-exception-escape' check.
This is recommended by the 'performance-inefficient-vector-operation' check.
This is recommended by the 'readability-else-after-return' check.
This is recommended by the 'readability-redundant-string-cstr' check.
train-text-from-scratch.cpp:1991:61: warning: casting (double + 0.5) to integer leads to incorrect rounding; consider using lround (#include <cmath>) instead [bugprone-incorrect-roundings]
int impr_plot = std::isnan(opt->loss_after) ? 0 : -(int)(1 + (opt->loss_before - opt->loss_after) * 10.0f + 0.5f);
^
ggerganov
approved these changes
Sep 7, 2023
| *sched = min_sched + *sched * (1.0f - min_sched); | ||
|
|
||
| int impr_plot = std::isnan(opt->loss_after) ? 0 : -(int)(1 + (opt->loss_before - opt->loss_after) * 10.0f + 0.5f); | ||
| int impr_plot = std::isnan(opt->loss_after) ? 0 : -std::lround(1 + (opt->loss_before - opt->loss_after) * 10.0f); |
Member
There was a problem hiding this comment.
This is unrelated to the PR, but I just saw this:
@xaedes When would we expect nan? Isn't it better to guarantee that we will never receive nan here?
Collaborator
There was a problem hiding this comment.
When would we expect nan?
Actually only when messing up something with the optimizer or gradients during development.
When everything works as it should, then there should be no NANs.
When, during development, a NAN occurs the length of the "improvement plot bar" will be incredibly high, which will flood the console with single characters. The output before that could be useful in identifying the cause of the issue but will be lost.
To avoid flooding the console I added this ternary operator.
slaren
reviewed
Sep 7, 2023
(cherry picked from commit 5854f51)
Merged
Seunghhon
pushed a commit
to Seunghhon/llama.cpp
that referenced
this pull request
Apr 26, 2026
Co-authored-by: xaedes <xaedes@gmail.com>
phuongncn
pushed a commit
to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4
that referenced
this pull request
Apr 28, 2026
Co-authored-by: xaedes <xaedes@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See the commit log for the different improvements that have been made.
My fix in 22ff140 may need some scrutiny, but either way I want to avoid throwing unhandled exceptions where possible - calling abort() on e.g. I/O errors is not user-friendly. Wrapping the exception-throwing code in a try/catch is another option.