Spaces:
Running
Running
futurespyhi
commited on
Commit
Β·
06059a8
1
Parent(s):
297dc31
1.try using git clone for structure and use wget for critical lfs files
Browse files- download_models.py +87 -28
download_models.py
CHANGED
|
@@ -11,15 +11,15 @@ from pathlib import Path
|
|
| 11 |
|
| 12 |
|
| 13 |
def download_xcodec_models():
|
| 14 |
-
"""Download xcodec_mini_infer
|
| 15 |
|
| 16 |
# Base path for xcodec models
|
| 17 |
xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
|
| 18 |
|
| 19 |
-
print("π₯ Downloading xcodec_mini_infer
|
| 20 |
|
| 21 |
try:
|
| 22 |
-
# Remove existing directory if it exists
|
| 23 |
if xcodec_base.exists():
|
| 24 |
print("ποΈ Removing existing xcodec_mini_infer directory...")
|
| 25 |
shutil.rmtree(xcodec_base)
|
|
@@ -32,39 +32,98 @@ def download_xcodec_models():
|
|
| 32 |
os.chdir(xcodec_base.parent)
|
| 33 |
|
| 34 |
try:
|
| 35 |
-
# Clone
|
| 36 |
-
print("π Cloning repository
|
| 37 |
-
|
| 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=
|
| 42 |
-
|
| 43 |
-
print("β
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
decoder_files = [
|
| 47 |
xcodec_base / "decoders" / "decoder_131000.pth",
|
| 48 |
xcodec_base / "decoders" / "decoder_151000.pth"
|
| 49 |
]
|
| 50 |
|
| 51 |
-
missing_decoders = [
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 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("β
|
|
|
|
| 68 |
return True
|
| 69 |
|
| 70 |
finally:
|
|
@@ -79,11 +138,11 @@ def download_xcodec_models():
|
|
| 79 |
return False
|
| 80 |
|
| 81 |
except subprocess.TimeoutExpired:
|
| 82 |
-
print("β Git clone timed out
|
| 83 |
return False
|
| 84 |
|
| 85 |
except Exception as e:
|
| 86 |
-
print(f"β Unexpected error
|
| 87 |
return False
|
| 88 |
|
| 89 |
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def download_xcodec_models():
|
| 14 |
+
"""Download xcodec_mini_infer using git clone (no LFS) + wget for large files"""
|
| 15 |
|
| 16 |
# Base path for xcodec models
|
| 17 |
xcodec_base = Path("YuEGP/inference/xcodec_mini_infer")
|
| 18 |
|
| 19 |
+
print("π₯ Downloading xcodec_mini_infer using git clone + wget strategy...")
|
| 20 |
|
| 21 |
try:
|
| 22 |
+
# Remove existing directory if it exists
|
| 23 |
if xcodec_base.exists():
|
| 24 |
print("ποΈ Removing existing xcodec_mini_infer directory...")
|
| 25 |
shutil.rmtree(xcodec_base)
|
|
|
|
| 32 |
os.chdir(xcodec_base.parent)
|
| 33 |
|
| 34 |
try:
|
| 35 |
+
# Step 1: Clone repository structure without LFS files
|
| 36 |
+
print("π Step 1: Cloning repository structure (no LFS)...")
|
| 37 |
+
subprocess.run([
|
| 38 |
+
"git", "clone", "--no-lfs",
|
| 39 |
"https://huggingface.co/m-a-p/xcodec_mini_infer",
|
| 40 |
"xcodec_mini_infer"
|
| 41 |
+
], check=True, capture_output=True, text=True, timeout=300)
|
| 42 |
+
|
| 43 |
+
print("β
Repository structure downloaded successfully")
|
| 44 |
+
|
| 45 |
+
# Step 2: Download critical LFS files using wget
|
| 46 |
+
print("π Step 2: Downloading critical LFS files with wget...")
|
| 47 |
+
|
| 48 |
+
# Define critical LFS files and their download URLs
|
| 49 |
+
lfs_files = [
|
| 50 |
+
{
|
| 51 |
+
"path": "decoders/decoder_131000.pth",
|
| 52 |
+
"url": "https://huggingface.co/m-a-p/xcodec_mini_infer/resolve/main/decoders/decoder_131000.pth",
|
| 53 |
+
"description": "Vocal decoder model (70MB)"
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"path": "decoders/decoder_151000.pth",
|
| 57 |
+
"url": "https://huggingface.co/m-a-p/xcodec_mini_infer/resolve/main/decoders/decoder_151000.pth",
|
| 58 |
+
"description": "Instrumental decoder model (70MB)"
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"path": "final_ckpt/ckpt_00360000.pth",
|
| 62 |
+
"url": "https://huggingface.co/m-a-p/xcodec_mini_infer/resolve/main/final_ckpt/ckpt_00360000.pth",
|
| 63 |
+
"description": "Main checkpoint (1.3GB)"
|
| 64 |
+
},
|
| 65 |
+
{
|
| 66 |
+
"path": "semantic_ckpts/hf_1_325000/pytorch_model.bin",
|
| 67 |
+
"url": "https://huggingface.co/m-a-p/xcodec_mini_infer/resolve/main/semantic_ckpts/hf_1_325000/pytorch_model.bin",
|
| 68 |
+
"description": "Semantic model (361MB)"
|
| 69 |
+
}
|
| 70 |
+
]
|
| 71 |
|
| 72 |
+
# Change to the cloned directory
|
| 73 |
+
os.chdir("xcodec_mini_infer")
|
| 74 |
+
|
| 75 |
+
# Download each LFS file
|
| 76 |
+
success_count = 0
|
| 77 |
+
for file_info in lfs_files:
|
| 78 |
+
try:
|
| 79 |
+
file_path = Path(file_info["path"])
|
| 80 |
+
print(f"π₯ Downloading {file_info['description']}...")
|
| 81 |
+
|
| 82 |
+
# Ensure directory exists
|
| 83 |
+
os.makedirs(file_path.parent, exist_ok=True)
|
| 84 |
+
|
| 85 |
+
# Download with wget
|
| 86 |
+
subprocess.run([
|
| 87 |
+
"wget", "-O", str(file_path),
|
| 88 |
+
file_info["url"]
|
| 89 |
+
], check=True, capture_output=True, text=True, timeout=1800) # 30min timeout for large files
|
| 90 |
+
|
| 91 |
+
# Verify download
|
| 92 |
+
if file_path.exists() and file_path.stat().st_size > 1024: # > 1KB
|
| 93 |
+
print(f"β
Successfully downloaded {file_info['path']} ({file_path.stat().st_size // (1024*1024)}MB)")
|
| 94 |
+
success_count += 1
|
| 95 |
+
else:
|
| 96 |
+
print(f"β οΈ {file_info['path']} download appears incomplete")
|
| 97 |
+
|
| 98 |
+
except subprocess.CalledProcessError as e:
|
| 99 |
+
print(f"β Failed to download {file_info['path']}: {e}")
|
| 100 |
+
if e.stderr:
|
| 101 |
+
print(f"Error details: {e.stderr[-500:]}...") # Last 500 chars
|
| 102 |
+
except subprocess.TimeoutExpired:
|
| 103 |
+
print(f"β Download timeout for {file_info['path']} (large file)")
|
| 104 |
+
except Exception as e:
|
| 105 |
+
print(f"β Unexpected error downloading {file_info['path']}: {e}")
|
| 106 |
+
|
| 107 |
+
os.chdir("..")
|
| 108 |
+
|
| 109 |
+
# Verify critical decoder files (minimum requirement)
|
| 110 |
decoder_files = [
|
| 111 |
xcodec_base / "decoders" / "decoder_131000.pth",
|
| 112 |
xcodec_base / "decoders" / "decoder_151000.pth"
|
| 113 |
]
|
| 114 |
|
| 115 |
+
missing_decoders = []
|
| 116 |
+
for decoder_file in decoder_files:
|
| 117 |
+
if not decoder_file.exists() or decoder_file.stat().st_size < 1024:
|
| 118 |
+
missing_decoders.append(decoder_file.name)
|
| 119 |
|
| 120 |
+
if missing_decoders:
|
| 121 |
+
print(f"β Critical decoder files missing or incomplete: {missing_decoders}")
|
| 122 |
+
print("Vocoder functionality will not work without decoder files.")
|
| 123 |
+
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
print(f"β
Successfully downloaded {success_count}/{len(lfs_files)} LFS files")
|
| 126 |
+
print("β
All critical decoder files verified present and complete")
|
| 127 |
return True
|
| 128 |
|
| 129 |
finally:
|
|
|
|
| 138 |
return False
|
| 139 |
|
| 140 |
except subprocess.TimeoutExpired:
|
| 141 |
+
print("β Git clone timed out")
|
| 142 |
return False
|
| 143 |
|
| 144 |
except Exception as e:
|
| 145 |
+
print(f"β Unexpected error: {e}")
|
| 146 |
return False
|
| 147 |
|
| 148 |
|