[GH-ISSUE #295] [Enhancement] Respect the XDG_CACHE_HOME variable for checkpoint storage #253

Open
opened 2026-10-31 21:13:00 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @Kiyos on GitHub (Oct 19, 2022).
Original GitHub issue: https://github.com/openai/CLIP/issues/295

For the purpose of bringing order (and for portability), I propose the following patch for clip/clip.py:

--- clip.py	Wed Oct 19 20:37:09 2022
+++ clip.xdg.py	Wed Oct 19 20:39:34 2022
@@ -108,3 +108,3 @@
     download_root: str
-        path to download the model files; by default, it uses "~/.cache/clip"
+        path to download the model files; by default, it uses "$XDG_CACHE_HOME/clip" or "~/.cache/clip"
 
@@ -119,3 +119,3 @@
     if name in _MODELS:
-        model_path = _download(_MODELS[name], download_root or os.path.expanduser("~/.cache/clip"))
+        model_path = _download(_MODELS[name], download_root or os.path.join(os.getenv('XDG_CACHE_HOME', os.path.expanduser("~/.cache")), "clip"))
     elif os.path.isfile(name):

More about XDG environment variables: https://xdgbasedirectoryspecification.com/

Originally created by @Kiyos on GitHub (Oct 19, 2022). Original GitHub issue: https://github.com/openai/CLIP/issues/295 For the purpose of bringing order (and for portability), I propose the following patch for clip/clip.py: ``` --- clip.py Wed Oct 19 20:37:09 2022 +++ clip.xdg.py Wed Oct 19 20:39:34 2022 @@ -108,3 +108,3 @@ download_root: str - path to download the model files; by default, it uses "~/.cache/clip" + path to download the model files; by default, it uses "$XDG_CACHE_HOME/clip" or "~/.cache/clip" @@ -119,3 +119,3 @@ if name in _MODELS: - model_path = _download(_MODELS[name], download_root or os.path.expanduser("~/.cache/clip")) + model_path = _download(_MODELS[name], download_root or os.path.join(os.getenv('XDG_CACHE_HOME', os.path.expanduser("~/.cache")), "clip")) elif os.path.isfile(name): ``` More about XDG environment variables: https://xdgbasedirectoryspecification.com/
Author
Owner

@StefanoCiamma commented on GitHub (Feb 8, 2025):

Thanks @Kiyos I pached your proposal and my project goes on!
I hope in a soon patch for clip package, it's important to set cache path, using clip in specific part of project.

<!-- gh-comment-id:2644801273 --> @StefanoCiamma commented on GitHub (Feb 8, 2025): Thanks @Kiyos I pached your proposal and my project goes on! I hope in a soon patch for clip package, it's important to set cache path, using clip in specific part of project.
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openai/CLIP#253
No description provided.