ac75faa0cc
CI / build-and-test (push) Has been cancelled
- E4B-MarkBase model (42 layers, 4.4GB) loaded successfully - All Phase 1-6 tests passed (model loading, forward pass, vision/audio towers, token generation, performance) - All stress tests passed (5/5 in 127.6s) - Concurrent inference - Memory stress (67.5 tok/s, 0 NaN) - Continuous generation - Batch processing - Long-running stability - Swift Metal inference engine with multimodal support
89 lines
3.8 KiB
Swift
89 lines
3.8 KiB
Swift
import XCTest
|
|
@testable import MarkBase
|
|
|
|
final class RouterMatmulInputDebugTest: XCTestCase {
|
|
|
|
func testRouterMatmulInputDebug() throws {
|
|
print("\n═══════════════════════════════════════")
|
|
print(" Router Matmul Input Debug Test")
|
|
print("═══════════════════════════════════════\n")
|
|
|
|
let modelDir = "/Users/accusys/MarkBaseEngine/models/gemma-4-26b-a4b-it-4bit"
|
|
|
|
print("Loading model...")
|
|
fflush(stdout)
|
|
let engine = try MarkBaseEngine(autoCompile: true)
|
|
let model = try E4BModel(modelDir: modelDir, engine: engine, maxContextLength: 32)
|
|
|
|
print("\nStep 1: Get layer 0...")
|
|
fflush(stdout)
|
|
let layer0 = model.layers[0]
|
|
|
|
print("\nStep 2: Create input buffer (simulating pre_feedforward_norm output)...")
|
|
fflush(stdout)
|
|
|
|
// Create input buffer with realistic values (from hidden state)
|
|
let hs = model.hiddenSize
|
|
let inputBuffer = engine.device.makeBuffer(length: hs * MemoryLayout<Float>.size)!
|
|
|
|
// Fill with realistic values (similar to hidden state)
|
|
var inputData = [Float](repeating: 0, count: hs)
|
|
for i in 0..<hs {
|
|
inputData[i] = Float.random(in: -2.0...2.0) // Realistic hidden state range
|
|
}
|
|
memcpy(inputBuffer.contents(), &inputData, inputData.count * MemoryLayout<Float>.size)
|
|
|
|
print(" Input buffer created with random values (range -2.0 to 2.0)")
|
|
let inputSample = engine.readFloats(from: inputBuffer, count: 10)
|
|
print(" Input sample: \(inputSample)")
|
|
fflush(stdout)
|
|
|
|
print("\nStep 3: Test router matmul...")
|
|
fflush(stdout)
|
|
|
|
guard let router = layer0.routerProj else {
|
|
print(" ERROR: routerProj is nil!")
|
|
XCTFail("routerProj is nil")
|
|
return
|
|
}
|
|
|
|
print(" Router weights: bits=\(router.bits), inDim=\(router.inDim), outDim=\(router.outDim)")
|
|
fflush(stdout)
|
|
|
|
// Create output buffer
|
|
let outputBuffer = engine.device.makeBuffer(length: router.outDim * MemoryLayout<Float>.size)!
|
|
|
|
// Run router matmul
|
|
let cmdBuf = engine.commandQueue.makeCommandBuffer()!
|
|
try layer0.quantizedMatmul(engine: engine, cmdBuf: cmdBuf,
|
|
input: inputBuffer, weights: router,
|
|
output: outputBuffer)
|
|
cmdBuf.commit()
|
|
cmdBuf.waitUntilCompleted()
|
|
|
|
print(" Router matmul completed")
|
|
fflush(stdout)
|
|
|
|
// Read output
|
|
let routerOutput = engine.readFloats(from: outputBuffer, count: router.outDim)
|
|
print(" Router output first 10: \(routerOutput[0..<min(10, router.outDim)])")
|
|
print(" Router output max/min: \(routerOutput.max() ?? 0), \(routerOutput.min() ?? 0)")
|
|
print(" Router output mean: \(routerOutput.reduce(0, +) / Float(router.outDim))")
|
|
fflush(stdout)
|
|
|
|
// Check if output is all zeros
|
|
let hasNonzero = routerOutput.contains { $0 != 0 }
|
|
if hasNonzero {
|
|
print(" ✓ Router matmul works (has non-zero output)")
|
|
} else {
|
|
print(" ✗ Router matmul returns all zeros!")
|
|
XCTFail("Router matmul returns all zeros")
|
|
}
|
|
|
|
print("\n═══════════════════════════════════════")
|
|
print("✓ Router matmul input debug completed")
|
|
print("═══════════════════════════════════════\n")
|
|
fflush(stdout)
|
|
}
|
|
}
|