ndc8
Add gguf_file parameter to tokenizer loading and introduce diagnostic script for GGUF validation
6f81ff7
#!/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) | |