Rajesh0279 commited on
Commit
48a990e
·
verified ·
1 Parent(s): d89ed60

Upload 3 files

Browse files
Files changed (3) hide show
  1. src/run2.py +136 -0
  2. src/run3.py +56 -0
  3. src/utils.py +19 -0
src/run2.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def run_app2():
4
+ st.title(" LLM Compatibility Advisor (Manual Spec Entry)")
5
+ st.markdown("Enter your CPU and GPU specs to get local LLM suggestions (Ollama-compatible)")
6
+
7
+ st.markdown("### 🔧 How to Find Your Device Configuration")
8
+ st.markdown("""
9
+ - **🪟 Windows**: Press `Win + R`, type `dxdiag`, and press Enter to view CPU, GPU, and RAM details.
10
+ - **🍎 macOS**: Click Apple  menu → `About This Mac` → `More Info...`
11
+ - **🐧 Linux**: Use terminal commands like `lscpu`, `free -h`, or `neofetch`
12
+ """)
13
+
14
+ st.markdown("#### 💡 Tip: You can use these tools to help find your processor and GPU names.")
15
+
16
+ cpu_name = st.text_input("🖥️ Enter your Processor Name", placeholder="e.g., Intel Core i5-10300H")
17
+ st.caption("ℹ️ Enter your exact CPU name to help identify its capability (found in system settings).")
18
+
19
+ with st.expander("💡 Suggested Processor Examples"):
20
+ st.markdown("""
21
+ - **Intel i3**: i3-10100U, i3-1115G4, i3-N305
22
+ - **Intel i5**: i5-10300H, i5-1240P, i5-13400
23
+ - **Intel i7**: i7-9750H, i7-11800H, i7-13700K
24
+ - **Apple M Series**: M1, M1 Pro, M2, M3
25
+ - **AMD Ryzen**: Ryzen 5 5600H, Ryzen 7 5800X, Ryzen 9 7945HX
26
+ - **Snapdragon**: Snapdragon 8 Gen 1, Snapdragon 7c Gen 2
27
+ """)
28
+
29
+ cpu_category = st.selectbox(
30
+ "⚙️ Select your CPU Category",
31
+ ["Intel i3", "Intel i5", "Intel i7", "Apple M Series", "AMD Ryzen", "Qualcomm Snapdragon", "Other/Unknown"]
32
+ )
33
+ st.caption("ℹ️ If unsure, choose the closest matching category from the dropdown.")
34
+
35
+ gpu_name = st.text_input("🎮 GPU (Optional)", placeholder="e.g., NVIDIA GTX 1650 / None")
36
+ st.caption("ℹ️ GPU helps speed up models. If you're unsure or using only CPU, leave it blank or type 'None'.")
37
+
38
+ performance_score = {
39
+ "Intel i3": ("🔴 Low-end", "May only support 4-bit quantized models."),
40
+ "Intel i5": ("🟡 Moderate", "Can run most 4-bit and some 8-bit models."),
41
+ "Intel i7": ("🟢 High-end", "Handles 8-bit and some full FP16 models."),
42
+ "Apple M Series": ("🟢 High-end", "Great efficiency for quantized models."),
43
+ "AMD Ryzen": ("🟢 High-end", "Multi-core power suitable for larger models."),
44
+ "Qualcomm Snapdragon": ("🔴 Low-end", "Best for smallest on-device models."),
45
+ "Other/Unknown": ("🟡 Average", "Limited info—may vary by chip.")
46
+ }
47
+
48
+ llm_recommendations = {
49
+ "Intel i3": {
50
+ "Coding": ["Code Llama (7B - quantized)", "Phi-2"],
51
+ "Math & Logic": ["Mistral (7B - quantized)", "Gemma 2B"],
52
+ "General": ["Phi-2", "TinyLlama"]
53
+ },
54
+ "Intel i5": {
55
+ "Coding": ["Code Llama (7B)", "Deepseek Coder (6.7B)"],
56
+ "Math & Logic": ["Mistral 7B", "Gemma 7B"],
57
+ "General": ["Phi-2", "Mistral", "LLaMA 2 (7B)"]
58
+ },
59
+ "Intel i7": {
60
+ "Coding": ["Code Llama (13B - Q4)", "Deepseek Coder 6.7B"],
61
+ "Math & Logic": ["Mistral 7B", "LLaMA 2 13B (quantized)"],
62
+ "General": ["LLaMA 2 (13B)", "OpenChat 3.5"]
63
+ },
64
+ "Apple M Series": {
65
+ "Coding": ["Code Llama 7B (Q4)", "Phi-2"],
66
+ "Math & Logic": ["Gemma 7B", "Mistral (quantized)"],
67
+ "General": ["Mistral", "LLaMA 2 7B", "Phi-2"]
68
+ },
69
+ "AMD Ryzen": {
70
+ "Coding": ["Deepseek Coder", "Code Llama"],
71
+ "Math & Logic": ["Mistral", "LLaMA 2"],
72
+ "General": ["Phi-2", "Mistral", "LLaMA 2"]
73
+ },
74
+ "Qualcomm Snapdragon": {
75
+ "Coding": ["Phi-2 (on-device)"],
76
+ "Math & Logic": ["TinyLlama", "Phi-2"],
77
+ "General": ["TinyLlama", "Gemma 2B"]
78
+ },
79
+ "Other/Unknown": {
80
+ "Coding": ["Phi-2", "TinyLlama"],
81
+ "Math & Logic": ["Gemma 2B", "TinyLlama"],
82
+ "General": ["Phi-2", "TinyLlama"]
83
+ }
84
+ }
85
+
86
+ quantized_sizes = {
87
+ "TinyLlama": "FP16: 0.6GB, 8-bit: 0.3GB, 4-bit: 0.15GB",
88
+ "Phi-2": "FP16: 5.2GB, 8-bit: 2.6GB, 4-bit: 1.3GB",
89
+ "Mistral": "FP16: 13GB, 8-bit: 7GB, 4-bit: 3.5GB",
90
+ "Gemma 2B": "FP16: 4.2GB, 8-bit: 2.1GB, 4-bit: 1.1GB",
91
+ "Gemma 7B": "FP16: 13GB, 8-bit: 6.5GB, 4-bit: 3.2GB",
92
+ "Code Llama": "7B: FP16: 13GB, 8-bit: 6.5GB, 4-bit: 3.3GB | 13B: FP16: 26GB, 8-bit: 13GB, 4-bit: 6.5GB",
93
+ "Deepseek Coder": "6.7B: FP16: 12.8GB, 8-bit: 6.4GB, 4-bit: 3.2GB",
94
+ "LLaMA 2": "7B: FP16: 13GB, 8-bit: 6.7GB, 4-bit: 3.5GB | 13B: FP16: 26GB, 8-bit: 13GB, 4-bit: 6.5GB",
95
+ "OpenChat 3.5": "FP16: 7.1GB, 8-bit: 3.6GB, 4-bit: 1.8GB"
96
+ }
97
+
98
+ if cpu_name:
99
+ st.markdown("---")
100
+ st.subheader(" Your Hardware Configuration")
101
+ st.write(f"**Processor Name:** {cpu_name}")
102
+ st.write(f"**CPU Category:** {cpu_category}")
103
+ st.write(f"**GPU:** {gpu_name or 'Not specified'}")
104
+
105
+ score_label, score_note = performance_score.get(cpu_category, ("🟡 Unknown", "Estimate based on general category."))
106
+ st.success(f"💡 Performance Score: {score_label}")
107
+ st.caption(score_note)
108
+
109
+ st.markdown("---")
110
+ st.subheader("📋 Recommended LLMs for Local Use (Ollama Compatible)")
111
+
112
+ recommendations_text = f"Processor: {cpu_name} ({cpu_category})\\nGPU: {gpu_name or 'None'}\\nPerformance Score: {score_label}\\n\\nRecommended Models:\\n"
113
+
114
+ recs = llm_recommendations.get(cpu_category, llm_recommendations["Other/Unknown"])
115
+ for task in ["Coding", "Math & Logic", "General"]:
116
+ st.markdown(f"### 🔹 {task}")
117
+ recommendations_text += f"\\n{task}:\\n"
118
+ for model in recs[task]:
119
+ st.markdown(f"- ✅ **{model}**")
120
+ recommendations_text += f"- {model}"
121
+ for key in quantized_sizes:
122
+ if key.lower() in model.lower():
123
+ st.caption(f"💾 {quantized_sizes[key]}")
124
+ recommendations_text += f" ({quantized_sizes[key]})"
125
+ break
126
+ # Generate command
127
+ cmd = model.split("(")[0].strip().lower().replace(" ", "_").replace("-", "")
128
+ st.code(f"ollama pull {cmd}", language="bash")
129
+ recommendations_text += f"\\n Command: ollama pull {cmd}\\n"
130
+
131
+ st.markdown("---")
132
+ st.markdown("💡 _Tip: Run these models using `ollama run <model>` or download with `ollama pull <model>`._")
133
+
134
+ st.download_button("📥 Download These Recommendations", recommendations_text, file_name="llm_suggestions.txt")
135
+ else:
136
+ st.info("Enter your processor details to see LLM recommendations.")
src/run3.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # llm_training_estimator.py
2
+
3
+ def get_gpu_teraflops(gpu_type: str, exo_flops: float = None) -> float:
4
+ """
5
+ Returns TFLOPs/s based on GPU type or Exo input.
6
+ """
7
+ gpu_lookup = {
8
+ "A100": 312, # FP16
9
+ "H100": 700,
10
+ }
11
+
12
+ if gpu_type == "Exo":
13
+ if exo_flops is None or exo_flops <= 0:
14
+ raise ValueError("Exo TFLOPs must be provided.")
15
+ return exo_flops
16
+
17
+ return gpu_lookup.get(gpu_type, 0)
18
+
19
+
20
+ def get_gpu_cost_per_tflop_hour(gpu_type: str, manual_cost: float = None) -> float:
21
+ """
22
+ Returns ₹ cost per TFLOP-hour based on GPU type.
23
+ """
24
+ cost_lookup = {
25
+ "A100": 17.64 * 83, # $17.64 × ₹83 (approx.) = ₹1464 per TFLOP/hr
26
+ "H100": 7.56 * 83 # ₹627 per TFLOP/hr
27
+ }
28
+
29
+ if gpu_type == "Exo" and manual_cost:
30
+ return manual_cost
31
+ return cost_lookup.get(gpu_type, 0)
32
+
33
+
34
+ def estimate_training_time_and_cost(params_billion: float, tokens_billion: float, teraflops: float,
35
+ cost_per_tflop_hr: float = 0.0):
36
+ """
37
+ Estimate training time and cost.
38
+
39
+ Returns:
40
+ - FLOPs required
41
+ - Time (hours/days)
42
+ - Cost (₹)
43
+ """
44
+ total_flops_required = 6 * params_billion * 1e9 * tokens_billion * 1e9 # 6 × N × T
45
+ time_seconds = total_flops_required / (teraflops * 1e12)
46
+ time_hours = time_seconds / 3600
47
+ time_days = time_hours / 24
48
+
49
+ total_cost = (teraflops * time_hours) * cost_per_tflop_hr if cost_per_tflop_hr > 0 else 0
50
+
51
+ return {
52
+ "flops_required": total_flops_required,
53
+ "time_hours": time_hours,
54
+ "time_days": time_days,
55
+ "total_cost": total_cost
56
+ }
src/utils.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # utils.py
2
+
3
+ def get_all_models_from_database(db):
4
+ models = []
5
+ for tier, categories in db.items():
6
+ for category, items in categories.items():
7
+ for model in items:
8
+ display_name = f"{model['name']} | {model['size']} | {category} | {tier}"
9
+ models.append({
10
+ "display": display_name,
11
+ "name": model["name"],
12
+ "size": model["size"],
13
+ "description": model["description"],
14
+ "cost_a100": model.get("cost(A100)", "₹0"),
15
+ "cost_h100": model.get("cost(H100)", "₹0"),
16
+ "tier": tier,
17
+ "category": category
18
+ })
19
+ return models