Spaces:
Sleeping
Sleeping
File size: 7,222 Bytes
89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 89c14ba b174d42 | 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | """
Model downloader for GAIA Evaluation Agent
Helps download and set up local models for offline usage
"""
import os
import argparse
from pathlib import Path
from huggingface_hub import snapshot_download
from config import set_model_strategy, set_local_model_paths
def download_model(model_id, local_dir, token=None):
"""Download a model from Hugging Face Hub"""
print(f"Downloading {model_id} to {local_dir}...")
try:
snapshot_download(
repo_id=model_id,
local_dir=local_dir,
token=token,
resume_download=True,
local_dir_use_symlinks=False
)
print(f" Successfully downloaded {model_id}")
return True
except Exception as e:
print(f" Failed to download {model_id}: {e}")
return False
def setup_model_directory(base_dir="./models"):
"""Create model directory structure"""
models_dir = Path(base_dir)
models_dir.mkdir(exist_ok=True)
return models_dir
def download_recommended_models(models_dir, token=None, model_size="light"):
"""Download recommended models for GAIA evaluation"""
if model_size == "tiny":
models_to_download = {
"llm_model": {
"id": "microsoft/DialoGPT-small",
"dir": "DialoGPT-small"
},
"fallback_model": {
"id": "distilbert-base-uncased",
"dir": "distilbert-base-uncased"
},
"embedding_model": {
"id": "sentence-transformers/all-MiniLM-L6-v2",
"dir": "all-MiniLM-L6-v2"
}
}
elif model_size == "full":
models_to_download = {
"llm_model": {
"id": "meta-llama/Llama-3.3-70B-Instruct",
"dir": "Llama-3.3-70B-Instruct"
},
"fallback_model": {
"id": "HuggingFaceH4/zephyr-7b-beta",
"dir": "zephyr-7b-beta"
},
"embedding_model": {
"id": "thenlper/gte-small",
"dir": "gte-small"
}
}
elif model_size == "medium":
models_to_download = {
"llm_model": {
"id": "meta-llama/Llama-3.2-8B-Instruct",
"dir": "Llama-3.2-8B-Instruct"
},
"fallback_model": {
"id": "microsoft/DialoGPT-medium",
"dir": "DialoGPT-medium"
},
"embedding_model": {
"id": "sentence-transformers/all-MiniLM-L6-v2",
"dir": "all-MiniLM-L6-v2"
}
}
else:
models_to_download = {
"llm_model": {
"id": "microsoft/DialoGPT-medium",
"dir": "DialoGPT-medium"
},
"fallback_model": {
"id": "Qwen/Qwen2.5-7B-Instruct",
"dir": "Qwen2.5-7B-Instruct"
},
"embedding_model": {
"id": "sentence-transformers/all-MiniLM-L6-v2",
"dir": "all-MiniLM-L6-v2"
}
}
downloaded_models = {}
for model_type, model_info in models_to_download.items():
model_dir = models_dir / model_info["dir"]
if model_dir.exists() and any(model_dir.iterdir()):
print(f" {model_info['id']} already exists at {model_dir}")
downloaded_models[model_type] = str(model_dir)
else:
if download_model(model_info["id"], str(model_dir), token):
downloaded_models[model_type] = str(model_dir)
return downloaded_models
def update_config_for_local_models(downloaded_models):
"""Update configuration to use downloaded local models"""
print("\nUpdating configuration for local models...")
set_local_model_paths(
llm_path=downloaded_models.get("llm_model"),
fallback_path=downloaded_models.get("fallback_model"),
embedding_path=downloaded_models.get("embedding_model")
)
if downloaded_models.get("llm_model") or downloaded_models.get("fallback_model"):
if downloaded_models.get("llm_model"):
set_model_strategy("local")
print(" Configuration updated to use local models")
else:
set_local_model_paths(
llm_path=downloaded_models.get("fallback_model"),
fallback_path=downloaded_models.get("llm_model"),
embedding_path=downloaded_models.get("embedding_model")
)
set_model_strategy("local")
print(" Configuration updated to use local models (using fallback as primary)")
else:
print(" No models downloaded successfully, keeping remote configuration")
def main():
parser = argparse.ArgumentParser(description="Download models for GAIA evaluation")
parser.add_argument(
"--model-size",
choices=["tiny", "light", "medium", "full"],
default="light",
help="Size of models to download (default: light)"
)
parser.add_argument(
"--models-dir",
default="./models",
help="Directory to store models (default: ./models)"
)
parser.add_argument(
"--token",
help="Hugging Face API token (for gated models)"
)
parser.add_argument(
"--custom-model",
help="Download a specific model ID"
)
parser.add_argument(
"--list-sizes",
action="store_true",
help="Show information about different model sizes"
)
args = parser.parse_args()
if args.list_sizes:
print("""
Model Size Information:
TINY (Quick testing, limited capability):
- LLM: DialoGPT-small (~300MB, no gating required)
- Fallback: distilbert-base-uncased (~250MB)
- Embedding: all-MiniLM-L6-v2 (~90MB)
- Total: ~650MB
- Memory: 4-8GB RAM recommended
LIGHT (Recommended for most users):
- LLM: DialoGPT-medium (~1.5GB, no gating required)
- Fallback: Qwen2.5-7B-Instruct (~14GB)
- Embedding: all-MiniLM-L6-v2 (~90MB)
- Total: ~16GB
- Memory: 8-16GB RAM recommended
MEDIUM (Balanced performance):
- LLM: Llama-3.2-8B-Instruct (~16GB)
- Fallback: DialoGPT-medium (~1.5GB)
- Embedding: all-MiniLM-L6-v2 (~90MB)
- Total: ~18GB
- Memory: 16-32GB RAM recommended
FULL (Best performance):
- LLM: Llama-3.3-70B-Instruct (~140GB)
- Fallback: zephyr-7b-beta (~14GB)
- Embedding: gte-small (~130MB)
- Total: ~155GB
- Memory: 64GB+ RAM recommended or GPU with 80GB+ VRAM
""")
return
models_dir = setup_model_directory(args.models_dir)
print(f"Using models directory: {models_dir}")
if args.custom_model:
model_name = args.custom_model.split("/")[-1]
model_dir = models_dir / model_name
download_model(args.custom_model, str(model_dir), args.token)
else:
downloaded_models = download_recommended_models(
models_dir,
args.token,
args.model_size
)
update_config_for_local_models(downloaded_models)
print(f"\nTo use local models, run:")
print(f"python -c \"from config import set_model_strategy; set_model_strategy('local')\"")
print(f"python evaluation.py")
if __name__ == "__main__":
main()
|