ml-stable-diffusion: MultilingualTextEncoder.swift:12:25: error: cannot find type 'NLContextualEmbedding' in scope
I apologize in advance if this is something so obvious for coders, but I don’t know much about this. I was looking into Stable Diffusion and I found this article, so I thought let’s give a try: https://www.createwithswift.com/generating-images-with-stable-diffusion-on-apple-silicon-with-core-ml/
I did everything there step by step, but when I run the terminal command to generate the image, I get several errors all related to the file MultilingualTextEncoder.swift:
% swift run StableDiffusionSample “a photo of a child looking at the stars” --resource-path /Users/myusername/AI_Stable_Diff/coreml-stable-diffusion-v1-4 --seed 93 --output-path /Users/myusername/AI_Stable_Diff/coreml-stable-diffusion-v1-4/output Fetching https://github.com/apple/swift-argument-parser.git from cache Fetched https://github.com/apple/swift-argument-parser.git (0.90s) Computing version for https://github.com/apple/swift-argument-parser.git Computed https://github.com/apple/swift-argument-parser.git at 1.2.0 (1.44s) Computed https://github.com/apple/swift-argument-parser.git at 1.2.0 (0.00s) Creating working copy for https://github.com/apple/swift-argument-parser.git Working copy of https://github.com/apple/swift-argument-parser.git resolved at 1.2.0 Building for debugging... /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:12:25: error: cannot find type 'NLContextualEmbedding' in scope let embeddingModel: NLContextualEmbedding ^~~~~~~~~~~~~~~~~~~~~ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:183:21: error: cannot find type 'NLScript' in scope var asNLScript: NLScript { ^~~~~~~~ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:34:31: error: cannot find 'NLContextualEmbedding' in scope self.embeddingModel = NLContextualEmbedding(script: script.asNLScript)! ^~~~~~~~~~~~~~~~~~~~~ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:60:81: error: 'nil' requires a contextual type let embedding = try embeddingModel.embeddingResult(for: text, language: nil) ^ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:12:25: error: cannot find type 'NLContextualEmbedding' in scope let embeddingModel: NLContextualEmbedding ^~~~~~~~~~~~~~~~~~~~~ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:183:21: error: cannot find type 'NLScript' in scope var asNLScript: NLScript { ^~~~~~~~ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:34:31: error: cannot find 'NLContextualEmbedding' in scope self.embeddingModel = NLContextualEmbedding(script: script.asNLScript)! ^~~~~~~~~~~~~~~~~~~~~ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:60:81: error: 'nil' requires a contextual type let embedding = try embeddingModel.embeddingResult(for: text, language: nil) ^ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:12:25: error: cannot find type 'NLContextualEmbedding' in scope let embeddingModel: NLContextualEmbedding ^~~~~~~~~~~~~~~~~~~~~ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:12:25: error: cannot find type 'NLContextualEmbedding' in scope let embeddingModel: NLContextualEmbedding ^~~~~~~~~~~~~~~~~~~~~ error: emit-module command failed with exit code 1 (use -v to see invocation) /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:12:25: error: cannot find type 'NLContextualEmbedding' in scope let embeddingModel: NLContextualEmbedding ^~~~~~~~~~~~~~~~~~~~~ /Users/myusername/AI_Stable_Diff/ml-stable-diffusion/swift/StableDiffusion/pipeline/MultilingualTextEncoder.swift:183:21: error: cannot find type 'NLScript' in scope var asNLScript: NLScript { ^~~~~~~~ [66/67] Compiling StableDiffusion BPETokenizer.swift
I have tried everything for the last 7 hours or so. I’m really surprised that when I do a search even for smaller parts of the error, even just one small portion of it, nothing of any real use comes up. It doesn’t seem to be something that happens to a lot of people or there would be posts everywhere.
I deleted the whole ml-stable-diffusion folder, downloaded it again with the git command from that article, and I even downloaded it from here, but neither of them work. The file MultilingualTextEncoder.swift is under <ml-stable-diffusion/swift/StableDiffusion/pipeline>.
I also kept going after that part in the article and started the project in Xcode, but it gives me tons of errors from the start, and it’s all related to the same thing, that “‘NLContextualEmbedding’ in scope” error.
Not knowing much about this, I have no idea if it’s a bug, or if I’m missing anything that I should’ve installed, but if it was, it wasn’t mentioned in the article.
Any clues?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 29 (1 by maintainers)
The current (12July) ml-stable-diffusion/main (source) now can be used in Xcode 14.3.1: https://github.com/apple/ml-stable-diffusion/pull/208
The 1.0.0 release package has not been updated for this new commit point.
Exactly, minimum requirements for ml-stable-diffusion-1.0.0 indicate Xcode 15. I recommend upgrading to Xcode 15 if possible. Otherwise, ml-stable-diffusion-0.4.0 should work with Xcode 14.3 but lack some of the key features that accelerate these models.
I think you need to be working with the Xcode 15 beta to get new frameworks that can talk NL and then run in macOS 14 beta to have the new libraries that get called. I tried building an app yesterday that used ml-stable-diffusion 1.0.0, with Xcode 14.3, and I got a half-dozen build errors about NL pieces. Then I ran the same code through the Xcode 15 beta 2 and it built successfully, and ran fine. If you want to work with Xcode 14 and macOS 13 instead, you should use the older ml-stable-diffusion 0.4.0 release.
And you probably didn’t find anything searching NL terms because it is too new to be in the wild yet.
I would say thanks but don’t spend your time on this. It’s not a big deal for me, and I won’t be able to produce anything that great with this, like what I can generate with Automatic1111, so I’d rather focus on that.
Interesting, I didn’t even consider that this would need betas of macOS and Xcode to run properly. But I’m wondering, the only file that has a problem is that multilingual one, and I don’t need multiple languages, is there a way to make this work without that file?
I’m definitely not installing macOS betas in my work Mac, or my personal Mac. I could do it in two older Macs, but they are too old for even Ventura.