Skip to content

Conversation

@ssam18
Copy link

@ssam18 ssam18 commented Nov 17, 2025

I was running some llama.cpp examples on a system with a German locale (de_DE) and noticed something odd - when llama-cli printed out the model metadata, all the float values had commas as decimal separators (like "0,000000") instead of periods. But when I ran llama-perplexity on the same model, it used periods normally.

After some digging, I found the issue was in the gguf_data_to_str() function in llama-impl.cpp. It was using std::to_string() to format floats, which respects the system's LC_NUMERIC locale setting. So depending on which tool you used and what locale it was running with, you'd get different formatting.

I've changed it to use std::ostringstream with std::locale::classic() instead, which always formats floats with a period as the decimal separator, regardless of the system locale. This should make the output consistent across all tools and locales.

Fixes #10613

The documentation stated that non-terminal symbols must be 'dashed lowercase
words' like 'move' or 'check-mate', but the actual parser supports much more
flexibility. Rule names can include:
- Uppercase letters (e.g., dataType, UPPER-CASE)
- Numbers (e.g., rule123)
- Both dashes and underscores

This was discovered when c.gbnf used 'dataType' with an uppercase letter,
which works correctly despite the documentation saying otherwise. Updated
the docs to accurately describe the parser's capabilities rather than
restrict them.

Fixes ggml-org#7720

Signed-off-by: Samaresh Kumar Singh <ssam3003@gmail.com>
Previously, std::to_string was used to format float and double values,
which respects the LC_NUMERIC locale setting. This caused inconsistent
output where some tools would print '0,000000' (comma) while others
printed '0.000000' (period), depending on the system locale.

Now using std::ostringstream with std::locale::classic() to ensure
float values are always formatted with a period as the decimal separator,
regardless of the system locale settings.

Signed-off-by: Samaresh Kumar Singh <ssam3003@gmail.com>
@ssam18 ssam18 requested a review from ggerganov as a code owner November 17, 2025 21:31
@ssam18
Copy link
Author

ssam18 commented Nov 17, 2025

This was a fun one to track down! The locale dependency was subtle enough that most people probably wouldn't notice it unless they happened to be running with a non-English locale. I'm glad I could spot the inconsistency and fix it.

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.

Misc. bug: inconsistent locale for printing GGUF kv data across examples

1 participant