""" 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()