Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -40,65 +40,149 @@ class UltimateModelLoader:
|
|
40 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
41 |
|
42 |
# Comprehensive model configurations
|
43 |
-
self.model_configs =
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
"gpt2-medium": {
|
46 |
-
"display_name": "GPT2 Medium (355M)",
|
47 |
"size": "medium",
|
48 |
-
"priority":
|
49 |
"reliable": True,
|
50 |
"params": 355_000_000
|
51 |
},
|
52 |
"gpt2": {
|
53 |
-
"display_name": "GPT2 Base (117M)",
|
54 |
"size": "small",
|
55 |
-
"priority":
|
56 |
"reliable": True,
|
57 |
"params": 117_000_000
|
58 |
},
|
59 |
"distilgpt2": {
|
60 |
-
"display_name": "DistilGPT2 (82M)",
|
61 |
"size": "small",
|
62 |
-
"priority":
|
63 |
"reliable": True,
|
64 |
"params": 82_000_000
|
65 |
},
|
66 |
-
# Advanced models (priority 4-7)
|
67 |
"microsoft/DialoGPT-medium": {
|
68 |
-
"display_name": "DialoGPT Medium (355M)",
|
69 |
"size": "medium",
|
70 |
-
"priority":
|
71 |
"reliable": True,
|
72 |
"params": 355_000_000
|
73 |
-
},
|
74 |
-
"state-spaces/mamba-130m": {
|
75 |
-
"display_name": "Mamba 130M",
|
76 |
-
"size": "small",
|
77 |
-
"priority": 5,
|
78 |
-
"reliable": False, # Needs validation
|
79 |
-
"params": 130_000_000,
|
80 |
-
"vocab_size": 50280,
|
81 |
-
"d_model": 768
|
82 |
-
},
|
83 |
-
"state-spaces/mamba-790m": {
|
84 |
-
"display_name": "Mamba 790M",
|
85 |
-
"size": "large",
|
86 |
-
"priority": 6,
|
87 |
-
"reliable": False,
|
88 |
-
"params": 790_000_000,
|
89 |
-
"vocab_size": 50280,
|
90 |
-
"d_model": 1536
|
91 |
-
},
|
92 |
-
"state-spaces/mamba-1.4b": {
|
93 |
-
"display_name": "Mamba 1.4B",
|
94 |
-
"size": "xlarge",
|
95 |
-
"priority": 7,
|
96 |
-
"reliable": False,
|
97 |
-
"params": 1_400_000_000,
|
98 |
-
"vocab_size": 50280,
|
99 |
-
"d_model": 2048
|
100 |
}
|
101 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
# Generation configurations by model size
|
104 |
self.generation_configs = {
|
@@ -1209,18 +1293,22 @@ def create_ultimate_interface():
|
|
1209 |
) as demo:
|
1210 |
|
1211 |
gr.Markdown("""
|
1212 |
-
# π Mamba Encoder Swarm
|
|
|
|
|
1213 |
|
1214 |
-
|
1215 |
|
1216 |
-
|
1217 |
""")
|
1218 |
|
1219 |
# Ultimate status display
|
1220 |
with gr.Row():
|
1221 |
-
status_text = "π’
|
1222 |
-
model_info = f" |
|
1223 |
-
|
|
|
|
|
1224 |
|
1225 |
with gr.Row():
|
1226 |
# Ultimate control panel
|
@@ -1310,15 +1398,17 @@ def create_ultimate_interface():
|
|
1310 |
# Ultimate footer
|
1311 |
gr.Markdown("""
|
1312 |
---
|
1313 |
-
###
|
1314 |
-
- **π§
|
1315 |
- **π― Elite Domain Routing** - 7 specialized domains with confidence-based encoder selection
|
1316 |
-
- **β‘
|
1317 |
- **π‘οΈ Zero-Gibberish Guarantee** - Multi-layer quality validation prevents nonsense output
|
1318 |
- **π Ultimate Analytics** - Real-time performance monitoring with comprehensive metrics
|
1319 |
-
- **π Smart Fallbacks** -
|
1320 |
-
- **ποΈ Dynamic Control** - Real-time model switching
|
1321 |
-
- **π Production Ready** - Enterprise-grade reliability
|
|
|
|
|
1322 |
""")
|
1323 |
|
1324 |
return demo
|
|
|
40 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
41 |
|
42 |
# Comprehensive model configurations
|
43 |
+
self.model_configs = self._get_all_available_models()
|
44 |
+
|
45 |
+
def _get_all_available_models(self):
|
46 |
+
"""Get all available models including trained checkpoints"""
|
47 |
+
models = {}
|
48 |
+
|
49 |
+
# Check for custom trained models first (highest priority)
|
50 |
+
trained_models = self._discover_trained_models()
|
51 |
+
for model_name, config in trained_models.items():
|
52 |
+
models[model_name] = config
|
53 |
+
|
54 |
+
# Standard models with adjusted priorities
|
55 |
+
models.update({
|
56 |
+
# Priority Mamba models - adjusted priorities for trained models
|
57 |
+
"state-spaces/mamba-130m": {
|
58 |
+
"display_name": "Mamba 130M Encoder",
|
59 |
+
"size": "small",
|
60 |
+
"priority": 10, # Lower priority than trained models
|
61 |
+
"reliable": True,
|
62 |
+
"params": 130_000_000,
|
63 |
+
"vocab_size": 50280,
|
64 |
+
"d_model": 768
|
65 |
+
},
|
66 |
+
"state-spaces/mamba-790m": {
|
67 |
+
"display_name": "Mamba 790M Encoder",
|
68 |
+
"size": "large",
|
69 |
+
"priority": 11,
|
70 |
+
"reliable": True,
|
71 |
+
"params": 790_000_000,
|
72 |
+
"vocab_size": 50280,
|
73 |
+
"d_model": 1536
|
74 |
+
},
|
75 |
+
"state-spaces/mamba-1.4b": {
|
76 |
+
"display_name": "Mamba 1.4B Encoder",
|
77 |
+
"size": "xlarge",
|
78 |
+
"priority": 12,
|
79 |
+
"reliable": True,
|
80 |
+
"params": 1_400_000_000,
|
81 |
+
"vocab_size": 50280,
|
82 |
+
"d_model": 2048
|
83 |
+
},
|
84 |
+
# Fallback models (priority 20-27) - Only used if Mamba fails
|
85 |
"gpt2-medium": {
|
86 |
+
"display_name": "GPT2 Medium (355M) [Fallback]",
|
87 |
"size": "medium",
|
88 |
+
"priority": 20,
|
89 |
"reliable": True,
|
90 |
"params": 355_000_000
|
91 |
},
|
92 |
"gpt2": {
|
93 |
+
"display_name": "GPT2 Base (117M) [Fallback]",
|
94 |
"size": "small",
|
95 |
+
"priority": 21,
|
96 |
"reliable": True,
|
97 |
"params": 117_000_000
|
98 |
},
|
99 |
"distilgpt2": {
|
100 |
+
"display_name": "DistilGPT2 (82M) [Fallback]",
|
101 |
"size": "small",
|
102 |
+
"priority": 22,
|
103 |
"reliable": True,
|
104 |
"params": 82_000_000
|
105 |
},
|
|
|
106 |
"microsoft/DialoGPT-medium": {
|
107 |
+
"display_name": "DialoGPT Medium (355M) [Fallback]",
|
108 |
"size": "medium",
|
109 |
+
"priority": 23,
|
110 |
"reliable": True,
|
111 |
"params": 355_000_000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
+
})
|
114 |
+
|
115 |
+
return models
|
116 |
+
|
117 |
+
def _discover_trained_models(self):
|
118 |
+
"""Discover custom trained models in checkpoints directory"""
|
119 |
+
trained_models = {}
|
120 |
+
|
121 |
+
# Check for checkpoint directories
|
122 |
+
checkpoint_dirs = [
|
123 |
+
"checkpoints",
|
124 |
+
"mamba_checkpoints",
|
125 |
+
"training_output"
|
126 |
+
]
|
127 |
+
|
128 |
+
priority = 1 # Highest priority for trained models
|
129 |
+
|
130 |
+
for checkpoint_dir in checkpoint_dirs:
|
131 |
+
if os.path.exists(checkpoint_dir):
|
132 |
+
for item in os.listdir(checkpoint_dir):
|
133 |
+
item_path = os.path.join(checkpoint_dir, item)
|
134 |
+
|
135 |
+
# Check if it's a model directory with config.json
|
136 |
+
config_path = os.path.join(item_path, "config.json")
|
137 |
+
if os.path.isdir(item_path) and os.path.exists(config_path):
|
138 |
+
|
139 |
+
try:
|
140 |
+
import json
|
141 |
+
with open(config_path, 'r') as f:
|
142 |
+
model_config = json.load(f)
|
143 |
+
|
144 |
+
# Estimate model size from config
|
145 |
+
d_model = model_config.get('d_model', model_config.get('hidden_size', 768))
|
146 |
+
n_layers = model_config.get('n_layers', model_config.get('num_hidden_layers', 12))
|
147 |
+
vocab_size = model_config.get('vocab_size', 50257)
|
148 |
+
|
149 |
+
# Estimate parameters
|
150 |
+
estimated_params = d_model * d_model * n_layers * 4 # Rough estimate
|
151 |
+
|
152 |
+
# Determine size category
|
153 |
+
if estimated_params < 200_000_000:
|
154 |
+
size = "small"
|
155 |
+
elif estimated_params < 800_000_000:
|
156 |
+
size = "medium"
|
157 |
+
elif estimated_params < 1_500_000_000:
|
158 |
+
size = "large"
|
159 |
+
else:
|
160 |
+
size = "xlarge"
|
161 |
+
|
162 |
+
trained_models[item_path] = {
|
163 |
+
"display_name": f"π― Custom Trained: {item} ({d_model}D)",
|
164 |
+
"size": size,
|
165 |
+
"priority": priority,
|
166 |
+
"reliable": True,
|
167 |
+
"params": estimated_params,
|
168 |
+
"vocab_size": vocab_size,
|
169 |
+
"d_model": d_model,
|
170 |
+
"is_custom": True,
|
171 |
+
"local_path": item_path
|
172 |
+
}
|
173 |
+
|
174 |
+
priority += 1
|
175 |
+
|
176 |
+
except Exception as e:
|
177 |
+
logger.warning(f"Could not load config for {item_path}: {e}")
|
178 |
+
continue
|
179 |
+
|
180 |
+
if trained_models:
|
181 |
+
logger.info(f"π― Found {len(trained_models)} custom trained models!")
|
182 |
+
for name, config in trained_models.items():
|
183 |
+
logger.info(f" - {config['display_name']}")
|
184 |
+
|
185 |
+
return trained_models
|
186 |
|
187 |
# Generation configurations by model size
|
188 |
self.generation_configs = {
|
|
|
1293 |
) as demo:
|
1294 |
|
1295 |
gr.Markdown("""
|
1296 |
+
# π Ultimate Mamba Encoder Swarm - Production Intelligence System
|
1297 |
+
|
1298 |
+
**π Advanced AI Language Model with True Mamba Encoder Swarm Intelligence**
|
1299 |
|
1300 |
+
Features cutting-edge **Mamba State-Space Models**, advanced domain routing, comprehensive performance analytics, and multi-tier quality protection.
|
1301 |
|
1302 |
+
**π₯ Now Prioritizing REAL Mamba Encoders over GPT2 fallbacks!**
|
1303 |
""")
|
1304 |
|
1305 |
# Ultimate status display
|
1306 |
with gr.Row():
|
1307 |
+
status_text = "π’ Mamba Encoder System Online" if swarm.model_loaded else "π‘ Protected Fallback Mode"
|
1308 |
+
model_info = f" | Active: {swarm.model_loader.model_name} ({swarm.current_model_size.title()})" if swarm.model_loaded else ""
|
1309 |
+
is_mamba = "mamba" in swarm.model_loader.model_name.lower() if swarm.model_loaded and swarm.model_loader.model_name else False
|
1310 |
+
encoder_type = "π MAMBA ENCODERS" if is_mamba else "β οΈ FALLBACK MODE"
|
1311 |
+
gr.Markdown(f"**{encoder_type}**: {status_text}{model_info}", elem_classes=["status-box"])
|
1312 |
|
1313 |
with gr.Row():
|
1314 |
# Ultimate control panel
|
|
|
1398 |
# Ultimate footer
|
1399 |
gr.Markdown("""
|
1400 |
---
|
1401 |
+
### π True Mamba Encoder Swarm Features
|
1402 |
+
- **π§ Real Mamba State-Space Models** - Prioritized Mamba-130M, Mamba-790M, Mamba-1.4B encoders
|
1403 |
- **π― Elite Domain Routing** - 7 specialized domains with confidence-based encoder selection
|
1404 |
+
- **β‘ Advanced State-Space Processing** - Leveraging Mamba's selective state-space architecture
|
1405 |
- **π‘οΈ Zero-Gibberish Guarantee** - Multi-layer quality validation prevents nonsense output
|
1406 |
- **π Ultimate Analytics** - Real-time performance monitoring with comprehensive metrics
|
1407 |
+
- **π Smart Fallbacks** - GPT2 models only used if Mamba encoders fail to load
|
1408 |
+
- **ποΈ Dynamic Control** - Real-time model switching between different Mamba sizes
|
1409 |
+
- **π Production Ready** - Enterprise-grade reliability with true encoder swarm intelligence
|
1410 |
+
|
1411 |
+
**Note**: System prioritizes Mamba encoders over traditional transformers for authentic swarm behavior!
|
1412 |
""")
|
1413 |
|
1414 |
return demo
|