Update app.py
Browse files
app.py
CHANGED
|
@@ -207,6 +207,36 @@ def quantize(model_path, repo_id, quant_method=None):
|
|
| 207 |
|
| 208 |
return final_path
|
| 209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
@timeit
|
| 211 |
def process_model(base_model_name, lora_model_name, repo_name, quant_methods, hf_token):
|
| 212 |
"""
|
|
@@ -243,6 +273,8 @@ def process_model(base_model_name, lora_model_name, repo_name, quant_methods, hf
|
|
| 243 |
# 量化模型
|
| 244 |
for quant_method in quant_methods:
|
| 245 |
quantize(output_dir, repo_name, quant_method=quant_method)
|
|
|
|
|
|
|
| 246 |
|
| 247 |
# 上传合并后的模型和量化模型
|
| 248 |
api.upload_large_folder(
|
|
|
|
| 207 |
|
| 208 |
return final_path
|
| 209 |
|
| 210 |
+
def create_readme(repo_name, base_model_name, lora_model_name, quant_methods):
|
| 211 |
+
readme_path = os.path.join("output", repo_name, "README.md")
|
| 212 |
+
readme_template = f"""
|
| 213 |
+
---
|
| 214 |
+
tags:
|
| 215 |
+
- autotrain
|
| 216 |
+
- text-generation-inference
|
| 217 |
+
- text-generation
|
| 218 |
+
- peft{"\n- quantization" if len(quant_methods) > 0 else ""}
|
| 219 |
+
library_name: transformers
|
| 220 |
+
base_model: {base_model_name}
|
| 221 |
+
widget:
|
| 222 |
+
- messages:
|
| 223 |
+
- role: user
|
| 224 |
+
content: What is your favorite condiment?
|
| 225 |
+
license: other
|
| 226 |
+
datasets:
|
| 227 |
+
- {lora_model_name}
|
| 228 |
+
---
|
| 229 |
+
# Model
|
| 230 |
+
{repo_name}
|
| 231 |
+
base_model: {base_model_name}
|
| 232 |
+
lora_model: {lora_model_name}
|
| 233 |
+
quant_methods: {quant_methods}
|
| 234 |
+
created_at: {time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())}
|
| 235 |
+
created_by: [Steven10429/apply_lora_and_quantize](https://github.com/Steven10429/apply_lora_and_quantize)"""
|
| 236 |
+
|
| 237 |
+
with open(readme_path, "w") as f:
|
| 238 |
+
f.write(readme_template)
|
| 239 |
+
|
| 240 |
@timeit
|
| 241 |
def process_model(base_model_name, lora_model_name, repo_name, quant_methods, hf_token):
|
| 242 |
"""
|
|
|
|
| 273 |
# 量化模型
|
| 274 |
for quant_method in quant_methods:
|
| 275 |
quantize(output_dir, repo_name, quant_method=quant_method)
|
| 276 |
+
|
| 277 |
+
create_readme(repo_name, base_model_name, lora_model_name, quant_methods)
|
| 278 |
|
| 279 |
# 上传合并后的模型和量化模型
|
| 280 |
api.upload_large_folder(
|