-
Notifications
You must be signed in to change notification settings - Fork 6
fix: move callCapturing to *ModelInner (callers use model.callCapturing) #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -176,6 +176,27 @@ public class Qwen3ModelInner: Module, LayerPartitionable { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return norm(h) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public func callCapturing( | ||||||||||||||||||||||||
| _ inputs: MLXArray, cache: [KVCache?]? = nil, captureLayerIDs: Set<Int> | ||||||||||||||||||||||||
| ) -> (MLXArray, [Int: MLXArray]) { | ||||||||||||||||||||||||
| var h = embedTokens(inputs) | ||||||||||||||||||||||||
| let kvCache: [KVCache?] = { | ||||||||||||||||||||||||
| guard let c = cache else { return Array(repeating: nil, count: layers.count) } | ||||||||||||||||||||||||
| var normalized: [KVCache?] = Array(repeating: nil, count: layers.count) | ||||||||||||||||||||||||
| for (i, v) in c.prefix(layers.count).enumerated() { normalized[i] = v } | ||||||||||||||||||||||||
| return normalized | ||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||
| let mask = createAttentionMask(h: h, cache: kvCache.first ?? nil) | ||||||||||||||||||||||||
| var captured: [Int: MLXArray] = [:] | ||||||||||||||||||||||||
| for (i, layer) in layers.enumerated() { | ||||||||||||||||||||||||
| h = partitionedLayerCall(index: i, gpuLayerCount: gpuLayerCount) { | ||||||||||||||||||||||||
| layer(h, mask: mask, cache: kvCache[i]) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| if captureLayerIDs.contains(i) { captured[i] = h } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| return (norm(h), captured) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public class Qwen3Model: Module, LLMModel, KVCacheDimensionProvider { | ||||||||||||||||||||||||
|
|
@@ -208,29 +229,6 @@ public class Qwen3Model: Module, LLMModel, KVCacheDimensionProvider { | |||||||||||||||||||||||
| return out | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
| public func callCapturing(_ inputs: MLXArray, cache: [KVCache]?) -> (MLXArray, [MLXArray]) { | |
| var (out, captured) = model.callCapturing(inputs, cache: cache) | |
| if let lmHead { | |
| out = lmHead(out) | |
| } else { | |
| out = model.embedTokens.asLinear(out) | |
| } | |
| return (out, captured) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callCapturingwas removed from the publicLlamaModelwrapper. Since it was introduced as part of the public API in the prior PR, consider keeping a forwardingLlamaModel.callCapturing(...)that delegates tomodel.callCapturing(...)(optionally marking it deprecated) to avoid a breaking change for any clients already calling the wrapper type.