Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLFeatureDescription "time_ids" crash #334

Open
vedlaicm opened this issue Jul 8, 2024 · 0 comments
Open

MLFeatureDescription "time_ids" crash #334

vedlaicm opened this issue Jul 8, 2024 · 0 comments

Comments

@vedlaicm
Copy link

vedlaicm commented Jul 8, 2024

I am creating a package with this command

ml-stable-diffusion-main % python -m python_coreml_stable_diffusion.torch2coreml --convert-unet --convert-text-encoder --convert-vae-decoder --model-version "diffusers/stable-diffusion-xl-1.0-inpainting-0.1" -o "/Users/cm/Documents/VisionOS/StableDiPackage/Sources/StableDiPackage/Models" --attention-implementation ORIGINAL --bundle-resources-for-swift-cli

and using it in Swift with

import Foundation
import StableDiffusion
import CoreImage
import CoreML
@available(macCatalyst 17.0, *)
public struct StableDIService {
    let pipeline : StableDiffusionXLPipeline
    public init() throws {
        print("\(type(of: self)) :: \(#function)")

        let url = Bundle.module.resourceURL!
        print("\(type(of: self)) :: \(#function) :: \(url)")

        let config = MLModelConfiguration()
        config.computeUnits = .cpuAndGPU
        pipeline = try StableDiffusionXLPipeline(
            resourcesAt: url,
            configuration: config,
            reduceMemory: false)
        print("\(type(of: self)) :: \(#function) :: post pipeline")

        try pipeline.loadResources()
        
        print("\(type(of: self)) :: \(#function) :: post load resources")

    }
    
    public func generateImage(image: CGImage) throws -> CIImage {
        print("\(type(of: self)) :: \(#function)")

        var prompt : PipelineConfiguration = .init(prompt: "Fill in blank area")
        prompt.imageCount = 1
        prompt.startingImage = image
        
        print("\(type(of: self)) :: \(#function) :: post pipeline config")
        
        let images = try pipeline.generateImages(configuration: .init(prompt: "Fill in blank area"), progressHandler: { progress in
            print(progress.step)
            return true
        })

        guard let image = images.first else {
            return .red
        }
        print("\(type(of: self)) :: \(#function) :: post generate")

        return CIImage(cgImage: image!)

    }
}

I am getting a crash in

public struct Unet: ResourceManaging {

at line 74

model.modelDescription.inputDescriptionsByName["time_ids"]!

Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant