Skip to content

Commit a8cba73

Browse files
committed
Set HF_HOME environment before importing from diffusers
diffusers uses this environment variable to automatically downloads files on import. weird side effect to do that amount of actual work on import.
1 parent f8601c2 commit a8cba73

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

studio.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
import time
66
from pathlib import PurePath
77

8+
9+
# Set environment variables
10+
STUDIO_HF_HOME = os.path.abspath(os.path.realpath(os.path.join(os.path.dirname(__file__), './hf_download')))
11+
# maybe only set HF_HOME if the directory exists, providing an opt-in migration path for users
12+
# make sure to document this behavior if the HF_HOME changes in the future
13+
# Set the HF_HOME to the studio's hf_download directory
14+
# HF_HOME Must be set to its expected value prior to importing diffusers and transformers
15+
os.environ['HF_HOME'] = STUDIO_HF_HOME
16+
os.environ['TOKENIZERS_PARALLELISM'] = 'false' # Prevent tokenizers parallelism warning
17+
818
# Site packages
919
from diffusers import AutoencoderKLHunyuanVideo
1020
from transformers import LlamaModel, CLIPTextModel, LlamaTokenizerFast, CLIPTokenizer
@@ -28,13 +38,7 @@
2838
from modules.ui.queue import format_queue_status
2939
from modules.video_queue import JobStatus
3040

31-
# Set environment variables
32-
STUDIO_HF_HOME = os.path.abspath(os.path.realpath(os.path.join(os.path.dirname(__file__), './hf_download')))
33-
# maybe only set HF_HOME if the directory exists, providing an opt-in migration path for users
34-
# make sure to document this behavior if the HF_HOME changes in the future
35-
# Set the HF_HOME to the studio's hf_download directory
36-
os.environ['HF_HOME'] = STUDIO_HF_HOME
37-
os.environ['TOKENIZERS_PARALLELISM'] = 'false' # Prevent tokenizers parallelism warning
41+
3842

3943
# Try to suppress annoyingly persistent Windows asyncio proactor errors
4044
if os.name == 'nt': # Windows only

0 commit comments

Comments
 (0)