@@ -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