#!/usr/bin/env python3 """ Diagnostic script to test GGUF loading with transformers """ import os import sys def test_gguf_loading(): print("๐Ÿ”ฌ GGUF Loading Diagnostic") print("=" * 40) # Check variables current_model = os.environ.get("AI_MODEL", "unsloth/gemma-3n-E4B-it-GGUF") gguf_filename = os.environ.get("GGUF_FILE", "gemma-3n-E4B-it-Q4_K_M.gguf") print(f"๐Ÿ“‹ Configuration:") print(f" Model: {current_model}") print(f" GGUF File: {gguf_filename}") print(f" Type check - Model: {type(current_model)}") print(f" Type check - Filename: {type(gguf_filename)}") # Test string validation if not isinstance(current_model, str): print(f"โŒ current_model is not a string: {type(current_model)}") return False if not isinstance(gguf_filename, str): print(f"โŒ gguf_filename is not a string: {type(gguf_filename)}") return False print("โœ… All parameters are strings") # Test import try: from transformers import AutoTokenizer, AutoModelForCausalLM print("โœ… Transformers import successful") except ImportError as e: print(f"โŒ Transformers import failed: {e}") return False # Test GGUF dependency try: import gguf print("โœ… GGUF library available") except ImportError as e: print(f"โš ๏ธ GGUF library not available: {e}") print(" This is expected in local test, but needed on HF Spaces") # Test tokenizer loading parameters (dry run) try: print("\n๐Ÿงช Testing tokenizer loading parameters...") tokenizer_args = { "pretrained_model_name_or_path": current_model, "gguf_file": gguf_filename, "trust_remote_code": True, "use_fast": True } print(f" Tokenizer args: {tokenizer_args}") print("โœ… Tokenizer parameters valid") print("\n๐Ÿงช Testing model loading parameters...") model_args = { "pretrained_model_name_or_path": current_model, "gguf_file": gguf_filename, "torch_dtype": "torch.float32", "device_map": "auto", "low_cpu_mem_usage": True, "trust_remote_code": True, } print(f" Model args: {model_args}") print("โœ… Model parameters valid") except Exception as e: print(f"โŒ Parameter validation failed: {e}") return False print("\n๐ŸŽฏ Summary:") print(" โœ… All parameter types are correct") print(" โœ… GGUF filename is exact (not wildcard)") print(" โœ… Both tokenizer and model get gguf_file parameter") print(" ๐Ÿš€ Ready for deployment testing") return True if __name__ == "__main__": success = test_gguf_loading() sys.exit(0 if success else 1)