Spaces:
Sleeping
Sleeping
fix
Browse files
setup.sh
CHANGED
|
@@ -1,207 +1,37 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
-
echo "Setting up GGUF
|
| 5 |
|
| 6 |
-
# Clone
|
| 7 |
if [ ! -d "llama.cpp" ]; then
|
| 8 |
-
echo "
|
| 9 |
-
|
| 10 |
fi
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
print(f"Converting {model_path} to {output_path} as {model_type}")
|
| 30 |
-
|
| 31 |
-
# Create a mock output file with some metadata
|
| 32 |
-
model_name = os.path.basename(model_path)
|
| 33 |
-
|
| 34 |
-
# Try to get some real model info if possible
|
| 35 |
-
config_path = os.path.join(model_path, "config.json")
|
| 36 |
-
model_info = {
|
| 37 |
-
"name": model_name,
|
| 38 |
-
"type": model_type,
|
| 39 |
-
"created": "2025-03-09",
|
| 40 |
-
"format": "GGUF"
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
if os.path.exists(config_path):
|
| 44 |
-
try:
|
| 45 |
-
with open(config_path, 'r') as f:
|
| 46 |
-
config = json.load(f)
|
| 47 |
-
if "model_type" in config:
|
| 48 |
-
model_info["architecture"] = config["model_type"]
|
| 49 |
-
if "vocab_size" in config:
|
| 50 |
-
model_info["vocab_size"] = config["vocab_size"]
|
| 51 |
-
except Exception as e:
|
| 52 |
-
print(f"Error reading config: {e}")
|
| 53 |
-
|
| 54 |
-
# Save model info as a small file
|
| 55 |
-
with open(output_path, 'w') as f:
|
| 56 |
-
f.write(json.dumps(model_info, indent=2))
|
| 57 |
-
|
| 58 |
-
# Make the file a reasonable size to simulate a real model
|
| 59 |
-
# Just append some data to make it look like a real file
|
| 60 |
-
with open(output_path, 'ab') as f:
|
| 61 |
-
f.write(b'\0' * 1024 * 1024) # Add 1MB of data
|
| 62 |
-
|
| 63 |
-
print(f"Mock conversion completed: {output_path}")
|
| 64 |
-
return True
|
| 65 |
-
|
| 66 |
-
def main():
|
| 67 |
-
parser = argparse.ArgumentParser(description="Convert model to GGUF format")
|
| 68 |
-
parser.add_argument("model_path", help="Path to the model directory")
|
| 69 |
-
parser.add_argument("--outfile", help="Output file path")
|
| 70 |
-
parser.add_argument("--outtype", default="f16", help="Output type")
|
| 71 |
-
args = parser.parse_args()
|
| 72 |
-
|
| 73 |
-
try:
|
| 74 |
-
output_path = args.outfile
|
| 75 |
-
if not output_path:
|
| 76 |
-
output_path = f"{os.path.basename(args.model_path)}.gguf"
|
| 77 |
-
|
| 78 |
-
success = mock_convert_to_gguf(args.model_path, output_path, args.outtype)
|
| 79 |
-
return 0 if success else 1
|
| 80 |
-
except Exception as e:
|
| 81 |
-
print(f"Error: {e}")
|
| 82 |
-
return 1
|
| 83 |
-
|
| 84 |
-
if __name__ == "__main__":
|
| 85 |
-
sys.exit(main())
|
| 86 |
-
EOL
|
| 87 |
-
chmod +x llama.cpp/convert.py
|
| 88 |
-
|
| 89 |
-
# Create a quantization script
|
| 90 |
-
echo "Creating quantization script..."
|
| 91 |
-
cat > llama.cpp/quantize.py << 'EOL'
|
| 92 |
-
#!/usr/bin/env python3
|
| 93 |
-
import os
|
| 94 |
-
import sys
|
| 95 |
-
import argparse
|
| 96 |
-
import json
|
| 97 |
-
import shutil
|
| 98 |
-
from pathlib import Path
|
| 99 |
-
|
| 100 |
-
def mock_quantize(input_path, output_path, quant_type):
|
| 101 |
-
"""
|
| 102 |
-
Mock quantization function that creates a dummy GGUF file
|
| 103 |
-
For demonstration purposes in the free tier
|
| 104 |
-
"""
|
| 105 |
-
print(f"Quantizing {input_path} to {output_path} with {quant_type}")
|
| 106 |
-
|
| 107 |
-
# Read the input file if it exists
|
| 108 |
-
model_info = {}
|
| 109 |
-
if os.path.exists(input_path):
|
| 110 |
-
try:
|
| 111 |
-
with open(input_path, 'r') as f:
|
| 112 |
-
content = f.read(1024 * 10) # Read first 10KB (metadata should be at start)
|
| 113 |
-
# Try to parse JSON from the beginning of the file
|
| 114 |
-
try:
|
| 115 |
-
start_json = content.strip().split('{', 1)[0] + '{'
|
| 116 |
-
end_json = '}'
|
| 117 |
-
json_str = start_json + content.split(start_json, 1)[1].split(end_json, 1)[0] + end_json
|
| 118 |
-
model_info = json.loads(json_str)
|
| 119 |
-
except:
|
| 120 |
-
# If that fails, assume the first part might be JSON
|
| 121 |
-
try:
|
| 122 |
-
model_info = json.loads(content.split('\0', 1)[0])
|
| 123 |
-
except:
|
| 124 |
-
print("Could not parse input file metadata")
|
| 125 |
-
except Exception as e:
|
| 126 |
-
print(f"Error reading input file: {e}")
|
| 127 |
-
|
| 128 |
-
# Update with quantization info
|
| 129 |
-
model_info.update({
|
| 130 |
-
"quantization": quant_type,
|
| 131 |
-
"bits_per_token": get_bits_per_token(quant_type),
|
| 132 |
-
"quantized_at": "2025-03-09"
|
| 133 |
-
})
|
| 134 |
-
|
| 135 |
-
# Create the output file with updated metadata
|
| 136 |
-
with open(output_path, 'w') as f:
|
| 137 |
-
f.write(json.dumps(model_info, indent=2))
|
| 138 |
-
|
| 139 |
-
# Make the file a reasonable size based on the quantization type
|
| 140 |
-
size_factor = get_size_factor(quant_type)
|
| 141 |
-
with open(output_path, 'ab') as f:
|
| 142 |
-
f.write(b'\0' * int(1024 * 1024 * size_factor)) # Add data proportional to quantization
|
| 143 |
-
|
| 144 |
-
print(f"Mock quantization completed: {output_path}")
|
| 145 |
-
return True
|
| 146 |
-
|
| 147 |
-
def get_bits_per_token(quant_type):
|
| 148 |
-
"""Get the bits per token for the quantization type"""
|
| 149 |
-
if quant_type == "f16":
|
| 150 |
-
return 16
|
| 151 |
-
elif quant_type.startswith("Q8"):
|
| 152 |
-
return 8
|
| 153 |
-
elif quant_type.startswith("Q6"):
|
| 154 |
-
return 6
|
| 155 |
-
elif quant_type.startswith("Q5"):
|
| 156 |
-
return 5
|
| 157 |
-
elif quant_type.startswith("Q4"):
|
| 158 |
-
return 4
|
| 159 |
-
elif quant_type.startswith("Q3"):
|
| 160 |
-
return 3
|
| 161 |
-
elif quant_type.startswith("Q2"):
|
| 162 |
-
return 2
|
| 163 |
-
else:
|
| 164 |
-
return 4 # Default
|
| 165 |
-
|
| 166 |
-
def get_size_factor(quant_type):
|
| 167 |
-
"""Get the size factor for the quantization type (in MB)"""
|
| 168 |
-
if quant_type == "f16":
|
| 169 |
-
return 3.0
|
| 170 |
-
elif quant_type.startswith("Q8"):
|
| 171 |
-
return 1.5
|
| 172 |
-
elif quant_type.startswith("Q6"):
|
| 173 |
-
return 1.2
|
| 174 |
-
elif quant_type.startswith("Q5"):
|
| 175 |
-
return 1.0
|
| 176 |
-
elif quant_type.startswith("Q4"):
|
| 177 |
-
return 0.9
|
| 178 |
-
elif quant_type.startswith("Q3"):
|
| 179 |
-
return 0.8
|
| 180 |
-
elif quant_type.startswith("Q2"):
|
| 181 |
-
return 0.7
|
| 182 |
-
else:
|
| 183 |
-
return 1.0 # Default
|
| 184 |
-
|
| 185 |
-
def main():
|
| 186 |
-
parser = argparse.ArgumentParser(description="Quantize GGUF model")
|
| 187 |
-
parser.add_argument("input_file", help="Input GGUF file")
|
| 188 |
-
parser.add_argument("output_file", help="Output quantized GGUF file")
|
| 189 |
-
parser.add_argument("quant_type", help="Quantization type")
|
| 190 |
-
args = parser.parse_args()
|
| 191 |
-
|
| 192 |
-
try:
|
| 193 |
-
success = mock_quantize(args.input_file, args.output_file, args.quant_type)
|
| 194 |
-
return 0 if success else 1
|
| 195 |
-
except Exception as e:
|
| 196 |
-
print(f"Error: {e}")
|
| 197 |
-
return 1
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
EOL
|
| 202 |
-
chmod +x llama.cpp/quantize.py
|
| 203 |
|
| 204 |
# Initialize state file
|
|
|
|
| 205 |
if [ ! -f "state.json" ]; then
|
| 206 |
echo "Initializing state file..."
|
| 207 |
echo '{"last_checked": null, "last_commit_hash": null, "is_up_to_date": true, "is_processing": false, "current_quant": null, "progress": 0, "total_quants": 12, "completed_quants": [], "failed_quants": [], "out_of_memory": false, "last_error": null, "status_message": "Ready to check for updates"}' > state.json
|
|
@@ -215,3 +45,4 @@ mkdir -p temp_outputs
|
|
| 215 |
echo "Setup completed successfully"
|
| 216 |
|
| 217 |
|
|
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
+
echo "Setting up for real GGUF quantization..."
|
| 5 |
|
| 6 |
+
# Clone llama.cpp
|
| 7 |
if [ ! -d "llama.cpp" ]; then
|
| 8 |
+
echo "Cloning llama.cpp repository..."
|
| 9 |
+
git clone --depth=1 https://github.com/ggerganov/llama.cpp
|
| 10 |
fi
|
| 11 |
|
| 12 |
+
cd llama.cpp
|
| 13 |
+
|
| 14 |
+
# Get conversion script
|
| 15 |
+
echo "Setting up conversion script..."
|
| 16 |
+
if [ -f "convert.py" ]; then
|
| 17 |
+
echo "Found existing convert.py script"
|
| 18 |
+
elif [ -f "convert-hf-to-gguf.py" ]; then
|
| 19 |
+
echo "Found convert-hf-to-gguf.py"
|
| 20 |
+
cp convert-hf-to-gguf.py convert.py
|
| 21 |
+
elif [ -f "examples/convert-hf-to-gguf.py" ]; then
|
| 22 |
+
echo "Found examples/convert-hf-to-gguf.py"
|
| 23 |
+
cp examples/convert-hf-to-gguf.py convert.py
|
| 24 |
+
else
|
| 25 |
+
echo "Cannot find conversion script. Using Python alternative."
|
| 26 |
+
# Install required packages
|
| 27 |
+
pip install -q transformers torch
|
| 28 |
+
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Install required packages for the conversion script
|
| 31 |
+
pip install -q transformers torch
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Initialize state file
|
| 34 |
+
cd ..
|
| 35 |
if [ ! -f "state.json" ]; then
|
| 36 |
echo "Initializing state file..."
|
| 37 |
echo '{"last_checked": null, "last_commit_hash": null, "is_up_to_date": true, "is_processing": false, "current_quant": null, "progress": 0, "total_quants": 12, "completed_quants": [], "failed_quants": [], "out_of_memory": false, "last_error": null, "status_message": "Ready to check for updates"}' > state.json
|
|
|
|
| 45 |
echo "Setup completed successfully"
|
| 46 |
|
| 47 |
|
| 48 |
+
|