Commit
·
d9c43bd
1
Parent(s):
9ad705e
version 08
Browse files- .modelsignore +18 -0
- app.py +130 -14
.modelsignore
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Models to ignore in the comparison tool
|
2 |
+
# Each line is a pattern that can include wildcards (*)
|
3 |
+
|
4 |
+
# Ignore specific repositories
|
5 |
+
fbaldassarri/modello-italia-9b-autoround-w4g128-cpu,modello-italia-9bw4g128-cpu
|
6 |
+
fbaldassarri/modello-italia-9b-autoround-w4g128-cpu,modello-italia-9bw4g128-gpu
|
7 |
+
|
8 |
+
# Ignore model families with wildcards
|
9 |
+
# *phi-2*
|
10 |
+
# *llama-2-13b*
|
11 |
+
# *mistral-7b*
|
12 |
+
|
13 |
+
# Ignore by quantization type (all INT8 models)
|
14 |
+
# *int8*
|
15 |
+
|
16 |
+
# Ignore testing models
|
17 |
+
# *test*
|
18 |
+
# *experimental*
|
app.py
CHANGED
@@ -13,6 +13,7 @@ import numpy as np
|
|
13 |
from functools import partial
|
14 |
import gc
|
15 |
import sys
|
|
|
16 |
|
17 |
# Set page configuration
|
18 |
st.set_page_config(
|
@@ -42,16 +43,68 @@ QUANTIZATION_KEYWORDS = [
|
|
42 |
"autoawq", "auto_awq", "auto-awq"
|
43 |
]
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
# Cache API results
|
46 |
@st.cache_data(ttl=3600) # Cache for 1 hour
|
47 |
-
def get_user_models(username):
|
48 |
api = HfApi()
|
49 |
try:
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
except Exception as e:
|
53 |
st.error(f"Error fetching models: {str(e)}")
|
54 |
-
return []
|
55 |
|
56 |
# Get model metadata without loading the model
|
57 |
@st.cache_data(ttl=3600)
|
@@ -73,7 +126,7 @@ def model_matches_keywords(model_id):
|
|
73 |
def extract_quantization_method(model_id):
|
74 |
model_name = model_id.lower()
|
75 |
|
76 |
-
if any(kw in model_name for kw in ["auto_round", "auto-round", "autoround"
|
77 |
return "Intel AutoRound"
|
78 |
elif any(kw in model_name for kw in ["autogptq", "auto_gptq", "auto-gptq"]):
|
79 |
return "AutoGPTQ"
|
@@ -257,21 +310,39 @@ def estimate_model_size_from_files(model_id):
|
|
257 |
# Main function
|
258 |
def main():
|
259 |
st.title("🔍 Quantized Model Comparison Tool")
|
260 |
-
st.write("Compare Intel AutoRound, AutoGPTQ, and AutoAWQ models
|
|
|
|
|
|
|
261 |
|
262 |
# Sidebar for configuration
|
263 |
st.sidebar.header("Configuration")
|
264 |
username = st.sidebar.text_input("HuggingFace Username", "fbaldassarri")
|
265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
# Fetch all models
|
267 |
with st.spinner("Fetching models..."):
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
|
271 |
# Filter models with quantization keywords
|
272 |
quantized_model_ids = [model_id for model_id in all_model_ids if model_matches_keywords(model_id)]
|
273 |
|
274 |
-
st.sidebar.write(f"Found {len(quantized_model_ids)} quantized models out of {
|
275 |
|
276 |
# Quantization method filtering
|
277 |
quant_methods = ["Intel AutoRound", "AutoGPTQ", "AutoAWQ"]
|
@@ -317,7 +388,7 @@ def main():
|
|
317 |
model_selection_options = model_groups[selected_base_model]
|
318 |
|
319 |
# Limit selection to prevent resource issues
|
320 |
-
max_models_comparison = st.sidebar.slider("Maximum models to compare", 2, len(quantized_model_ids), 5
|
321 |
default_models = model_selection_options[:min(max_models_comparison, len(model_selection_options))]
|
322 |
|
323 |
selected_models = st.sidebar.multiselect(
|
@@ -673,6 +744,7 @@ def main():
|
|
673 |
- **Repository Stats**: View downloads, likes, and update frequency
|
674 |
- **Visualization**: Compare models across multiple dimensions
|
675 |
- **Filtering**: Focus on specific quantization methods or model families
|
|
|
676 |
|
677 |
### Supported Quantization Methods:
|
678 |
|
@@ -682,10 +754,54 @@ def main():
|
|
682 |
|
683 |
### Instructions:
|
684 |
|
685 |
-
1.
|
686 |
-
2.
|
687 |
-
3.
|
688 |
-
4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
689 |
""")
|
690 |
|
691 |
if __name__ == "__main__":
|
|
|
13 |
from functools import partial
|
14 |
import gc
|
15 |
import sys
|
16 |
+
import fnmatch
|
17 |
|
18 |
# Set page configuration
|
19 |
st.set_page_config(
|
|
|
43 |
"autoawq", "auto_awq", "auto-awq"
|
44 |
]
|
45 |
|
46 |
+
# Function to read and parse .modelsignore file
|
47 |
+
def read_models_ignore_file(file_path=".modelsignore"):
|
48 |
+
"""
|
49 |
+
Read the .modelsignore file and return a list of patterns to ignore.
|
50 |
+
Each line in the file represents a pattern.
|
51 |
+
"""
|
52 |
+
ignore_patterns = []
|
53 |
+
try:
|
54 |
+
with open(file_path, 'r') as f:
|
55 |
+
for line in f:
|
56 |
+
# Strip whitespace and skip empty lines and comments
|
57 |
+
line = line.strip()
|
58 |
+
if line and not line.startswith('#'):
|
59 |
+
ignore_patterns.append(line)
|
60 |
+
return ignore_patterns
|
61 |
+
except FileNotFoundError:
|
62 |
+
return [] # Return empty list if file doesn't exist
|
63 |
+
|
64 |
+
# Function to check if a model should be ignored
|
65 |
+
def should_ignore_model(model_id, ignore_patterns):
|
66 |
+
"""
|
67 |
+
Check if a model ID matches any pattern in the ignore list.
|
68 |
+
|
69 |
+
Supports:
|
70 |
+
- Exact matches
|
71 |
+
- Glob patterns with wildcards (e.g., "*mistral*")
|
72 |
+
"""
|
73 |
+
if not ignore_patterns:
|
74 |
+
return False
|
75 |
+
|
76 |
+
for pattern in ignore_patterns:
|
77 |
+
# Check if the pattern matches using fnmatch (supports wildcards)
|
78 |
+
if fnmatch.fnmatch(model_id.lower(), pattern.lower()):
|
79 |
+
return True
|
80 |
+
|
81 |
+
return False
|
82 |
+
|
83 |
# Cache API results
|
84 |
@st.cache_data(ttl=3600) # Cache for 1 hour
|
85 |
+
def get_user_models(username, ignore_patterns=None):
|
86 |
api = HfApi()
|
87 |
try:
|
88 |
+
all_models = list(api.list_models(author=username))
|
89 |
+
model_ids = [model.id for model in all_models]
|
90 |
+
|
91 |
+
# Filter out ignored models
|
92 |
+
if ignore_patterns:
|
93 |
+
filtered_models = []
|
94 |
+
ignored_models = []
|
95 |
+
|
96 |
+
for model_id in model_ids:
|
97 |
+
if should_ignore_model(model_id, ignore_patterns):
|
98 |
+
ignored_models.append(model_id)
|
99 |
+
else:
|
100 |
+
filtered_models.append(model_id)
|
101 |
+
|
102 |
+
return filtered_models, ignored_models, len(all_models)
|
103 |
+
|
104 |
+
return model_ids, [], len(all_models)
|
105 |
except Exception as e:
|
106 |
st.error(f"Error fetching models: {str(e)}")
|
107 |
+
return [], [], 0
|
108 |
|
109 |
# Get model metadata without loading the model
|
110 |
@st.cache_data(ttl=3600)
|
|
|
126 |
def extract_quantization_method(model_id):
|
127 |
model_name = model_id.lower()
|
128 |
|
129 |
+
if any(kw in model_name for kw in ["auto_round", "auto-round", "autoround"]):
|
130 |
return "Intel AutoRound"
|
131 |
elif any(kw in model_name for kw in ["autogptq", "auto_gptq", "auto-gptq"]):
|
132 |
return "AutoGPTQ"
|
|
|
310 |
# Main function
|
311 |
def main():
|
312 |
st.title("🔍 Quantized Model Comparison Tool")
|
313 |
+
st.write("Compare Intel AutoRound, AutoGPTQ, and AutoAWQ models")
|
314 |
+
|
315 |
+
# Read the models ignore file
|
316 |
+
ignore_patterns = read_models_ignore_file()
|
317 |
|
318 |
# Sidebar for configuration
|
319 |
st.sidebar.header("Configuration")
|
320 |
username = st.sidebar.text_input("HuggingFace Username", "fbaldassarri")
|
321 |
|
322 |
+
# Display ignore file status
|
323 |
+
if ignore_patterns:
|
324 |
+
st.sidebar.info(f"Using .modelsignore file with {len(ignore_patterns)} patterns")
|
325 |
+
if st.sidebar.expander("Show ignored patterns"):
|
326 |
+
for pattern in ignore_patterns:
|
327 |
+
st.sidebar.code(pattern)
|
328 |
+
else:
|
329 |
+
st.sidebar.info("No .modelsignore file found. All models will be included.")
|
330 |
+
|
331 |
# Fetch all models
|
332 |
with st.spinner("Fetching models..."):
|
333 |
+
all_model_ids, ignored_models, total_models = get_user_models(username, ignore_patterns)
|
334 |
+
|
335 |
+
# Show ignored models count if any
|
336 |
+
if ignored_models:
|
337 |
+
st.sidebar.warning(f"{len(ignored_models)} models ignored based on .modelsignore patterns")
|
338 |
+
with st.sidebar.expander("Show ignored models"):
|
339 |
+
for ignored in ignored_models:
|
340 |
+
st.sidebar.text(ignored)
|
341 |
|
342 |
# Filter models with quantization keywords
|
343 |
quantized_model_ids = [model_id for model_id in all_model_ids if model_matches_keywords(model_id)]
|
344 |
|
345 |
+
st.sidebar.write(f"Found {len(quantized_model_ids)} quantized models out of {total_models} total models")
|
346 |
|
347 |
# Quantization method filtering
|
348 |
quant_methods = ["Intel AutoRound", "AutoGPTQ", "AutoAWQ"]
|
|
|
388 |
model_selection_options = model_groups[selected_base_model]
|
389 |
|
390 |
# Limit selection to prevent resource issues
|
391 |
+
max_models_comparison = st.sidebar.slider("Maximum models to compare", 2, len(quantized_model_ids), 5)
|
392 |
default_models = model_selection_options[:min(max_models_comparison, len(model_selection_options))]
|
393 |
|
394 |
selected_models = st.sidebar.multiselect(
|
|
|
744 |
- **Repository Stats**: View downloads, likes, and update frequency
|
745 |
- **Visualization**: Compare models across multiple dimensions
|
746 |
- **Filtering**: Focus on specific quantization methods or model families
|
747 |
+
- **Model Ignoring**: Use .modelsignore file to exclude specific models
|
748 |
|
749 |
### Supported Quantization Methods:
|
750 |
|
|
|
754 |
|
755 |
### Instructions:
|
756 |
|
757 |
+
1. Create a .modelsignore file to exclude models (optional)
|
758 |
+
2. Select models using the sidebar filters
|
759 |
+
3. Click "Run Comparison" to analyze without loading full models
|
760 |
+
4. View results in the tabs and charts
|
761 |
+
5. Download results as CSV for further analysis
|
762 |
+
|
763 |
+
### .modelsignore Format:
|
764 |
+
|
765 |
+
Add one pattern per line to ignore specific models:
|
766 |
+
```
|
767 |
+
# Comments start with #
|
768 |
+
fbaldassarri/llama-2-7b-* # Ignores all llama-2-7b models
|
769 |
+
*mistral* # Ignores anything with "mistral" in the name
|
770 |
+
fbaldassarri/exact-model-name # Ignores a specific model
|
771 |
+
```
|
772 |
+
""")
|
773 |
+
|
774 |
+
# Add a section about the modelsignore file format
|
775 |
+
with st.expander("How to use .modelsignore file"):
|
776 |
+
st.markdown("""
|
777 |
+
### .modelsignore File Format
|
778 |
+
|
779 |
+
Create a file named `.modelsignore` in the same directory as app.py. Each line in this file represents a pattern for models to exclude from comparison.
|
780 |
+
|
781 |
+
#### Pattern Format:
|
782 |
+
- **Exact match**: `fbaldassarri/model-name`
|
783 |
+
- **Wildcard match**: `*keyword*` (matches any model with "keyword" in the name)
|
784 |
+
- **Prefix match**: `fbaldassarri/prefix*` (matches models starting with "prefix")
|
785 |
+
- **Suffix match**: `*suffix` (matches models ending with "suffix")
|
786 |
+
|
787 |
+
#### Example .modelsignore file:
|
788 |
+
```
|
789 |
+
# Comments start with #
|
790 |
+
|
791 |
+
# Ignore specific models
|
792 |
+
fbaldassarri/llama-2-7b-auto-gptq
|
793 |
+
|
794 |
+
# Ignore all models containing "phi" and "3b"
|
795 |
+
*phi*3b*
|
796 |
+
|
797 |
+
# Ignore all models starting with "gemma-"
|
798 |
+
fbaldassarri/gemma-*
|
799 |
+
|
800 |
+
# Ignore all mistral models
|
801 |
+
*mistral*
|
802 |
+
```
|
803 |
+
|
804 |
+
The tool will read this file at startup and filter out any matching models before analysis.
|
805 |
""")
|
806 |
|
807 |
if __name__ == "__main__":
|