Skip to content

Commit 8775112

Browse files
authored
fix LFM 2 for 2.6B variant (#409)
1 parent 95cc51f commit 8775112

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Libraries/MLXLLM/Models/LFM2.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,20 @@ public struct LFM2Configuration: Codable, Sendable {
2929
let blockFFNDimMultiplier: Float
3030
let blockAutoAdjustFFDim: Bool
3131
private let _fullAttnIdxs: [Int]?
32-
var fullAttnIdxs: [Int] { _fullAttnIdxs ?? Array(0 ..< hiddenLayers) }
32+
private let layerTypes: [String]?
33+
var fullAttnIdxs: [Int] {
34+
if let fullAttnIdxs = _fullAttnIdxs {
35+
return fullAttnIdxs
36+
}
37+
38+
if let layerTypes {
39+
return layerTypes.enumerated().compactMap { index, layerType in
40+
layerType == "full_attention" ? index : nil
41+
}
42+
}
43+
44+
return Array(0 ..< hiddenLayers)
45+
}
3346
let ropeTheta: Float
3447
var headDimensions: Int { hiddenSize / attentionHeads }
3548

@@ -50,6 +63,7 @@ public struct LFM2Configuration: Codable, Sendable {
5063
case blockFFNDimMultiplier = "block_ffn_dim_multiplier"
5164
case blockAutoAdjustFFDim = "block_auto_adjust_ff_dim"
5265
case _fullAttnIdxs = "full_attn_idxs"
66+
case layerTypes = "layer_types"
5367
case ropeTheta = "rope_theta"
5468
}
5569

@@ -77,6 +91,7 @@ public struct LFM2Configuration: Codable, Sendable {
7791
self.blockAutoAdjustFFDim =
7892
try container.decodeIfPresent(Bool.self, forKey: .blockAutoAdjustFFDim) ?? true
7993
self._fullAttnIdxs = try container.decodeIfPresent([Int].self, forKey: ._fullAttnIdxs)
94+
self.layerTypes = try container.decodeIfPresent([String].self, forKey: .layerTypes)
8095
self.ropeTheta = try container.decodeIfPresent(Float.self, forKey: .ropeTheta) ?? 1000000.0
8196
}
8297
}

0 commit comments

Comments
 (0)