futurespyhi commited on
Commit
297dc31
Β·
1 Parent(s): c87f4fd

1.modify the logic of downloading_xcodec_models: using git clone instead of huggingface_hub 2. modify .gitignore

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. download_models.py +81 -72
.gitignore CHANGED
@@ -108,6 +108,7 @@ flash_attn/
108
  # bcakup files
109
  packages.txt.backup
110
  requirements.txt.backup
 
111
 
112
  # test files
113
  tests/
 
108
  # bcakup files
109
  packages.txt.backup
110
  requirements.txt.backup
111
+ download_model.py.backup
112
 
113
  # test files
114
  tests/
download_models.py CHANGED
@@ -5,77 +5,86 @@ Downloads required model files from Hugging Face Hub at runtime to avoid storage
5
  """
6
 
7
  import os
 
8
  import shutil
9
  from pathlib import Path
10
- from huggingface_hub import hf_hub_download, snapshot_download
11
 
12
 
13
  def download_xcodec_models():
14
- """Download xcodec_mini_infer models from Hugging Face Hub"""
15
-
16
  # Base path for xcodec models
17
  xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
18
-
19
- print("πŸ“₯ Downloading xcodec_mini_infer models...")
20
-
21
  try:
22
- # Download the entire xcodec_mini_infer repository
23
- cache_dir = snapshot_download(
24
- repo_id="m-a-p/xcodec_mini_infer",
25
- cache_dir="/tmp/hf_cache",
26
- local_dir=str(xcodec_base),
27
- local_dir_use_symlinks=False
28
- )
29
-
30
- print("βœ… Successfully downloaded xcodec_mini_infer models")
31
- return True
32
-
33
- except Exception as e:
34
- print(f"❌ Error downloading xcodec_mini_infer models: {e}")
35
-
36
- # Try downloading individual essential files if full download fails
37
  try:
38
- print("πŸ”„ Attempting to download essential files individually...")
39
-
40
- # Ensure directories exist
41
- os.makedirs(xcodec_base / "semantic_ckpts" / "hf_1_325000", exist_ok=True)
42
- os.makedirs(xcodec_base / "final_ckpt", exist_ok=True)
43
- os.makedirs(xcodec_base / "decoders", exist_ok=True)
44
-
45
- # Download essential model files
46
- essential_files = [
47
- "semantic_ckpts/hf_1_325000/pytorch_model.bin",
48
- "semantic_ckpts/hf_1_325000/preprocessor_config.json",
49
- "final_ckpt/ckpt_00360000.pth",
50
- "final_ckpt/config.yaml",
51
- "decoders/decoder_131000.pth",
52
- "decoders/decoder_151000.pth",
53
- "decoders/config.yaml"
54
  ]
55
-
56
- for file_path in essential_files:
57
- try:
58
- local_path = xcodec_base / file_path
59
- os.makedirs(local_path.parent, exist_ok=True)
60
-
61
- downloaded_file = hf_hub_download(
62
- repo_id="m-a-p/xcodec_mini_infer",
63
- filename=file_path,
64
- cache_dir="/tmp/hf_cache"
65
- )
66
-
67
- # Copy to local directory
68
- shutil.copy2(downloaded_file, local_path)
69
- print(f"βœ… Downloaded: {file_path}")
70
-
71
- except Exception as file_error:
72
- print(f"⚠️ Failed to download {file_path}: {file_error}")
73
-
74
  return True
75
-
76
- except Exception as fallback_error:
77
- print(f"❌ Fallback download also failed: {fallback_error}")
78
- return False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
 
81
  def ensure_model_availability():
@@ -86,28 +95,28 @@ def ensure_model_availability():
86
 
87
  xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
88
 
89
- # Check if essential model files exist
90
- essential_files = [
91
- xcodec_base / "semantic_ckpts" / "hf_1_325000" / "pytorch_model.bin",
92
- xcodec_base / "final_ckpt" / "ckpt_00360000.pth",
93
- xcodec_base / "decoders" / "decoder_131000.pth"
94
  ]
95
 
96
- missing_files = [f for f in essential_files if not f.exists()]
97
 
98
  if missing_files:
99
- print(f"⚠️ Missing model files: {[str(f) for f in missing_files]}")
100
- print("πŸš€ Starting model download...")
101
-
102
  success = download_xcodec_models()
103
-
104
  if success:
105
  print("βœ… Model download completed successfully!")
106
  else:
107
- print("❌ Model download failed. Some functionality may be limited.")
108
  return False
109
  else:
110
- print("βœ… All required model files are already present")
111
 
112
  return True
113
 
 
5
  """
