A parser for the GGUF file format. Done using swift-binary-parsing.
let fileData = try Data(contentsOf: url, options: .mappedIfSafe)
let gguf = try GGUF(parsing: fileData)
print("Version: \(gguf.header.version)")
print("Tensors: \(gguf.tensorInfos.count)")
// Access metadata
if let modelName = gguf.metadataValue(forKey: "general.name") {
print("Model: \(modelName)")
}
// Load float array
let tensor = try gguf.tensorFloatArray(at: 0, from: fileData)This project uses some of the code from:
This project uses swift-format. To format the code run:
swift format . -i -r --configuration .swift-format