v2: EmbeddingGemma - single cmdBuf fix, needs Metal kernel compilation

This commit is contained in:
MarkBase Admin
2026-07-06 11:37:10 +08:00
parent dbec6b20ea
commit 5e060c7aea
2 changed files with 157 additions and 147 deletions
+29
View File
@@ -0,0 +1,29 @@
import XCTest
@testable import MarkBase
final class EmbeddingGemmaTest: XCTestCase {
func testLoadAndEmbed() throws {
let modelDir = "/Users/accusys/MarkBaseEngine/models/embeddinggemma-300m"
guard FileManager.default.fileExists(atPath: modelDir + "/model.safetensors") else {
XCTFail("Model not found"); return
}
let engine = try MarkBaseEngine(autoCompile: true)
let model = try EmbeddingGemmaModel(modelDir: modelDir, engine: engine)
XCTAssertEqual(model.config.numHiddenLayers, 24)
XCTAssertEqual(model.config.hiddenSize, 768)
let emb = try model.embed(text: "Hello world")
XCTAssertEqual(emb.count, 768)
// Check L2 norm is 1.0
var norm: Float = 0
for v in emb { norm += v * v }
norm = sqrt(norm)
XCTAssertEqual(norm, 1.0, accuracy: 0.001, "L2 norm should be 1.0")
// Check no NaN
XCTAssertFalse(emb.contains { $0.isNaN }, "No NaN values")
print("✓ Embedding dim=\(emb.count), norm=\(String(format: "%.4f", norm))")
}
}