From 68d72c747318f36746518e52b7362fb23a63d0d9 Mon Sep 17 00:00:00 2001 From: Pedro Cuenca Date: Tue, 14 Feb 2023 09:49:55 +0100 Subject: [PATCH] Do not show advanced settings if ane is not available. --- Diffusion-macOS/ControlsView.swift | 70 ++++++++++++------------ Diffusion-macOS/Diffusion_macOSApp.swift | 7 +++ 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/Diffusion-macOS/ControlsView.swift b/Diffusion-macOS/ControlsView.swift index dfdaf82..9e8ef1c 100644 --- a/Diffusion-macOS/ControlsView.swift +++ b/Diffusion-macOS/ControlsView.swift @@ -283,44 +283,46 @@ struct ControlsView: View { } }.foregroundColor(.secondary) } - Divider() - DisclosureGroup(isExpanded: $disclosedAdvanced) { - HStack { - Toggle("Use Neural Engine", isOn: $useANE).onChange(of: useANE) { value in - guard let currentModel = ModelInfo.from(modelVersion: model) else { return } - let variantDownloaded = isModelDownloaded(currentModel, variant: useANE ? .splitEinsum : .original) - if variantDownloaded { - updateANEState() - } else { - mustShowModelDownloadDisclaimer.toggle() + if hasANE { + Divider() + DisclosureGroup(isExpanded: $disclosedAdvanced) { + HStack { + Toggle("Use Neural Engine", isOn: $useANE).onChange(of: useANE) { value in + guard let currentModel = ModelInfo.from(modelVersion: model) else { return } + let variantDownloaded = isModelDownloaded(currentModel, variant: useANE ? .splitEinsum : .original) + if variantDownloaded { + updateANEState() + } else { + mustShowModelDownloadDisclaimer.toggle() + } } + .padding(.leading, 10) + Spacer() } - .padding(.leading, 10) - Spacer() - } - .alert("Download Required", isPresented: $mustShowModelDownloadDisclaimer, actions: { - Button("Cancel", role: .destructive) { useANE.toggle() } - Button("Download", role: .cancel) { updateANEState() } - }, message: { - Text("This setting requires a new version of the selected model.") - }) - } label: { - HStack { - Label("Advanced", systemImage: "terminal").foregroundColor(.secondary) - Spacer() - if disclosedAdvanced { - Button { - showAdvancedHelp.toggle() - } label: { - Image(systemName: "info.circle") - } - .buttonStyle(.plain) - .popover(isPresented: $showAdvancedHelp, arrowEdge: .trailing) { - advancedHelp($showAdvancedHelp) + .alert("Download Required", isPresented: $mustShowModelDownloadDisclaimer, actions: { + Button("Cancel", role: .destructive) { useANE.toggle() } + Button("Download", role: .cancel) { updateANEState() } + }, message: { + Text("This setting requires a new version of the selected model.") + }) + } label: { + HStack { + Label("Advanced", systemImage: "terminal").foregroundColor(.secondary) + Spacer() + if disclosedAdvanced { + Button { + showAdvancedHelp.toggle() + } label: { + Image(systemName: "info.circle") + } + .buttonStyle(.plain) + .popover(isPresented: $showAdvancedHelp, arrowEdge: .trailing) { + advancedHelp($showAdvancedHelp) + } } - } - }.foregroundColor(.secondary) + }.foregroundColor(.secondary) + } } } } diff --git a/Diffusion-macOS/Diffusion_macOSApp.swift b/Diffusion-macOS/Diffusion_macOSApp.swift index 623c1c4..1c2c59d 100644 --- a/Diffusion-macOS/Diffusion_macOSApp.swift +++ b/Diffusion-macOS/Diffusion_macOSApp.swift @@ -18,3 +18,10 @@ struct Diffusion_macOSApp: App { } let runningOnMac = true + +#if canImport(MLCompute) +import MLCompute +let hasANE = MLCDevice.ane() != nil +#else +let hasANE = false +#endif