···130130 let kSize = kvHeads * headDim
131131 let qkvOut = qkv(x)
132132 let splits = split(qkvOut, indices: [qSize, qSize + kSize], axis: -1)
133133+ // Bail on a failed split (empty vector from a recorded MLX error)
134134+ // rather than trapping on the q/k/v subscripts below.
135135+ guard splits.count == 3 else { return x }
133136 var queries = splits[0]
134137 var keys = splits[1]
135138 var values = splits[2]
···264264 indices: [timeStepRank, timeStepRank + ssmStateSize],
265265 axis: -1
266266 )
267267+ // Bail on a failed split rather than trapping on the subscripts below.
268268+ guard splits.count == 3 else { return (x, state ?? x) }
267269 var delta = splits[0]
268270 var B = splits[1]
269271 var C = splits[2]
···294296 ) {
295297 let xz = inProj(x)
296298 let splits = xz.split(parts: 2, axis: -1)
299299+ // Bail on a failed split rather than trapping on the subscripts below.
300300+ guard splits.count == 2 else { return (x, (x, x)) }
297301 var x = splits[0]
298302 let z = splits[1]
299303
···206206 public func callAsFunction(_ x: MLXArray, cache: MambaCache?) -> MLXArray {
207207 let BCx = inProj(x)
208208 let BCxSplit = BCx.split(parts: 3, axis: -1)
209209+ // Bail on a failed split (empty vector from a recorded MLX error)
210210+ // rather than trapping on the subscripts below.
211211+ guard BCxSplit.count == 3 else { return x }
209212 let B = BCxSplit[0]
210213 let C = BCxSplit[1]
211214 let x = BCxSplit[2]
···207207 ) -> MLXArray {
208208 let BCx = inProj(x)
209209 let parts = BCx.split(parts: 3, axis: -1)
210210+ // Bail on a failed split rather than trapping on the subscripts below.
211211+ guard parts.count == 3 else { return x }
210212 let B = parts[0]
211213 let C = parts[1]
212214 let xComp = parts[2]
···290290 let convOut = silu(conv1d(convInput))
291291292292 let convSplit = MLX.split(convOut, indices: [keyDim, 2 * keyDim], axis: -1)
293293+ // A failed split (e.g. a checkpoint whose conv width disagrees with
294294+ // keyDim*2 + valueDim) records an MLX error and returns an empty
295295+ // vector; subscripting it traps the process before the recorded error
296296+ // can surface. Bail with the input so the enclosing withError scope
297297+ // throws the real diagnostic at exit. (Same guard as NemotronH.)
298298+ guard convSplit.count == 3 else { return inputs }
293299 let q = convSplit[0].reshaped(B, S, numKHeads, headKDim)
294300 let k = convSplit[1].reshaped(B, S, numKHeads, headKDim)
295301 let v = convSplit[2].reshaped(B, S, numVHeads, headVDim)
···465471466472 let qProjOutput = qProj(x)
467473 let qSplit = qProjOutput.reshaped(B, L, attentionHeads, -1).split(parts: 2, axis: -1)
474474+ // Guard the query/gate split: an empty result from a recorded MLX error
475475+ // would trap on subscript before the diagnostic can surface.
476476+ guard qSplit.count == 2 else { return x }
468477 var queries = qSplit[0]
469478 let gate = qSplit[1].reshaped(B, L, -1)
470479