qwerty45-uiop commited on
Commit
e17660e
·
verified ·
1 Parent(s): 1b7ef96

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +43 -0
src/streamlit_app.py CHANGED
@@ -51,6 +51,49 @@ def load_data():
51
  def extract_numeric_ram(ram) -> Optional[int]:
52
  if pd.isna(ram):
53
  return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  ram_str = str(ram).lower().replace(" ", "")
56
 
 
51
  def extract_numeric_ram(ram) -> Optional[int]:
52
  if pd.isna(ram):
53
  return None
54
+ def calculate_quantized_size(base_size_str: str, quantization: str) -> str:
55
+ """Calculate quantized model size based on base size and quantization type"""
56
+ try:
57
+ # Extract numeric value and unit from base size
58
+ import re
59
+ match = re.match(r'(\d+(?:\.\d+)?)\s*(GB|MB)', base_size_str.upper())
60
+ if not match:
61
+ return base_size_str
62
+
63
+ value, unit = float(match.group(1)), match.group(2)
64
+ multiplier = QUANTIZATION_INFO[quantization]["multiplier"]
65
+
66
+ # Calculate new size
67
+ new_value = value * multiplier
68
+
69
+ # Convert MB to GB if needed for better readability
70
+ if unit == "MB" and new_value >= 1024:
71
+ new_value = new_value / 1024
72
+ unit = "GB"
73
+ elif unit == "GB" and new_value < 1:
74
+ new_value = new_value * 1024
75
+ unit = "MB"
76
+
77
+ # Format the result
78
+ if new_value >= 10:
79
+ return f"{new_value:.0f}{unit}"
80
+ else:
81
+ return f"{new_value:.1f}{unit}"
82
+ except:
83
+ return base_size_str
84
+
85
+ def get_quantization_recommendations(ram_gb: int) -> List[str]:
86
+ """Recommend best quantization options based on available RAM"""
87
+ if ram_gb <= 2:
88
+ return ["4bit"]
89
+ elif ram_gb <= 4:
90
+ return ["4bit", "8bit"]
91
+ elif ram_gb <= 8:
92
+ return ["4bit", "8bit"]
93
+ elif ram_gb <= 16:
94
+ return ["8bit", "fp16"]
95
+ else:
96
+ return ["fp16", "8bit", "4bit"]
97
 
98
  ram_str = str(ram).lower().replace(" ", "")
99