6
 
7
  import os
8
+ import subprocess
9
  import shutil
10
  from pathlib import Path
 
11
 
12
 
13
  def download_xcodec_models():
14
+ """Download xcodec_mini_infer models using git clone (supports Git LFS)"""
15
+
16
  # Base path for xcodec models
17
  xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
18
+
19
+ print("πŸ“₯ Downloading xcodec_mini_infer models using git clone...")
20
+
21
  try:
22
+ # Remove existing directory if it exists (might be empty or incomplete)
23
+ if xcodec_base.exists():
24
+ print("πŸ—‘οΈ Removing existing xcodec_mini_infer directory...")
25
+ shutil.rmtree(xcodec_base)
26
+
27
+ # Ensure parent directory exists
28
+ os.makedirs(xcodec_base.parent, exist_ok=True)
29
+
30
+ # Change to the parent directory for git clone
31
+ original_cwd = os.getcwd()
32
+ os.chdir(xcodec_base.parent)
33
+
 
 
 
34
  try:
35
+ # Clone the repository using git (Spaces has git and git-lfs pre-installed)
36
+ print("πŸ”„ Cloning repository with Git LFS support...")
37
+ result = subprocess.run([
38
+ "git", "clone",
39
+ "https://huggingface.co/m-a-p/xcodec_mini_infer",
40
+ "xcodec_mini_infer"
41
+ ], check=True, capture_output=True, text=True, timeout=600)
42
+
43
+ print("βœ… Successfully cloned xcodec_mini_infer repository")
44
+
45
+ # Verify critical decoder files exist (these are Git LFS files)
46
+ decoder_files = [
47
+ xcodec_base / "decoders" / "decoder_131000.pth",
48
+ xcodec_base / "decoders" / "decoder_151000.pth"
 
 
49
  ]
50
+
51
+ missing_decoders = [f for f in decoder_files if not f.exists()]
52
+ if missing_decoders:
53
+ print(f"⚠️ Decoder files missing: {[f.name for f in missing_decoders]}")
54
+ print("πŸ”„ Ensuring Git LFS files are downloaded...")
55
+
56
+ # Try to explicitly pull LFS files
57
+ os.chdir("xcodec_mini_infer")
58
+ subprocess.run(["git", "lfs", "pull"], check=True, capture_output=True, text=True, timeout=300)
59
+ os.chdir("..")
60
+
61
+ # Check again
62
+ missing_decoders = [f for f in decoder_files if not f.exists()]
63
+ if missing_decoders:
64
+ print(f"❌ Critical decoder files still missing: {[f.name for f in missing_decoders]}")
65
+ return False
66
+
67
+ print("βœ… All critical model files verified present")
 
68
  return True
69
+
70
+ finally:
71
+ os.chdir(original_cwd)
72
+
73
+ except subprocess.CalledProcessError as e:
74
+ print(f"❌ Git clone failed: {e}")
75
+ if e.stdout:
76
+ print(f"stdout: {e.stdout}")
77
+ if e.stderr:
78
+ print(f"stderr: {e.stderr}")
79
+ return False
80
+
81
+ except subprocess.TimeoutExpired:
82
+ print("❌ Git clone timed out (network issue or large repository)")
83
+ return False
84
+
85
+ except Exception as e:
86
+ print(f"❌ Unexpected error during download: {e}")
87
+ return False
88
 
89
 
90
  def ensure_model_availability():
 
95
 
96
  xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
97
 
98
+ # Check if critical decoder files exist (these are the most important for vocoder)
99
+ critical_files = [
100
+ xcodec_base / "decoders" / "decoder_131000.pth",
101
+ xcodec_base / "decoders" / "decoder_151000.pth",
102
+ xcodec_base / "final_ckpt" / "ckpt_00360000.pth"
103
  ]
104
 
105
+ missing_files = [f for f in critical_files if not f.exists()]
106
 
107
  if missing_files:
108
+ print(f"⚠️ Missing critical model files: {[f.name for f in missing_files]}")
109
+ print("πŸš€ Starting model download with git clone...")
110
+
111
  success = download_xcodec_models()
112
+
113
  if success:
114
  print("βœ… Model download completed successfully!")
115
  else:
116
+ print("❌ Model download failed. Vocoder functionality will not work.")
117
  return False
118
  else:
119
+ print("βœ… All critical model files are already present")
120
 
121
  return True
122