Repository navigation
cb2-7 (chain 7/8): scheduler-aware loadModelContainer overloads (batching front door) - #30
ronaldmannak wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces scheduler-aware model loading overloads in ModelFactory+Scheduler.swift to enable continuous batching using InferenceScheduler. The feedback points out an incomplete code example in the documentation header that is missing the required 'from' and 'using' parameters, which would cause compilation errors if copied directly.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| // ```swift | ||
| // let container = try await loadModelContainer( | ||
| // configuration: .init(id: "mlx-community/Qwen3-4B-4bit"), | ||
| // scheduler: InferenceScheduler(), | ||
| // promptCache: LRUPromptCache(maxBytes: 2 << 30) | ||
| // ) | ||
| // ``` |
There was a problem hiding this comment.
The code example in the comment is missing the required from and using parameters (from: downloader, using: tokenizerLoader). Since loadModelContainer does not have an overload that omits these parameters, copying this example as-is will result in a compilation error. Let's update the example to include them.
// ```swift
// let container = try await loadModelContainer(
// from: downloader,
// using: tokenizerLoader,
// configuration: .init(id: "mlx-community/Qwen3-4B-4bit"),
// scheduler: InferenceScheduler(),
// promptCache: LRUPromptCache(maxBytes: 2 << 30)
// )
// ```There was a problem hiding this comment.
Fixed. The example now includes the required from:/using: arguments with placeholder comments -- MLXLMCommon cannot reference the MLXHuggingFace convenience macros from its docs. Thanks for catching this; the copy-paste version would not have compiled.
Generated by Claude Code
d828eef to
7486aa0
Compare
9b40345 to
5ff107c
Compare
7486aa0 to
f5c37d3
Compare
5ff107c to
d8bfc13
Compare
f5c37d3 to
8ccb571
Compare
d8bfc13 to
0f0daf3
Compare
8ccb571 to
06a44bc
Compare
0f0daf3 to
55b17a0
Compare
06a44bc to
a4e9c0c
Compare
55b17a0 to
7ab7720
Compare
a4e9c0c to
cf809fc
Compare
7ab7720 to
2b60e84
Compare
cf809fc to
e8eb5a7
Compare
2b60e84 to
a1fe6db
Compare
a1fe6db to
a3197df
Compare
e8eb5a7 to
d664757
Compare
a3197df to
a5db974
Compare
d664757 to
1c9e228
Compare
Convenience front door for continuous batching: optional overloads of loadModelContainer / loadContainer that install an InferenceScheduler (and optional prompt cache) at load time, instead of requiring manual ModelContainer(context:scheduler:promptCache:) construction. Pure composition in one new file -- no existing declaration changes, and `scheduler` has no default value so the plain loaders keep resolving exactly as before (zero-overhead default untouched). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jxj5hG5kLt2kkr5WDmHU5S
a5db974 to
6fa7071
Compare
1c9e228 to
e12db4b
Compare
Chain 7/8 — stacked on #29 (
cb2-6-scheduler). Optional convenience layer; the batching mechanism is complete without it.What
One new self-contained file (
ModelFactory+Scheduler.swift) adding overloads ofloadModelContainer/loadContainerthat install anInferenceScheduler(and optional cross-request prompt cache) at load time:Why
Without this, the loaders always produce a scheduler-free container (
_wrap→ModelContainer(context:)), and sinceModelContainer.scheduleris immutable by design (that immutability keeps the zero-overhead single-stream default airtight), the only way to opt into continuous batching is to bypass the loaders and constructModelContainer(context:scheduler:promptCache:)by hand. These overloads make the opt-in discoverable at the API users actually call.Design constraints
schedulerhas no default value, so these overloads never compete with the plain loaders in overload resolution — every existing call site keeps resolving to the original functions and keeps today's scheduler-free container.ModelContextthrough the existing (trampoline-dispatched)loadModelpaths and wraps it with the existing scheduler-awareModelContainerinitializer. No existing declaration changes; theModelFactoryprotocol surface is untouched.generateroutes VLM contexts to the single-stream path;generateBatchedrejects them), so misuse is harmless.Why a separate PR
This is an API-surface taste call — whether batching should be visible in the top-level loader signatures — and is split out so it can be accepted or declined independently of the mechanism in PRs 1–6. Declining this PR removes nothing from the batching feature itself.
Update 2026-07-13: rebased onto the audit-hardened chain; content unchanged. Note the upstream-coordination flag in
reviews/continuous-batching-audit-2026-07-13.md: ml-explore/mlx-swift-lm PR ml-explore#335 deprecatesModelContainerin favor of a SendableModelContext, so this front door (and the container API in 6/8) should be re-confirmed against that direction before upstreaming.🤖 Generated with Claude Code
https://claude.ai/code/session_011xThp8Po34ruijNS8TaShn