Skip to content

Misc. bug: needless exception handling in llm_chat_detect_template #16964

@AnonN10

Description

@AnonN10

Name and Version

version: 6877 (10fcc41)
built with Clang 17.0.3 for x64

Operating systems

No response

Which llama.cpp modules do you know to be affected?

No response

Command line

Problem description & steps to reproduce

llm_chat_template_from_str throws, as it simply is a std::map lookup via std::map::at(), almost useless wrapper. Then in the llm_chat_detect_template function it is wrapped in a try-catch block, which ignores the exception std::out_of_range, yet still pollutes the output with "exception thrown" message, and incurs negligible overhead. My main issue is the output pollution, so I propose to refactor the function to use sentinel value LLM_CHAT_TEMPLATE_UNKNOWN that already exists, and to check for that instead of catching exceptions.

First Bad Commit

No response

Relevant log output

Exception thrown at 0x00007FFF2A7FCD29 in chat.exe: Microsoft C++ exception: std::out_of_range at memory location 0x00000005BF5CF780.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions