Skip to content

add ScriptedLogitsModel - #719

Merged
davidkoski merged 2 commits into
mainfrom
scripted-3
Oct 23, 2026
Merged

davidkoski merged 2 commits into
mainfrom
scripted-3

Conversation

@davidkoski

Copy link
Copy Markdown
Member

Proposed changes

  • this model has a ScriptedScenario (containing a Transcript)
  • the Transcript gives the turns to be taken
  • this wraps an inner model that provides realistic (real actually) KVCache behavior

This allows developers to write tests like this:

    static let transcript = Transcript([
        .user("hello"),
        .assistant("hi there, how are you?"),
        .user("fine, and you?"),
        .assistant("doing well, thanks for asking."),
    ])

    @Test func testScriptedModel() async throws {
        // this can be used as a mock model that
        // works inside a ChatSession (or any other
        // way you would like to evaluate it)
        let scenario = try Self.scenario()
        let chat = ChatSession(scenario.context)

        let r1 = try await chat.respond(to: "hello")
        #expect(r1 == "hi there, how are you?")
        let r2 = try await chat.respond(to: "fine, and you?")
        #expect(r2 == "doing well, thanks for asking.")
    }

This wraps a real gemma3 model that does real KVCache work, but doesn't require any weight downloads.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: claude used to implement my design

- this model has a ScriptedScenario (containing a Transcript)
- the Transcript gives the turns to be taken
- this wraps an inner model that provides realistic (real actually) KVCache behavior
@davidkoski
davidkoski merged commit 260ada0 into main Oct 23, 2026
5 checks passed
@davidkoski
davidkoski deleted the scripted-3 branch October 23, 2026 17:16
wballard added a commit to swissarmyhammer/mlx-swift-lm-old that referenced this pull request Oct 24, 2026
Apply the upstream commits d02948b..991266a as a 3-way patch. CLAUDE.md is
excluded.

- 649f431 update for new TF32 comparison issues (ml-explore#721)
- 5ae2635 switch to MLXLogger (ml-explore#702)
- 260ada0 add ScriptedLogitsModel (ml-explore#719)
- 0ea4465 MLXVLM: Fix Qwen3VL attention masks after cache rotation (ml-explore#706)
- db2e7bf Expose request-scoped generation observations in ChatSession (ml-explore#714)
- 991266a Clear the MLX buffer cache after each prefill chunk (ml-explore#710)

Conflicts:
- Package.swift: both sides add the same README exclude; kept ours.
- ChatSession.swift: took upstream's transformer-based startGeneration and
  dropped the GenerationRun struct. Kept the fork's ReasoningHistory and
  thinkingEnabled capture. startGeneration takes an optional
  promptTokenCount, so the default path still counts the leading and
  checkpoint prefill tokens.

No new hybrid or recurrent models, so the post-merge ArraysCache.advance
checks do not apply.

Tests: MLXLMTests 894 XCTest and 1753 Swift Testing tests pass.
MLXGuidedGenerationTests 70, MLXFoundationModelsTests 374, CXGrammarTests 7,
MLXHuggingFaceMacrosTests 5 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants