Cannot load .mtlpackage to MTLLibrary

After watching WWDC 2025 session "Combine Metal 4 machine learning and graphics", I have decided to give it a shot to integrate the latest MTL4MachineLearningCommandEncoder to my existing render pipeline. After a lot of trial and errors, I managed to set up the pipeline and have the app compiled.

However, I am now stuck on creating a MTLLibrary with .mtlpackage.

Here is the code I have to create a MTLLibrary according the WWDC session https://developer.apple.com/videos/play/wwdc2025/262/?time=550:

        let coreMLFilePath = bundle.path(forResource: "my_model", ofType: "mtlpackage")!
       let coreMLURL = URL(string: coreMLFilePath)!
       do {
             metalDevice.makeLibrary(URL: coreMLURL)
       } catch {
             print("error: \(error)")
       }

With the above code, I am getting error:


Error Domain=MTLLibraryErrorDomain Code=1 "Invalid metal package" UserInfo={NSLocalizedDescription=Invalid metal package}

What is the correct way to create a MTLLibrary with .mtlpackage? Do I see this error because the .mtlpackage I am using is incorrect? How should I go with debugging this? I'd really appreciate if I could get some help on this as I have been stuck with it for some time now. Thanks in advance!

Cannot load .mtlpackage to MTLLibrary
 
 
Q