Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import yaml
|
| 3 |
+
|
| 4 |
+
def generate_config(base_model, models, layer_range, merge_method):
|
| 5 |
+
slices = []
|
| 6 |
+
for model in models:
|
| 7 |
+
slice_config = {
|
| 8 |
+
"sources": [
|
| 9 |
+
{
|
| 10 |
+
"model": model,
|
| 11 |
+
"layer_range": layer_range
|
| 12 |
+
}
|
| 13 |
+
]
|
| 14 |
+
}
|
| 15 |
+
slices.append(slice_config)
|
| 16 |
+
|
| 17 |
+
config = {
|
| 18 |
+
"slices": slices,
|
| 19 |
+
"merge_method": merge_method,
|
| 20 |
+
"base_model": base_model,
|
| 21 |
+
"parameters": {
|
| 22 |
+
"t": [
|
| 23 |
+
{
|
| 24 |
+
"filter": "self_attn",
|
| 25 |
+
"value": [0, 0.5, 0.3, 0.7, 1]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"filter": "mlp",
|
| 29 |
+
"value": [1, 0.5, 0.7, 0.3, 0]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"value": 0.5
|
| 33 |
+
}
|
| 34 |
+
]
|
| 35 |
+
},
|
| 36 |
+
"dtype": "bfloat16"
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
return yaml.dump(config)
|
| 40 |
+
|
| 41 |
+
iface = gr.Interface(
|
| 42 |
+
fn=generate_config,
|
| 43 |
+
inputs="dropdown",
|
| 44 |
+
inputs2="multiselect",
|
| 45 |
+
inputs3=gr.inputs.NumberSlider(minimum=0, maximum=32, step=1),
|
| 46 |
+
inputs4="dropdown",
|
| 47 |
+
output_type="text",
|
| 48 |
+
output_formats=["yaml"],
|
| 49 |
+
title="Merge Config Builder",
|
| 50 |
+
description="Build a merge config file for your models"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
iface.launch()
|
| 54 |
+
|
| 55 |
+
Here's a breakdown of the code:
|
| 56 |
+
|
| 57 |
+
We define a function generate_config that takes in the base model, a list of additional models, the layer range, and the merge method as inputs.
|
| 58 |
+
We create a list of slices, where each slice contains the configuration for a single model.
|
| 59 |
+
We create the final config dictionary, which includes the slices, merge method, base model, parameters, and data type.
|
| 60 |
+
We use the yaml.dump function to convert the config dictionary to a YAML string.
|
| 61 |
+
We create a Gradio interface using the gr.Interface function.
|
| 62 |
+
We define the input and output components of the interface.
|
| 63 |
+
We launch the interface using the launch method.
|