Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,50 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
from evo_transformer import EvoTransformer
|
| 4 |
-
import matplotlib.pyplot as plt
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
evo.evolve(generations)
|
|
|
|
| 9 |
history = evo.get_history()
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# Format history for output
|
| 13 |
-
trait_logs = ""
|
| 14 |
-
for i, config in enumerate(history):
|
| 15 |
-
trait_logs += f"Generation {i}: {config}\n"
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
ffn = [conf["ffn_dim"] for conf in history]
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
gr.Textbox(label="Evolution History"),
|
| 39 |
-
gr.Number(label="Simulated Accuracy"),
|
| 40 |
-
gr.Number(label="Estimated Parameters (M)"),
|
| 41 |
-
gr.Plot(label="Trait Evolution Plot"),
|
| 42 |
-
],
|
| 43 |
-
title="🧬 EvoTransformer Demo",
|
| 44 |
-
description="An evolving Transformer that mutates architecture traits during training. Watch the architecture change in real time!"
|
| 45 |
-
)
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from evo_transformer import EvoTransformer
|
|
|
|
| 3 |
|
| 4 |
+
# Initialize global EvoTransformer object
|
| 5 |
+
evo = EvoTransformer()
|
| 6 |
+
|
| 7 |
+
# Define Gradio functions
|
| 8 |
+
def evolve_and_display(generations):
|
| 9 |
evo.evolve(generations)
|
| 10 |
+
latest_config = evo.config
|
| 11 |
history = evo.get_history()
|
| 12 |
+
evaluation = evo.evaluate()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
history_table = "\n".join(
|
| 15 |
+
[f"Gen {i}: {cfg}" for i, cfg in enumerate(history[-generations:])]
|
| 16 |
+
)
|
|
|
|
| 17 |
|
| 18 |
+
return (
|
| 19 |
+
f"### Final Evolved Configuration\n"
|
| 20 |
+
f"**Layers**: {latest_config['layers']} \n"
|
| 21 |
+
f"**Attention Heads**: {latest_config['attention_heads']} \n"
|
| 22 |
+
f"**FFN Dimension**: {latest_config['ffn_dim']} \n"
|
| 23 |
+
f"**Dropout**: {latest_config['dropout']} \n"
|
| 24 |
+
f"**Memory**: {latest_config['memory']} \n\n"
|
| 25 |
+
f"### Evaluation\n"
|
| 26 |
+
f"**Simulated Accuracy**: {evaluation['accuracy']} \n"
|
| 27 |
+
f"**Estimated Parameters**: {evaluation['params']}M \n\n"
|
| 28 |
+
f"### Trait History (last {generations} generations)\n"
|
| 29 |
+
f"```\n{history_table}\n```"
|
| 30 |
+
)
|
| 31 |
|
| 32 |
+
# Build Gradio Interface
|
| 33 |
+
with gr.Blocks(title="EvoTransformer Demo") as demo:
|
| 34 |
+
gr.Markdown("# 🧬 EvoTransformer")
|
| 35 |
+
gr.Markdown("Simulate in-training architectural evolution of a Transformer model.")
|
| 36 |
+
|
| 37 |
+
with gr.Row():
|
| 38 |
+
generations_slider = gr.Slider(1, 10, value=3, label="Generations to Evolve")
|
| 39 |
+
evolve_btn = gr.Button("Evolve")
|
| 40 |
+
|
| 41 |
+
output_box = gr.Markdown()
|
| 42 |
|
| 43 |
+
evolve_btn.click(
|
| 44 |
+
evolve_and_display,
|
| 45 |
+
inputs=[generations_slider],
|
| 46 |
+
outputs=[output_box],
|
| 47 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
# Launch the app
|
| 50 |
+
demo.launch()
|