Enhance load_config function to check for config file existence and i…#701
Merged
awni merged 2 commits intoDec 27, 2025
Merged
Conversation
…ncorporate eos_token_id from generation_config.json if available
Contributor
Author
|
Hi @awni , I hope you’re doing well. Could you please take a look at this pull request when you have time? Before the fix, the output contains repeated and unintended <end_of_turn> tokens, for example: After the fix, the output is properly terminated and behaves as expected: Thank you very much for your time and for reviewing this change. I’d really appreciate any feedback you may have. |
b2e7747 to
b14694e
Compare
Contributor
Author
|
Thank you very much for taking a look @awni . It’s a small fix, but I believe it can help improve generation for some models. |
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.
Fix: Prioritize
eos_token_idfromgeneration_config.jsonProblem
The
load_configfunction was only reading configuration fromconfig.json. However, in many HuggingFace models,eos_token_idis sometimes missing fromconfig.jsonand is instead defined ingeneration_config.json. In HuggingFace's model structure,generation_config.jsonis the standard location for generation-related parameters likeeos_token_id, and it should be used as a fallback or override whenconfig.jsondoesn't contain this value.When
eos_token_idwas missing fromconfig.json, the code would fail to load it, leading to incorrect or missingeos_token_idvalues. This could cause generation to stop at the wrong token or fail to stop when appropriate.Solution
Updated
load_configto:config.json(as before)generation_config.jsonexistseos_token_id, use that value to override or populate theeos_token_idin the configThis ensures that
eos_token_idis correctly loaded even when it's missing fromconfig.json, by reading it fromgeneration_config.jsonwhere it's commonly defined in HuggingFace models.Changes
mlx_lm/utils.py::load_config()to check for and readgeneration_config.jsoneos_token_idfromgeneration_config.jsonwhen availableconfig.jsonfileImpact
This fix ensures correct EOS token handling for models where
eos_token_idis missing fromconfig.jsonbut present ingeneration_config.json. This improves generation accuracy and compatibility with standard HuggingFace model formats where generation-specific parameters are stored separately from the base model configuration.