Hello there! I tried my best again and here what I got:
First
If you replace MTLCommandBuffer with MPSCommandBuffer
func encodeTrainingBatch(commandBuffer: MPSCommandBuffer,
sourceTensorData: MPSGraphTensorData,
labelsTensorData: MPSGraphTensorData,
completion: ((Float) -> Void)?) -> MPSGraphTensorData {
and call it like this:
let commandBuffer = gCommandQueue.makeCommandBuffer()!
let mpsCommandBuffer = MPSCommandBuffer(commandBuffer: commandBuffer)
var yLabels: MPSNDArray? = nil
let xInput = dataset.getRandomTrainingBatch(device: gDevice, batchSize: batchSize, labels: &yLabels)
_ = classiferGraph.encodeTrainingBatch(commandBuffer: mpsCommandBuffer,
sourceTensorData: MPSGraphTensorData(xInput),
labelsTensorData: MPSGraphTensorData(yLabels!),
completion: updateProgressCubeAndLoss)
mpsCommandBuffer.commitAndContinue()
it starts working... But only on iPad version on Mac :D It won't do anything on physical iPhone device (more on this down the line)
Second one
If you replace graph.encode(to: to graph.runAsync( you no longer need to control commandBuffer and it's also solves the issue
Third
As I mentioned previously, you can replace MTLCommandBuffer with MPSCommandBuffer it will solve the issue on iPad build running on macOS. BUT it not working on physical iPhone. I mean, it doesn't crash, but descriptor not calling completionHandler.
BUT
If you add completion handler with addCompletedHandler on commandBuffer, it WILL run!
Appendix
I don't know why it works the way I explained before, but it seems that for now best way is to use runAsync because it does not need MPSCommandBuffer which cause the bug #1 and it calls completionHandler of MPSGraphExecutionDescriptor in every configuration
Hope it will help someone and I hope for Apple developers answers >_>
Topic:
Machine Learning & AI
SubTopic:
General
Tags: