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

Application support path fix #60

Merged
merged 2 commits into from Jul 12, 2023
Merged

Application support path fix #60

merged 2 commits into from Jul 12, 2023

Conversation

ghost
Copy link

@ghost ghost commented Jun 25, 2023

I discovered that post Path.swift fix the location of the default models folder was inconsistent. This PR creates a new internal API to access the user domain applicationSupportDirectory to improve consistency. If there is an issue with the user domain then this code will fall back to URL.applicationSupportDirectory but under normal operating conditions it should use the app bundle.

In the previous code I was using URL.applicationSupportDirectory directly which results in /Users//Library/Application Support/hs-diffusion-models

Whereas the previous and correct usage is
/Users//Library/Application Support/hf-diffusion-models

I've put the new applicationSupportURL function inside Settings. To access it use Settings.shared.applicationSupportURL()

Is Settings.shared a reasonable location for such an API? It's not quite a Util function.

(Note: this is extracted from the last commit to #59 and should commit before and then merge back into 59 before it's reviewed.)

I discovered that post Path.swift fix the location of the default models folder was inconsistent. This PR creates a new internal API to access the user domain applicationSupportDirectory to improve consistency. If there is an issue with the user domain then this code will fall back to URL.applicationSupportDirectory but under normal operating conditions it should use the app bundle.

In the previous code I was using URL.applicationSupportDirectory directly which results in
/Users/<uname>/Library/Application Support/hs-diffusion-models

Whereas the previous and correct usage is
/Users/<uname>/Library/Application Support/<bundle identifier>hf-diffusion-models

I've put the new applicationSupportURL function inside Settings. To access it use Settings.shared.applicationSupportURL()

Is Settings.shared a reasonable location for such an API? It's not quite a Util function.
Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did this issue manifest in practice? Was it using different locations at different times?

It's fine to add this as long as we make sure that:

  • It works on iOS and macOS
  • It works with/without code signing. The default locations change with code-signing, so maybe that was the reason you were seeing inconsistent paths?

I usually do development on Mac without code signing, but then to distribute the app we need to enable it of course. I think it doesn't matter that the locations don't match, as long as we don't break distribution builds :)

Also, it'd be nice to keep the same download location for distribution builds so people that installed the app from the Mac Store don't need to download the model again.

@ghost
Copy link
Author

ghost commented Jun 27, 2023

It was all in macOS Xcode testing, no signing issues. I noticed I didn't properly describe the two locations...
/Users/-user-/Library/Application Support/hf-diffusion-models
vs. the bundle ID...
/Users/-user-/Library/Application Support/com.huggingface.Diffusion/hf-diffusion-models

I'll make a test project and compare mac vs iOS FileManager vs. URL vs. Path.swift.

@ghost
Copy link
Author

ghost commented Jun 27, 2023

Sample code:
.onAppear() {
print("URL.applicationSupportDirectory")
print(URL.applicationSupportDirectory)
print("FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first")
print(FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!)
print("FileManager.default.temporaryDirectory")
print(FileManager.default.temporaryDirectory)
print("Path.applicationSupport / "hf-diffusion-models"")
print(Path.applicationSupport / "hf-diffusion-models")
print("URL.applicationSupportDirectory.appendingPathComponent("hf-diffusion-models")")
print(URL.applicationSupportDirectory.appendingPathComponent("hf-diffusion-models"))
}

Output:
iOS test:
URL.applicationSupportDirectory
file:///Users/-user-/Library/Developer/CoreSimulator/Devices/55E25E20-B2B5-4093-BB99-1F49921D632F/data/Containers/Data/Application/14AF9A03-2DEC-44F3-AF5E-6EDD6C429892/Library/Application%20Support/

FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
file:///Users/-user-/Library/Developer/CoreSimulator/Devices/55E25E20-B2B5-4093-BB99-1F49921D632F/data/Containers/Data/Application/14AF9A03-2DEC-44F3-AF5E-6EDD6C429892/Library/Application%20Support/

FileManager.default.temporaryDirectory
file:///Users/-user-/Library/Developer/CoreSimulator/Devices/55E25E20-B2B5-4093-BB99-1F49921D632F/data/Containers/Data/Application/14AF9A03-2DEC-44F3-AF5E-6EDD6C429892/tmp/

Path.applicationSupport / "hf-diffusion-models"
/Users/-user-/Library/Developer/CoreSimulator/Devices/55E25E20-B2B5-4093-BB99-1F49921D632F/data/Containers/Data/Application/14AF9A03-2DEC-44F3-AF5E-6EDD6C429892/Library/Application Support/hf-diffusion-models

URL.applicationSupportDirectory.appendingPathComponent("hf-diffusion-models")
file:///Users/-user-/Library/Developer/CoreSimulator/Devices/55E25E20-B2B5-4093-BB99-1F49921D632F/data/Containers/Data/Application/14AF9A03-2DEC-44F3-AF5E-6EDD6C429892/Library/Application%20Support/hf-diffusion-models

macOS test:

URL.applicationSupportDirectory
file:///Users/-user-/Library/Containers/com.huggingface.testMac/Data/Library/Application%20Support/

FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
file:///Users/-user-/Library/Containers/com.huggingface.testMac/Data/Library/Application%20Support/

FileManager.default.temporaryDirectory
file:///var/folders/mt/h675p97j56s_1y2s4955rfxm1122/T/com.huggingface.testMac/

Path.applicationSupport / "hf-diffusion-models"
/Users/-user-/Library/Containers/com.huggingface.testMac/Data/Library/Application Support/hf-diffusion-models

URL.applicationSupportDirectory.appendingPathComponent("hf-diffusion-models")
file:///Users/-user-/Library/Containers/com.huggingface.testMac/Data/Library/Application%20Support/hf-diffusion-models

Result: these are pretty consistent actually.
What I was seeing was instead of /Users/-user-/Library/Containers/com.huggingface.testMac/Data/Library/Application Support/hf-diffusion-models the models folder was being put one folder up at /Users/-user-/Library/Containers/com.huggingface.testMac/Data/Library/hf-diffusion-models

Therefore, to avoid accidental misshapen code I thought it would make sense to have our own internal API to call on the correct folder rather than reconstructing it each time we want to interact. Do you think that this submission, given the comparable results above, is overkill?

@pcuenca pcuenca mentioned this pull request Jul 12, 2023
@pcuenca
Copy link
Member

pcuenca commented Jul 12, 2023

Result: these are pretty consistent actually. What I was seeing was instead of /Users/-user-/Library/Containers/com.huggingface.testMac/Data/Library/Application Support/hf-diffusion-models the models folder was being put one folder up at /Users/-user-/Library/Containers/com.huggingface.testMac/Data/Library/hf-diffusion-models

Oh, I see. Do you know when was this happening?

@pcuenca pcuenca mentioned this pull request Jul 12, 2023
@@ -14,7 +14,7 @@ import ZIPFoundation
import StableDiffusion

class PipelineLoader {
static let models = URL.applicationSupportDirectory.appendingPathComponent("hf-diffusion-models")
static let models = Settings.shared.applicationSupportURL().appendingPathComponent("hf-diffusion-models")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Author

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing app bundle folder container.

remove bundle identifier in path to ensure backward compatibility with current live release version.
@pcuenca pcuenca merged commit 333e40c into huggingface:main Jul 12, 2023
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

Successfully merging this pull request may close these issues.

1 participant