Spaces:
Sleeping
Sleeping
File size: 5,938 Bytes
60344c1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
#!/usr/bin/env python3
"""
Script to download Qwen2.5-Coder-7B-Instruct quantized model
"""
import os
import requests
import sys
from pathlib import Path
from tqdm import tqdm
import logging
logger = logging.getLogger("code_compass")
def download_file(url, filename):
"""Download file with progress bar"""
logger.info(f"π₯ Downloading {filename}...")
logger.info(f"π URL: {url}")
response = requests.get(url, stream=True)
total_size = int(response.headers.get('content-length', 0))
if total_size == 0:
logger.info("β Could not determine file size")
return False
logger.info(f"π File size: {total_size / (1024*1024*1024):.2f} GB")
with open(filename, 'wb') as file, tqdm(
desc=filename,
total=total_size,
unit='B',
unit_scale=True,
unit_divisor=1024,
) as progress_bar:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
file.write(chunk)
progress_bar.update(len(chunk))
logger.info(f"β
Downloaded {filename} successfully!")
return True
def main():
"""Main download function"""
logger.info("π Qwen2.5-Coder-7B-Instruct Model Downloader")
logger.info("=" * 50)
# Available quantization options
models = {
"Q4_K_M": {
"url": "https://huggingface.co/bartowski/Qwen2.5-Coder-7B-Instruct-GGUF/resolve/main/Qwen2.5-Coder-7B-Instruct-Q4_K_M.gguf",
"filename": "qwen2.5-coder-7b-instruct-q4_k_m.gguf",
"size": "~4.5 GB",
"description": "4-bit quantization, best balance of quality and size (RECOMMENDED)"
},
"Q5_K_M": {
"url": "https://huggingface.co/bartowski/Qwen2.5-Coder-7B-Instruct-GGUF/resolve/main/Qwen2.5-Coder-7B-Instruct-Q5_K_M.gguf",
"filename": "qwen2.5-coder-7b-instruct-q5_k_m.gguf",
"size": "~5.5 GB",
"description": "5-bit quantization, higher quality than Q4"
},
"Q6_K": {
"url": "https://huggingface.co/bartowski/Qwen2.5-Coder-7B-Instruct-GGUF/resolve/main/Qwen2.5-Coder-7B-Instruct-Q6_K.gguf",
"filename": "qwen2.5-coder-7b-instruct-q6_k.gguf",
"size": "~6.5 GB",
"description": "6-bit quantization, highest quality"
},
"Q8_0": {
"url": "https://huggingface.co/bartowski/Qwen2.5-Coder-7B-Instruct-GGUF/resolve/main/Qwen2.5-Coder-7B-Instruct-Q8_0.gguf",
"filename": "qwen2.5-coder-7b-instruct-q8_0.gguf",
"size": "~7.5 GB",
"description": "8-bit quantization, near full precision"
}
}
logger.info("π Available model variants:")
logger.info()
for i, (key, info) in enumerate(models.items(), 1):
marker = " β RECOMMENDED" if key == "Q4_K_M" else ""
logger.info(f"{i}. {key}{marker}")
logger.info(f" Size: {info['size']}")
logger.info(f" Description: {info['description']}")
logger.info()
# Get user choice
while True:
try:
choice = input("Enter your choice (1-4) or 'q' to quit: ").strip()
if choice.lower() == 'q':
logger.info("π Download cancelled.")
return
choice_num = int(choice)
if 1 <= choice_num <= len(models):
selected_key = list(models.keys())[choice_num - 1]
selected_model = models[selected_key]
break
else:
logger.info("β Invalid choice. Please enter 1-4.")
except ValueError:
logger.info("β Invalid input. Please enter a number 1-4 or 'q'.")
logger.info(f"π¦ Selected: {selected_key}")
logger.info(f"π Filename: {selected_model['filename']}")
logger.info(f"π Size: {selected_model['size']}")
logger.info()
# Check if file already exists
if os.path.exists(selected_model['filename']):
overwrite = input(f"β οΈ File {selected_model['filename']} already exists. Overwrite? (y/n): ")
if overwrite.lower() != 'y':
logger.info("π Download cancelled.")
return
# Create models directory if it doesn't exist
models_dir = Path("models")
models_dir.mkdir(exist_ok=True)
# Full path for the model
model_path = models_dir / selected_model['filename']
# Download the model
try:
success = download_file(selected_model['url'], str(model_path))
if success:
logger.info()
logger.info("π Download completed successfully!")
logger.info(f"π Model saved to: {model_path}")
logger.info()
logger.info("π To use the model:")
logger.info(" 1. Make sure the model path in llm_service.py points to this file")
logger.info(" 2. Run your main application: python main.py")
logger.info(" 3. Click 'Initialize LLM' in the web interface")
logger.info()
logger.info("π‘ System Requirements:")
logger.info(" - RAM: At least 8GB (16GB+ recommended)")
logger.info(" - Storage: Ensure you have enough free space")
logger.info(" - CPU: Modern multi-core processor recommended")
else:
logger.info("β Download failed!")
return 1
except KeyboardInterrupt:
logger.info("\nπ Download interrupted by user")
# Clean up partial file
if os.path.exists(model_path):
os.remove(model_path)
logger.info(f"ποΈ Cleaned up partial file: {model_path}")
return 1
except Exception as e:
logger.info(f"β Error during download: {str(e)}")
return 1
return 0
if __name__ == "__main__":
sys.exit(main()) |