|
|
|
|
|
""" |
|
|
Test script to verify enhanced fallback mechanisms for pre-quantized models. |
|
|
This simulates the production deployment scenario where bitsandbytes package metadata is missing. |
|
|
""" |
|
|
|
|
|
import sys |
|
|
import logging |
|
|
import os |
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
def test_pre_quantized_model_fallback(): |
|
|
"""Test loading a pre-quantized model without bitsandbytes package metadata.""" |
|
|
|
|
|
logger.info("π§ͺ Testing enhanced fallback for pre-quantized models...") |
|
|
|
|
|
|
|
|
os.environ["AI_MODEL"] = "unsloth/Mistral-Nemo-Instruct-2407-bnb-4bit" |
|
|
|
|
|
try: |
|
|
from backend_service import current_model, get_quantization_config |
|
|
from transformers import AutoConfig, AutoTokenizer, AutoModelForCausalLM |
|
|
|
|
|
logger.info(f"π Testing model: {current_model}") |
|
|
|
|
|
|
|
|
quant_config = get_quantization_config(current_model) |
|
|
if quant_config: |
|
|
logger.info(f"β
Quantization config detected: {type(quant_config).__name__}") |
|
|
else: |
|
|
logger.info("π No quantization config (bitsandbytes not available)") |
|
|
|
|
|
|
|
|
logger.info("π§ Testing enhanced config-based fallback...") |
|
|
|
|
|
try: |
|
|
|
|
|
config = AutoConfig.from_pretrained(current_model, trust_remote_code=True) |
|
|
logger.info(f"β
Successfully loaded config: {type(config).__name__}") |
|
|
|
|
|
|
|
|
if hasattr(config, 'quantization_config'): |
|
|
logger.info(f"π Found quantization_config in model config: {config.quantization_config}") |
|
|
|
|
|
|
|
|
config.quantization_config = None |
|
|
logger.info("π« Removed quantization_config from model config") |
|
|
else: |
|
|
logger.info("π No quantization_config found in model config") |
|
|
|
|
|
|
|
|
logger.info("π₯ Testing tokenizer loading...") |
|
|
tokenizer = AutoTokenizer.from_pretrained(current_model) |
|
|
logger.info(f"β
Tokenizer loaded successfully: {len(tokenizer)} tokens") |
|
|
|
|
|
|
|
|
logger.info("β
Enhanced fallback mechanism validated successfully!") |
|
|
|
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
logger.error(f"β Enhanced fallback test failed: {e}") |
|
|
return False |
|
|
|
|
|
except Exception as e: |
|
|
logger.error(f"β Test setup failed: {e}") |
|
|
return False |
|
|
|
|
|
if __name__ == "__main__": |
|
|
logger.info("π Starting enhanced fallback mechanism test...") |
|
|
|
|
|
success = test_pre_quantized_model_fallback() |
|
|
|
|
|
if success: |
|
|
logger.info("\nπ Enhanced fallback test passed!") |
|
|
logger.info("π‘ The deployment should now handle pre-quantized models correctly") |
|
|
else: |
|
|
logger.error("\nβ Enhanced fallback test failed") |
|
|
|
|
|
sys.exit(0 if success else 1) |
|
|
|