Skip to content

Feature/refactor generate - #1722

Open
michalk8 wants to merge 25 commits into
ml-explore:mainfrom
michalk8:feature/refactor-generate
Open

Feature/refactor generate#1722
michalk8 wants to merge 25 commits into
ml-explore:mainfrom
michalk8:feature/refactor-generate

Conversation

@michalk8

Copy link
Copy Markdown
Collaborator

This PR refactors some choices in the generate.py file and fixes (in some part) the issues below:

Also fixes some issues in the KV cache's left padding (syncing too often); now does self.left_padding.tolist()[idx] instead of computing this using mx).

Gabriel Benedict and others added 25 commits August 5, 2026 09:10
Apertus emits tool calls as an array of single key objects wrapped in
<|tools_prefix|> ... <|tools_suffix|>, e.g.

    <|tools_prefix|>[{"get_weather": {"location": "London"}}]<|tools_suffix|>

Adds a parser for that format and infers it from the chat template, so
Apertus models work without an explicit tool_parser_type.

Also fixes reasoning detection. Apertus delimits deliberation with
<|inner_prefix|> ... <|inner_suffix|>, but carries unused <think>/</think>
tokens in its vocabulary, so _infer_thinking matched those instead and the
reasoning state was never reachable — deliberation was returned as content
rather than reasoning.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@michalk8
michalk8 requested a review from nastya236 August 13, 2026 14:56
@michalk8 michalk8 self-assigned this Aug 13, 2026

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible to split the PR into smaller ones?

Comment thread mlx_lm/models/cache.py
# Shift left to reduce padding
min_left_pad = self.left_padding.min().item()
mx.eval(self.left_padding)
min_left_pad = min(self.left_padding.tolist())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What this change does is moving computation of min from gpu to cpu?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants