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)