Spaces:
Running
Running
MekkCyber
commited on
Commit
Β·
47efb70
1
Parent(s):
0b80656
fix
Browse files
app.py
CHANGED
|
@@ -106,7 +106,7 @@ def save_model(model, model_name, quantization_type, group_size=128, username=No
|
|
| 106 |
repo_id=repo_name,
|
| 107 |
repo_type="model",
|
| 108 |
)
|
| 109 |
-
return f'<h1
|
| 110 |
|
| 111 |
def quantize_and_save(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None, model_name, quantization_type, group_size, quantized_model_name):
|
| 112 |
if oauth_token is None :
|
|
@@ -122,11 +122,12 @@ def quantize_and_save(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToke
|
|
| 122 |
return "group_size must be a number"
|
| 123 |
|
| 124 |
group_size = int(group_size)
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
css="""/* Custom CSS to allow scrolling */
|
|
@@ -135,18 +136,42 @@ css="""/* Custom CSS to allow scrolling */
|
|
| 135 |
with gr.Blocks(theme=gr.themes.Ocean(), css=css) as app:
|
| 136 |
gr.Markdown(
|
| 137 |
"""
|
| 138 |
-
#
|
| 139 |
|
| 140 |
-
Quantize your favorite Hugging Face models and save them to your profile!
|
| 141 |
"""
|
| 142 |
)
|
| 143 |
|
| 144 |
-
|
| 145 |
gr.LoginButton(elem_id="login-button", elem_classes="center-button", min_width=250)
|
| 146 |
|
| 147 |
m1 = gr.Markdown()
|
| 148 |
app.load(hello, inputs=None, outputs=m1)
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
with gr.Row():
|
| 151 |
with gr.Column():
|
| 152 |
with gr.Row():
|
|
@@ -177,38 +202,10 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=css) as app:
|
|
| 177 |
interactive=True,
|
| 178 |
show_label=False
|
| 179 |
)
|
| 180 |
-
# device = gr.Dropdown(
|
| 181 |
-
# label="Device (int4 only works with cuda)",
|
| 182 |
-
# choices=["cuda", "cpu"],
|
| 183 |
-
# value="cuda"
|
| 184 |
-
# )
|
| 185 |
-
# with gr.Row():
|
| 186 |
-
# username = gr.Textbox(
|
| 187 |
-
# label="Hugging Face Username",
|
| 188 |
-
# placeholder="Enter your Hugging Face username",
|
| 189 |
-
# value="",
|
| 190 |
-
# interactive=True,
|
| 191 |
-
# elem_id="username-box"
|
| 192 |
-
# )
|
| 193 |
with gr.Column():
|
| 194 |
quantize_button = gr.Button("Quantize and Save Model", variant="primary")
|
| 195 |
output_link = gr.Markdown(label="Quantized Model Link", container=True)
|
| 196 |
|
| 197 |
-
gr.Markdown(
|
| 198 |
-
"""
|
| 199 |
-
## Instructions
|
| 200 |
-
1. Login to your HuggingFace account
|
| 201 |
-
2. Enter the name of the Hugging Face LLM model you want to quantize (Make sure you have access to it)
|
| 202 |
-
3. Choose the quantization type.
|
| 203 |
-
4. Optionally, specify the group size.
|
| 204 |
-
5. Optionally, choose a custom name for the quantized model
|
| 205 |
-
6. Click "Quantize and Save Model" to start the process.
|
| 206 |
-
7. Once complete, you'll receive a link to the quantized model on Hugging Face.
|
| 207 |
-
|
| 208 |
-
Note: This process may take some time depending on the model size and your hardware you can check the container logs to see where are you at in the process!
|
| 209 |
-
"""
|
| 210 |
-
)
|
| 211 |
-
|
| 212 |
|
| 213 |
# Adding CSS styles for the username box
|
| 214 |
app.css = """
|
|
|
|
| 106 |
repo_id=repo_name,
|
| 107 |
repo_type="model",
|
| 108 |
)
|
| 109 |
+
return f'<h1> π€ DONE</h1><br/>Find your repo here: <a href="https://huggingface.co/{repo_name}" target="_blank" style="text-decoration:underline">{repo_name}</a>'
|
| 110 |
|
| 111 |
def quantize_and_save(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None, model_name, quantization_type, group_size, quantized_model_name):
|
| 112 |
if oauth_token is None :
|
|
|
|
| 122 |
return "group_size must be a number"
|
| 123 |
|
| 124 |
group_size = int(group_size)
|
| 125 |
+
|
| 126 |
+
try:
|
| 127 |
+
quantized_model = quantize_model(model_name, quantization_type, group_size, oauth_token, profile.username)
|
| 128 |
+
return save_model(quantized_model, model_name, quantization_type, group_size, profile.username, oauth_token, quantized_model_name)
|
| 129 |
+
except Exception as e :
|
| 130 |
+
return e
|
| 131 |
|
| 132 |
|
| 133 |
css="""/* Custom CSS to allow scrolling */
|
|
|
|
| 136 |
with gr.Blocks(theme=gr.themes.Ocean(), css=css) as app:
|
| 137 |
gr.Markdown(
|
| 138 |
"""
|
| 139 |
+
# π€ LLM Model TorchAO Quantization App
|
| 140 |
|
| 141 |
+
Quantize your favorite Hugging Face models using TorchAO and save them to your profile!
|
| 142 |
"""
|
| 143 |
)
|
| 144 |
|
|
|
|
| 145 |
gr.LoginButton(elem_id="login-button", elem_classes="center-button", min_width=250)
|
| 146 |
|
| 147 |
m1 = gr.Markdown()
|
| 148 |
app.load(hello, inputs=None, outputs=m1)
|
| 149 |
|
| 150 |
+
|
| 151 |
+
radio = gr.Radio(["show", "hide"], label="Show Instructions")
|
| 152 |
+
instructions = gr.Markdown(
|
| 153 |
+
"""
|
| 154 |
+
## Instructions
|
| 155 |
+
1. Login to your HuggingFace account
|
| 156 |
+
2. Enter the name of the Hugging Face LLM model you want to quantize (Make sure you have access to it)
|
| 157 |
+
3. Choose the quantization type.
|
| 158 |
+
4. Optionally, specify the group size.
|
| 159 |
+
5. Optionally, choose a custom name for the quantized model
|
| 160 |
+
6. Click "Quantize and Save Model" to start the process.
|
| 161 |
+
7. Once complete, you'll receive a link to the quantized model on Hugging Face.
|
| 162 |
+
|
| 163 |
+
Note: This process may take some time depending on the model size and your hardware you can check the container logs to see where are you at in the process!
|
| 164 |
+
""",
|
| 165 |
+
visible=False
|
| 166 |
+
)
|
| 167 |
+
def update_visibility(radio): # Accept the event argument, even if not used
|
| 168 |
+
value = radio # Get the selected value from the radio button
|
| 169 |
+
if value == "show":
|
| 170 |
+
return gr.Textbox(visible=True) #make it visible
|
| 171 |
+
else:
|
| 172 |
+
return gr.Textbox(visible=False)
|
| 173 |
+
radio.change(update_visibility, radio, instructions)
|
| 174 |
+
|
| 175 |
with gr.Row():
|
| 176 |
with gr.Column():
|
| 177 |
with gr.Row():
|
|
|
|
| 202 |
interactive=True,
|
| 203 |
show_label=False
|
| 204 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
with gr.Column():
|
| 206 |
quantize_button = gr.Button("Quantize and Save Model", variant="primary")
|
| 207 |
output_link = gr.Markdown(label="Quantized Model Link", container=True)
|
| 208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
# Adding CSS styles for the username box
|
| 211 |
app.css = """
|