Commit Β·
6e9f653
1
Parent(s): add21d4
ui improved
Browse files
app.py
CHANGED
|
@@ -284,7 +284,7 @@ class ModelProfiler:
|
|
| 284 |
|
| 285 |
# Only flag dimension mismatch if dimensions are non-zero and don't match
|
| 286 |
if b_hidden > 0 and adapter_hidden > 0 and b_hidden != adapter_hidden:
|
| 287 |
-
mismatch_reasons.append(f"
|
| 288 |
|
| 289 |
# Check target modules against architecture
|
| 290 |
arch_targets = {
|
|
@@ -301,31 +301,31 @@ class ModelProfiler:
|
|
| 301 |
|
| 302 |
# If no valid targets found but we have target modules, it might still work
|
| 303 |
if target_modules and not has_valid_target and b_type not in ["unknown"]:
|
| 304 |
-
mismatch_reasons.append(f"
|
| 305 |
|
| 306 |
-
status = "success" if not mismatch_reasons else "warning"
|
| 307 |
-
title = "
|
| 308 |
|
| 309 |
detail_notes = ""
|
| 310 |
if mismatch_reasons:
|
| 311 |
detail_notes = "\n\n".join(mismatch_reasons)
|
| 312 |
else:
|
| 313 |
-
detail_notes = "
|
| 314 |
|
| 315 |
details_md = f"""
|
| 316 |
-
###
|
| 317 |
- **Architecture Type**: `{b_type.upper()}`
|
| 318 |
- **Hidden Dimensions**: `{b_hidden}` units
|
| 319 |
- **Attention Heads**: `{b_heads}` heads
|
| 320 |
- **Transformer Depth**: `{b_layers}` layers
|
| 321 |
|
| 322 |
-
###
|
| 323 |
- **PEFT Method**: `{adapt_cfg.get('peft_type', 'LORA')}`
|
| 324 |
- **LoRA Rank (r)**: `{adapt_cfg.get('r', 'N/A')}`
|
| 325 |
- **Alpha (scaling)**: `{adapt_cfg.get('lora_alpha', 'N/A')}`
|
| 326 |
- **Target Modules**: `{', '.join(target_modules[:6])}{'...' if len(target_modules) > 6 else ''}`
|
| 327 |
|
| 328 |
-
###
|
| 329 |
{detail_notes}
|
| 330 |
"""
|
| 331 |
|
|
@@ -396,15 +396,14 @@ class ModelProfiler:
|
|
| 396 |
|
| 397 |
report_md = f"""
|
| 398 |
<div class='dashboard-card'>
|
| 399 |
-
<h3>
|
| 400 |
<div style='display: flex; gap: 2rem;'>
|
| 401 |
<div><p>Total Provisioned VRAM</p><p class='metric-val'>{total:.2f} GB</p></div>
|
| 402 |
<div><p>KV Cache Overhead</p><p class='metric-val'>{mem_kv*1024:.0f} MB</p></div>
|
| 403 |
<div><p>Composition Efficiency</p><p class='metric-val' style='color: #10b981;'>{savings:.1f}%</p></div>
|
| 404 |
</div>
|
| 405 |
<p style='margin-top: 1rem; font-size: 0.9rem; color: #64748b;'>
|
| 406 |
-
|
| 407 |
-
using only {total/mem_weights:.1f}x the base model memory.
|
| 408 |
</p>
|
| 409 |
</div>
|
| 410 |
"""
|
|
@@ -426,15 +425,14 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="indigo", font=[gr.themes.Goo
|
|
| 426 |
gr.HTML("""
|
| 427 |
<div class='hero-banner'>
|
| 428 |
<div style='max-width: 980px;'>
|
| 429 |
-
<div class='hero-pill'>
|
| 430 |
<h1>Modular Model Composition Explorer</h1>
|
| 431 |
-
<p>
|
| 432 |
-
</p>
|
| 433 |
<div style='display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem;'>
|
| 434 |
<span class='hero-pill'>HF Hub compatible</span>
|
| 435 |
-
<span class='hero-pill'>PEFT
|
| 436 |
<span class='hero-pill'>Memory planning</span>
|
| 437 |
-
<span class='hero-pill'>
|
| 438 |
</div>
|
| 439 |
</div>
|
| 440 |
</div>
|
|
@@ -461,7 +459,7 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="indigo", font=[gr.themes.Goo
|
|
| 461 |
""")
|
| 462 |
|
| 463 |
with gr.Tabs():
|
| 464 |
-
with gr.Tab("
|
| 465 |
with gr.Row():
|
| 466 |
with gr.Column(scale=1):
|
| 467 |
gr.HTML("""
|
|
@@ -474,12 +472,12 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="indigo", font=[gr.themes.Goo
|
|
| 474 |
adapter_input = gr.Textbox(label="Adapter Repository", placeholder="e.g. username/model-lora", value="gpt2")
|
| 475 |
audit_btn = gr.Button("Execute Audit", variant="primary")
|
| 476 |
with gr.Column(scale=2):
|
| 477 |
-
status_out = gr.HTML(profiler._render_status("success", "
|
| 478 |
-
details_out = gr.Markdown("###
|
| 479 |
|
| 480 |
audit_btn.click(profiler.validate_architecture, [base_input, adapter_input], [status_out, details_out])
|
| 481 |
|
| 482 |
-
with gr.Tab("
|
| 483 |
with gr.Row():
|
| 484 |
with gr.Column(scale=1):
|
| 485 |
gr.Markdown("### Controller Settings")
|
|
@@ -494,7 +492,7 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="indigo", font=[gr.themes.Goo
|
|
| 494 |
|
| 495 |
sim_btn.click(profiler.simulate_routing_dynamics, [r_style, r_count, r_thresh], [plot_lat, plot_dist])
|
| 496 |
|
| 497 |
-
with gr.Tab("
|
| 498 |
with gr.Row():
|
| 499 |
with gr.Column(scale=1):
|
| 500 |
gr.Markdown("### Provisioning Specs")
|
|
@@ -505,7 +503,7 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="indigo", font=[gr.themes.Goo
|
|
| 505 |
calc_btn = gr.Button("Generate Resource Report", variant="primary")
|
| 506 |
with gr.Column(scale=2):
|
| 507 |
vram_plot = gr.Plot()
|
| 508 |
-
report_html = gr.HTML("<div class='dashboard-card status-success'><h3>
|
| 509 |
|
| 510 |
calc_btn.click(profiler.calculate_resource_footprint, [v_scale, v_quant, v_adapters, v_ctx], [vram_plot, report_html])
|
| 511 |
|
|
|
|
| 284 |
|
| 285 |
# Only flag dimension mismatch if dimensions are non-zero and don't match
|
| 286 |
if b_hidden > 0 and adapter_hidden > 0 and b_hidden != adapter_hidden:
|
| 287 |
+
mismatch_reasons.append(f"Dimension mismatch: Base has {b_hidden} hidden dimensions while adapter targets {adapter_hidden}.")
|
| 288 |
|
| 289 |
# Check target modules against architecture
|
| 290 |
arch_targets = {
|
|
|
|
| 301 |
|
| 302 |
# If no valid targets found but we have target modules, it might still work
|
| 303 |
if target_modules and not has_valid_target and b_type not in ["unknown"]:
|
| 304 |
+
mismatch_reasons.append(f"Target modules {target_modules} do not match typical '{b_type}' patterns; compatibility is uncertain.")
|
| 305 |
|
| 306 |
+
status = "success" if not mismatch_reasons else "warning"
|
| 307 |
+
title = "Architectural Alignment Confirmed" if not mismatch_reasons else "Review Recommended"
|
| 308 |
|
| 309 |
detail_notes = ""
|
| 310 |
if mismatch_reasons:
|
| 311 |
detail_notes = "\n\n".join(mismatch_reasons)
|
| 312 |
else:
|
| 313 |
+
detail_notes = "All structural tensors are dimensionally compatible and target modules match architecture patterns."
|
| 314 |
|
| 315 |
details_md = f"""
|
| 316 |
+
### Structural Audit: `{base_id}`
|
| 317 |
- **Architecture Type**: `{b_type.upper()}`
|
| 318 |
- **Hidden Dimensions**: `{b_hidden}` units
|
| 319 |
- **Attention Heads**: `{b_heads}` heads
|
| 320 |
- **Transformer Depth**: `{b_layers}` layers
|
| 321 |
|
| 322 |
+
### Adapter Composition: `{adapter_id}`
|
| 323 |
- **PEFT Method**: `{adapt_cfg.get('peft_type', 'LORA')}`
|
| 324 |
- **LoRA Rank (r)**: `{adapt_cfg.get('r', 'N/A')}`
|
| 325 |
- **Alpha (scaling)**: `{adapt_cfg.get('lora_alpha', 'N/A')}`
|
| 326 |
- **Target Modules**: `{', '.join(target_modules[:6])}{'...' if len(target_modules) > 6 else ''}`
|
| 327 |
|
| 328 |
+
### Compatibility Notes
|
| 329 |
{detail_notes}
|
| 330 |
"""
|
| 331 |
|
|
|
|
| 396 |
|
| 397 |
report_md = f"""
|
| 398 |
<div class='dashboard-card'>
|
| 399 |
+
<h3>Resource Summary</h3>
|
| 400 |
<div style='display: flex; gap: 2rem;'>
|
| 401 |
<div><p>Total Provisioned VRAM</p><p class='metric-val'>{total:.2f} GB</p></div>
|
| 402 |
<div><p>KV Cache Overhead</p><p class='metric-val'>{mem_kv*1024:.0f} MB</p></div>
|
| 403 |
<div><p>Composition Efficiency</p><p class='metric-val' style='color: #10b981;'>{savings:.1f}%</p></div>
|
| 404 |
</div>
|
| 405 |
<p style='margin-top: 1rem; font-size: 0.9rem; color: #64748b;'>
|
| 406 |
+
This estimate uses a shared base model plus adapter overhead and KV cache memory for {adapters} active adapters.
|
|
|
|
| 407 |
</p>
|
| 408 |
</div>
|
| 409 |
"""
|
|
|
|
| 425 |
gr.HTML("""
|
| 426 |
<div class='hero-banner'>
|
| 427 |
<div style='max-width: 980px;'>
|
| 428 |
+
<div class='hero-pill'>Architecture profiling for modular model deployments</div>
|
| 429 |
<h1>Modular Model Composition Explorer</h1>
|
| 430 |
+
<p>Compare base model architectures and adapters, identify compatibility gaps, and evaluate memory requirements with a clean, professional interface.</p>
|
|
|
|
| 431 |
<div style='display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem;'>
|
| 432 |
<span class='hero-pill'>HF Hub compatible</span>
|
| 433 |
+
<span class='hero-pill'>PEFT-aware analysis</span>
|
| 434 |
<span class='hero-pill'>Memory planning</span>
|
| 435 |
+
<span class='hero-pill'>Deployment-ready metrics</span>
|
| 436 |
</div>
|
| 437 |
</div>
|
| 438 |
</div>
|
|
|
|
| 459 |
""")
|
| 460 |
|
| 461 |
with gr.Tabs():
|
| 462 |
+
with gr.Tab("Architectural Audit"):
|
| 463 |
with gr.Row():
|
| 464 |
with gr.Column(scale=1):
|
| 465 |
gr.HTML("""
|
|
|
|
| 472 |
adapter_input = gr.Textbox(label="Adapter Repository", placeholder="e.g. username/model-lora", value="gpt2")
|
| 473 |
audit_btn = gr.Button("Execute Audit", variant="primary")
|
| 474 |
with gr.Column(scale=2):
|
| 475 |
+
status_out = gr.HTML(profiler._render_status("success", "System Ready", "Enter model repository IDs and click Execute Audit to analyze architectural compatibility."))
|
| 476 |
+
details_out = gr.Markdown("### Structural Analysis\nResults will appear here after running the audit.")
|
| 477 |
|
| 478 |
audit_btn.click(profiler.validate_architecture, [base_input, adapter_input], [status_out, details_out])
|
| 479 |
|
| 480 |
+
with gr.Tab("Routing Simulator"):
|
| 481 |
with gr.Row():
|
| 482 |
with gr.Column(scale=1):
|
| 483 |
gr.Markdown("### Controller Settings")
|
|
|
|
| 492 |
|
| 493 |
sim_btn.click(profiler.simulate_routing_dynamics, [r_style, r_count, r_thresh], [plot_lat, plot_dist])
|
| 494 |
|
| 495 |
+
with gr.Tab("Infrastructure Planner"):
|
| 496 |
with gr.Row():
|
| 497 |
with gr.Column(scale=1):
|
| 498 |
gr.Markdown("### Provisioning Specs")
|
|
|
|
| 503 |
calc_btn = gr.Button("Generate Resource Report", variant="primary")
|
| 504 |
with gr.Column(scale=2):
|
| 505 |
vram_plot = gr.Plot()
|
| 506 |
+
report_html = gr.HTML("<div class='dashboard-card status-success'><h3>Ready to Calculate</h3><p>Adjust the provisioning specs on the left and click Generate Resource Report to analyze memory requirements.</p></div>")
|
| 507 |
|
| 508 |
calc_btn.click(profiler.calculate_resource_footprint, [v_scale, v_quant, v_adapters, v_ctx], [vram_plot, report_html])
|
| 509 |
|