Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Libraries/MLXVLM/Models/Paligemma.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private enum Vision {
@ModuleInfo(key: "position_embedding") var positionEmbedding: Embedding

let positions: Int
let positionIds: MLXArray
let _positionIds: MLXArray
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As it was updating weights expected to find a positionIds in the incoming weights, but it is really just a cached MLXArray.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This avoids the error loading the model.


public init(_ config: PaliGemmaConfiguration.VisionConfiguration) {
self._patchEmbedding.wrappedValue = Conv2d(
Expand All @@ -348,13 +348,13 @@ private enum Vision {
self._positionEmbedding.wrappedValue = Embedding(
embeddingCount: positions, dimensions: config.hiddenSize
)
self.positionIds = MLXArray(0 ..< positions)[.newAxis, 0...]
self._positionIds = MLXArray(0 ..< positions)[.newAxis, 0...]
}

public func callAsFunction(_ x: MLXArray) -> MLXArray {
var patchEmbeddings = self.patchEmbedding(x)
patchEmbeddings = patchEmbeddings.flattened(start: 1, end: 2)
let embeddings = patchEmbeddings + self.positionEmbedding(self.positionIds)
let embeddings = patchEmbeddings + self.positionEmbedding(self._positionIds)
return embeddings
}
}
Expand Down