Download tests/test_quant_defaults.py from Intel/low_bit_open_llm_leaderboard: direct link, hf CLI and curl.
- Browser
- Download file 2.12 kB
-
https://huggingface.co/spaces/Intel/low_bit_open_llm_leaderboard/resolve/main/tests/test_quant_defaults.py
- Command line
-
hf download hf://spaces/Intel/low_bit_open_llm_leaderboard/tests/test_quant_defaults.py
-
curl -L -o test_quant_defaults.py https://huggingface.co/spaces/Intel/low_bit_open_llm_leaderboard/resolve/main/tests/test_quant_defaults.py
2.12 kB
| import ast | |
| from pathlib import Path | |
| from unittest.mock import patch | |
| import pytest | |
| from src.app_helpers.quant_defaults import default_quant_method | |
| def test_parameter_threshold(size, expected): | |
| with patch('src.app_helpers.quant_defaults.get_model_size_b', return_value=size): | |
| assert default_quant_method('org/model')['value'].startswith(expected) | |
| def test_empty_model_resets_without_hub_request(): | |
| with patch('src.app_helpers.quant_defaults.get_model_size_b') as lookup: | |
| assert default_quant_method('')['value'].startswith('Tuning') | |
| lookup.assert_not_called() | |
| def test_metadata_error_keeps_form_usable(): | |
| with patch('src.app_helpers.quant_defaults.get_model_size_b', side_effect=ValueError): | |
| assert default_quant_method('org/model')['value'].startswith('Tuning') | |
| def test_default_handler_does_not_shift_existing_gradio_events(): | |
| source = (Path(__file__).resolve().parents[1] / 'app.py').read_text() | |
| tree = ast.parse(source) | |
| default_handlers = [ | |
| node for node in ast.walk(tree) | |
| if isinstance(node, ast.Call) | |
| and isinstance(node.func, ast.Attribute) | |
| and any( | |
| keyword.arg == 'fn' | |
| and isinstance(keyword.value, ast.Name) | |
| and keyword.value.id == 'default_quant_method' | |
| for keyword in node.keywords | |
| ) | |
| ] | |
| assert len(default_handlers) == 1 | |
| handler = default_handlers[0] | |
| assert handler.func.attr == 'then' | |
| assert isinstance(handler.func.value, ast.Name) | |
| assert handler.func.value.id == '_quant_license_evt' | |
| timer_ticks = [ | |
| node for node in ast.walk(tree) | |
| if isinstance(node, ast.Call) | |
| and isinstance(node.func, ast.Attribute) | |
| and node.func.attr == 'tick' | |
| and isinstance(node.func.value, ast.Name) | |
| and node.func.value.id in {'_queue_timer', '_pipeline_timer'} | |
| ] | |
| assert len(timer_ticks) == 2 | |
| assert handler.lineno > max(tick.lineno for tick in timer_ticks) | |