Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some warnings from gcc and clang-tidy #3038

Merged
merged 14 commits into from
Sep 7, 2023

Conversation

cebtenzzre
Copy link
Collaborator

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.

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);
                                                            ^
@@ -1988,7 +1962,7 @@ void opt_callback(void * vdata, float * sched) {
float min_sched = params->adam_min_alpha / params->adam_alpha;
*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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ggml-alloc.c Show resolved Hide resolved
@cebtenzzre cebtenzzre requested a review from slaren September 7, 2023 15:03
@cebtenzzre cebtenzzre merged commit 00d62ad into ggerganov:master Sep 7, 2023
@cebtenzzre cebtenzzre deleted the warnings-and-tidy branch September 7, 2023 17:22
@cebtenzzre cebtenzzre mentioned this pull request Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants