When deploying large language models, quantization (reducing numerical precision of weights) is a common technique to save memory and speed up inference. However, quantization can degrade model quality. A standard way to measure this degradation is by comparing the perplexity of the original model to the perplexity of the quantized model on the same evaluation data.
Perplexity is computed from the log-probabilities that a model assigns to the correct next tokens in a sequence. Lower perplexity indicates a better model.
Implement a function quantization_quality_check(log_probs_original, log_probs_quantized, thresholds) that:
The thresholds parameter is an optional dictionary with keys 'excellent' and 'acceptable' representing percentage thresholds. If not provided, use defaults of 1.0 for excellent and 5.0 for acceptable.
Return a dictionary with keys: 'perplexity_original', 'perplexity_quantized', 'perplexity_delta', 'relative_delta_percent', and 'quality'. All numerical values should be rounded to 4 decimal places.