File size: 2,897 Bytes
6f81ff7 |
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 |
#!/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)
|