Skip to content

Add presence penalty options to MLX generation - #450

Open
james-333i wants to merge 1 commit into
huggingface:mainfrom
james-333i:feat/mlx-presence-penalty
Open

james-333i wants to merge 1 commit into
huggingface:mainfrom
james-333i:feat/mlx-presence-penalty

Conversation

@james-333i

Copy link
Copy Markdown
Contributor

MLXLMCommon.GenerateParameters supports a presence penalty, but MLXLanguageModel.CustomGenerationOptions only exposes the repetition penalty. Some models need the presence penalty to avoid looping. Qwen-derived models recommend 1.5 with thinking off, and there is currently no way to pass it.

This adds two optional fields:

  • presencePenalty: additive penalty for tokens in the recent context. nil or 0 disables it.
  • presenceContextSize: the token window. nil uses mlx-swift-lm's default of 20.

Both are passed through in toGenerateParameters and toStructuredGenerateParameters. Left unset, generation is unchanged.

The existing sampling tests cover the defaults and an explicit override, and the README example and field list include the new options.

This does not depend on a newer mlx-swift-lm. The parameters already exist in 3.32.3.

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.

1 participant