Commit
•
049ec21
1
Parent(s):
c651b1a
initial import of code
Browse files- .gitignore +1 -0
- .vscode/settings.json +3 -0
- README.md +2 -2
- app.py +153 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.env/
|
.vscode/settings.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"editor.formatOnSave": true
|
3 |
+
}
|
README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: ⚡
|
4 |
-
colorFrom:
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.26.0
|
|
|
1 |
---
|
2 |
+
title: mergekit-config-generator
|
3 |
emoji: ⚡
|
4 |
+
colorFrom: red
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.26.0
|
app.py
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from huggingface_hub import HfApi
|
4 |
+
import subprocess
|
5 |
+
|
6 |
+
|
7 |
+
def create_config_yaml(
|
8 |
+
model_name,
|
9 |
+
model1,
|
10 |
+
model1_layers,
|
11 |
+
model2,
|
12 |
+
model2_layers,
|
13 |
+
merge_method,
|
14 |
+
base_model,
|
15 |
+
parameters,
|
16 |
+
dtype,
|
17 |
+
):
|
18 |
+
yaml_config = (
|
19 |
+
f" slices:\n"
|
20 |
+
" - sources:\n"
|
21 |
+
f" - model: {model1}\n"
|
22 |
+
f" layer_range: {model1_layers}\n"
|
23 |
+
f" - model: {model2}\n"
|
24 |
+
f" layer_range: {model2_layers}\n"
|
25 |
+
f" merge_method: {merge_method}\n"
|
26 |
+
f" base_model: {base_model}\n"
|
27 |
+
f" parameters:\n"
|
28 |
+
f" {parameters}\n"
|
29 |
+
f" dtype: {dtype}\n"
|
30 |
+
)
|
31 |
+
print("Writing YAML config to 'config.yaml'...")
|
32 |
+
|
33 |
+
try:
|
34 |
+
with open("config.yaml", "w", encoding="utf-8") as f:
|
35 |
+
f.write(yaml_config)
|
36 |
+
print("File 'config.yaml' written successfully.")
|
37 |
+
except Exception as e:
|
38 |
+
print(f"Error writing file: {e}")
|
39 |
+
return yaml_config
|
40 |
+
|
41 |
+
|
42 |
+
def execute_merge_command():
|
43 |
+
# Define the command and arguments
|
44 |
+
command = "mergekit-yaml"
|
45 |
+
args = ["config.yaml", "./output-model-directory"]
|
46 |
+
|
47 |
+
# Execute the command
|
48 |
+
result = subprocess.run([command] + args, capture_output=True, text=True)
|
49 |
+
|
50 |
+
# Check if the command was executed successfully
|
51 |
+
if result.returncode == 0:
|
52 |
+
print("Command executed successfully")
|
53 |
+
return f"Output:\n{result.stdout}"
|
54 |
+
else:
|
55 |
+
print("Error in executing command")
|
56 |
+
return f"Error:\n{result.stderr}"
|
57 |
+
|
58 |
+
|
59 |
+
# Function to push to HF Hub (for the third tab)
|
60 |
+
def push_to_hf_hub(model_name, yaml_config):
|
61 |
+
# Username and API token setup
|
62 |
+
username = "arcee-ai"
|
63 |
+
api_token = os.getenv("HF_TOKEN")
|
64 |
+
if api_token is None:
|
65 |
+
return "Hugging Face API token not set. Please set the HF_TOKEN environment variable."
|
66 |
+
|
67 |
+
# Initialize HfApi with token
|
68 |
+
api = HfApi(token=api_token)
|
69 |
+
|
70 |
+
repo_id = f"{username}/{model_name}"
|
71 |
+
|
72 |
+
try:
|
73 |
+
# Create a new repository on Hugging Face
|
74 |
+
api.create_repo(repo_id=repo_id, repo_type="model")
|
75 |
+
|
76 |
+
# For demonstration, let's just create a yaml file inside a folder
|
77 |
+
# os.makedirs("merge", exist_ok=True)
|
78 |
+
with open("config.yaml", "w") as file:
|
79 |
+
file.write(yaml_config)
|
80 |
+
|
81 |
+
# Upload the contents of the 'merge' folder to the repository
|
82 |
+
api.upload_folder(repo_id=repo_id, folder_path="merge")
|
83 |
+
|
84 |
+
return f"Successfully pushed to HF Hub: {repo_id}"
|
85 |
+
except Exception as e:
|
86 |
+
return str(e)
|
87 |
+
|
88 |
+
|
89 |
+
# make sure to add the themes as well
|
90 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo")) as app:
|
91 |
+
gr.Markdown("# Mergekit GUI") # Title for your Gradio app
|
92 |
+
with gr.Tab("Config YAML"):
|
93 |
+
# Inputs for the YAML config
|
94 |
+
with gr.Row():
|
95 |
+
model_name_input = gr.Textbox(label="Model Name")
|
96 |
+
model1_input = gr.Textbox(label="Model 1")
|
97 |
+
model1_layers_input = gr.Textbox(
|
98 |
+
label="Model 1 Layer Range", placeholder="[start, end]"
|
99 |
+
)
|
100 |
+
model2_input = gr.Textbox(label="Model 2")
|
101 |
+
model2_layers_input = gr.Textbox(
|
102 |
+
label="Model 2 Layer Range", placeholder="[start, end]"
|
103 |
+
)
|
104 |
+
merge_method_input = gr.Dropdown(
|
105 |
+
label="Merge Method", choices=["slerp", "linear"]
|
106 |
+
)
|
107 |
+
base_model_input = gr.Textbox(label="Base Model")
|
108 |
+
parameters_input = gr.Textbox(
|
109 |
+
label="Parameters", placeholder="Formatted as a list of dicts"
|
110 |
+
)
|
111 |
+
dtype_input = gr.Textbox(label="Data Type", value="bfloat16")
|
112 |
+
|
113 |
+
create_button = gr.Button("Create Config YAML")
|
114 |
+
|
115 |
+
create_button.click(
|
116 |
+
fn=create_config_yaml,
|
117 |
+
inputs=[
|
118 |
+
model_name_input,
|
119 |
+
model1_input,
|
120 |
+
model1_layers_input,
|
121 |
+
model2_input,
|
122 |
+
model2_layers_input,
|
123 |
+
merge_method_input,
|
124 |
+
base_model_input,
|
125 |
+
parameters_input,
|
126 |
+
dtype_input,
|
127 |
+
],
|
128 |
+
outputs=[],
|
129 |
+
)
|
130 |
+
|
131 |
+
with gr.Tab("Merge"):
|
132 |
+
# Placeholder for Merge tab contents
|
133 |
+
# Not yet tested
|
134 |
+
|
135 |
+
merge_output = gr.Textbox(label="Merge Output", interactive=False)
|
136 |
+
merge_button = gr.Button("Execute Merge Command")
|
137 |
+
|
138 |
+
merge_button.click(fn=execute_merge_command, inputs=[], outputs=merge_output)
|
139 |
+
|
140 |
+
with gr.Tab("Push to HF Hub"):
|
141 |
+
push_model_name_input = gr.Textbox(label="Model Name", interactive=False)
|
142 |
+
push_yaml_config_input = gr.Textbox(label="YAML Config", interactive=False)
|
143 |
+
push_output = gr.Textbox(label="Push Output", interactive=False)
|
144 |
+
push_button = gr.Button("Push to HF Hub")
|
145 |
+
|
146 |
+
push_button.click(
|
147 |
+
fn=push_to_hf_hub,
|
148 |
+
inputs=[push_model_name_input, push_yaml_config_input],
|
149 |
+
outputs=push_output,
|
150 |
+
)
|
151 |
+
|
152 |
+
|
153 |
+
app.launch()
|