Text-to-Image
MLX
MiniMax H3
Safetensors
English
apple-silicon
macos
image-to-image
image-editing
image-generation
Instructions to use devin-lai/MiniMax-H3-Image-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use devin-lai/MiniMax-H3-Image-mlx with MLX:
# Download the model from the Hub pip install huggingface_hub[hf_xet] hf download devin-lai/MiniMax-H3-Image-mlx --local-dir MiniMax-H3-Image-mlx
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Download experiments/v2_mps.swift from devin-lai/MiniMax-H3-Image-mlx: direct link, hf CLI and curl.
- Browser
- Download file 3.27 kB
-
https://huggingface.co/devin-lai/MiniMax-H3-Image-mlx/resolve/main/experiments/v2_mps.swift
- Command line
-
hf download hf://devin-lai/MiniMax-H3-Image-mlx/experiments/v2_mps.swift
-
curl -L -o v2_mps.swift https://huggingface.co/devin-lai/MiniMax-H3-Image-mlx/resolve/main/experiments/v2_mps.swift
3.27 kB
| // Synchronized MPSMatrix baseline, including CPU submission and shared buffers. | |
| // Build: swiftc -O experiments/v2_mps.swift -o cache/v2-mps | |
| import Foundation | |
| import Metal | |
| import MetalPerformanceShaders | |
| let device = MTLCreateSystemDefaultDevice()! | |
| let queue = device.makeCommandQueue()! | |
| let repetitions = 7 | |
| let tokens = Int(CommandLine.arguments.dropFirst().first ?? "4181")! | |
| var results: [[String: Any]] = [] | |
| for (k,n) in [(5376,21504),(7168,5376),(5376,28672),(14336,5376)] { | |
| for fp16 in [true,false] { | |
| let bytes = fp16 ? 2 : 4 | |
| let type: MPSDataType = fp16 ? .float16 : .float32 | |
| let ab = device.makeBuffer(length: tokens*k*bytes, options:.storageModeShared)! | |
| let bb = device.makeBuffer(length: n*k*bytes, options:.storageModeShared)! | |
| let cb = device.makeBuffer(length: tokens*n*bytes, options:.storageModeShared)! | |
| if fp16 { | |
| ab.contents().bindMemory(to:Float16.self, capacity:tokens*k).initialize(repeating:Float16(1.0/64),count:tokens*k) | |
| bb.contents().bindMemory(to:Float16.self, capacity:n*k).initialize(repeating:Float16(1.0/64),count:n*k) | |
| } else { | |
| ab.contents().bindMemory(to:Float.self, capacity:tokens*k).initialize(repeating:1.0/64,count:tokens*k) | |
| bb.contents().bindMemory(to:Float.self, capacity:n*k).initialize(repeating:1.0/64,count:n*k) | |
| } | |
| let a = MPSMatrix(buffer:ab,descriptor:MPSMatrixDescriptor(rows:tokens,columns:k,rowBytes:k*bytes,dataType:type)) | |
| let b = MPSMatrix(buffer:bb,descriptor:MPSMatrixDescriptor(rows:n,columns:k,rowBytes:k*bytes,dataType:type)) | |
| let c = MPSMatrix(buffer:cb,descriptor:MPSMatrixDescriptor(rows:tokens,columns:n,rowBytes:n*bytes,dataType:type)) | |
| let mul = MPSMatrixMultiplication(device:device,transposeLeft:false,transposeRight:true,resultRows:tokens,resultColumns:n,interiorColumns:k,alpha:1,beta:0) | |
| var wall: [Double] = [], gpu: [Double] = [] | |
| for trial in 0..<(repetitions+2) { | |
| let start = ProcessInfo.processInfo.systemUptime | |
| let command = queue.makeCommandBuffer()! | |
| mul.encode(commandBuffer:command,leftMatrix:a,rightMatrix:b,resultMatrix:c) | |
| command.commit() | |
| command.waitUntilCompleted() | |
| precondition(command.status == .completed, "MPS command failed") | |
| if trial>=2 { | |
| wall.append(1000*(ProcessInfo.processInfo.systemUptime-start)) | |
| gpu.append(1000*(command.gpuEndTime-command.gpuStartTime)) | |
| } | |
| } | |
| let y = fp16 ? Float(cb.contents().bindMemory(to:Float16.self,capacity:tokens*n)[0]) : cb.contents().bindMemory(to:Float.self,capacity:tokens*n)[0] | |
| precondition(y == Float(k)/4096, "Projection correctness check failed") | |
| let row: [String:Any] = ["backend":"MPSMatrixMultiplication","dtype":fp16 ? "float16":"float32","shape":[tokens,k,n],"median_ms":wall.sorted()[wall.count/2],"gpu_median_ms":gpu.sorted()[gpu.count/2],"samples_ms":wall,"gpu_samples_ms":gpu,"first_element":y,"expected":Float(k)/4096] | |
| results.append(row) | |
| let encoded = try! JSONSerialization.data(withJSONObject:row,options:[.sortedKeys]) | |
| print(String(data:encoded,encoding:.utf8)!) | |
| fflush(stdout) | |
| } | |
| } | |