Spaces:
Runtime error
Runtime error
menouar
commited on
Commit
Β·
c7b9e3f
1
Parent(s):
6674f1f
Update UI
Browse files- app.py +1 -1
- utils/notebook_generator.py +9 -9
app.py
CHANGED
@@ -235,7 +235,7 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(text_size='lg', font=["monospace"],
|
|
235 |
gr.Markdown('''
|
236 |
This space generates a **Jupyter Notebook file (.ipynb)** πβοΈ that guides you through the
|
237 |
entire process of **supervised fine-tuning** of a raw Large Language Model (**LLM**) π§ on a chosen dataset in
|
238 |
-
the **Conversational format**. The process is facilitated by an intuitive **User Interface (UI)**
|
239 |
''', elem_classes=["center_text"])
|
240 |
with dashed_row():
|
241 |
with centered_column():
|
|
|
235 |
gr.Markdown('''
|
236 |
This space generates a **Jupyter Notebook file (.ipynb)** πβοΈ that guides you through the
|
237 |
entire process of **supervised fine-tuning** of a raw Large Language Model (**LLM**) π§ on a chosen dataset in
|
238 |
+
the **Conversational format**. The process is facilitated by an intuitive **User Interface (UI)** ππ»**:**
|
239 |
''', elem_classes=["center_text"])
|
240 |
with dashed_row():
|
241 |
with centered_column():
|
utils/notebook_generator.py
CHANGED
@@ -37,7 +37,7 @@ except ImportError:
|
|
37 |
|
38 |
def create_install_flash_attention(cells: list):
|
39 |
text_cell = nbf.v4.new_markdown_cell(
|
40 |
-
"
|
41 |
text_cell1 = nbf.v4.new_markdown_cell("Installing Flash Attention to reduce the memory "
|
42 |
"and runtime cost of the attention layer, and improve the performance of "
|
43 |
"the model training. Learn more at [FlashAttention]("
|
@@ -59,7 +59,7 @@ import torch; assert torch.cuda.get_device_capability()[0] >= 8, 'Hardware not s
|
|
59 |
|
60 |
def create_login_hf_cells(cells: list, should_login: bool = False, model_name: Optional[str] = None):
|
61 |
text_cell = nbf.v4.new_markdown_cell(
|
62 |
-
"
|
63 |
|
64 |
text_1 = "Login with our `HF_TOKEN` in order to push the finetuned model to `huggingface_hub`."
|
65 |
|
@@ -219,7 +219,7 @@ a 24GB GPU for fine-tuning.
|
|
219 |
|
220 |
|
221 |
def create_lora_config_cells(cells: list, r: int, alpha: int, dropout: float, bias: str):
|
222 |
-
text_cell = nbf.v4.new_markdown_cell("
|
223 |
code = f"""
|
224 |
from peft import LoraConfig
|
225 |
|
@@ -249,7 +249,7 @@ def create_training_args_cells(cells: list, epochs, max_steps, logging_steps, pe
|
|
249 |
save_strategy, gradient_accumulation_steps, gradient_checkpointing,
|
250 |
learning_rate, max_grad_norm, warmup_ratio, lr_scheduler_type, output_dir,
|
251 |
report_to, seed):
|
252 |
-
text_cell = nbf.v4.new_markdown_cell("
|
253 |
to_install = None
|
254 |
if report_to == "all":
|
255 |
to_install = "azure_ml comet_ml mlflow tensorboard wandb"
|
@@ -298,7 +298,7 @@ args = TrainingArguments(
|
|
298 |
|
299 |
def create_sft_trainer_cells(cells: list, max_seq_length, packing):
|
300 |
text_cell = nbf.v4.new_markdown_cell(
|
301 |
-
"""
|
302 |
|
303 |
This `SFTTrainer` is a wrapper around the `transformers.Trainer` class and inherits all of its attributes and methods.
|
304 |
The trainer takes care of properly initializing the `PeftModel`.
|
@@ -362,7 +362,7 @@ trainer.save_model()
|
|
362 |
|
363 |
def create_free_gpu_cells(cells: list):
|
364 |
text_cell = nbf.v4.new_markdown_cell(
|
365 |
-
"""
|
366 |
""")
|
367 |
|
368 |
code = f"""
|
@@ -379,7 +379,7 @@ torch.cuda.empty_cache()
|
|
379 |
|
380 |
def create_merge_lora_cells(cells: list, output_dir):
|
381 |
text_cell = nbf.v4.new_markdown_cell(
|
382 |
-
"""
|
383 |
|
384 |
While utilizing `LoRA`, we focus on training the adapters rather than the entire model. Consequently, during the
|
385 |
model saving process, only the `adapter weights` are preserved, not the complete model. If we wish to save the
|
@@ -411,7 +411,7 @@ tokenizer.save_pretrained("{output_dir}")
|
|
411 |
|
412 |
def merge_model_cells(cells: list, output_dir):
|
413 |
text_cell = nbf.v4.new_markdown_cell(
|
414 |
-
f"
|
415 |
|
416 |
code = f"""
|
417 |
import os
|
@@ -433,7 +433,7 @@ for item in os.listdir(source_folder):
|
|
433 |
|
434 |
|
435 |
def push_to_hub_cells(cells: list, output_dir):
|
436 |
-
text = f"
|
437 |
code = f"""
|
438 |
from huggingface_hub import HfApi, HfFolder, Repository
|
439 |
|
|
|
37 |
|
38 |
def create_install_flash_attention(cells: list):
|
39 |
text_cell = nbf.v4.new_markdown_cell(
|
40 |
+
"## Installing Flash Attention")
|
41 |
text_cell1 = nbf.v4.new_markdown_cell("Installing Flash Attention to reduce the memory "
|
42 |
"and runtime cost of the attention layer, and improve the performance of "
|
43 |
"the model training. Learn more at [FlashAttention]("
|
|
|
59 |
|
60 |
def create_login_hf_cells(cells: list, should_login: bool = False, model_name: Optional[str] = None):
|
61 |
text_cell = nbf.v4.new_markdown_cell(
|
62 |
+
"## Login to HF")
|
63 |
|
64 |
text_1 = "Login with our `HF_TOKEN` in order to push the finetuned model to `huggingface_hub`."
|
65 |
|
|
|
219 |
|
220 |
|
221 |
def create_lora_config_cells(cells: list, r: int, alpha: int, dropout: float, bias: str):
|
222 |
+
text_cell = nbf.v4.new_markdown_cell("## Setting LoraConfig")
|
223 |
code = f"""
|
224 |
from peft import LoraConfig
|
225 |
|
|
|
249 |
save_strategy, gradient_accumulation_steps, gradient_checkpointing,
|
250 |
learning_rate, max_grad_norm, warmup_ratio, lr_scheduler_type, output_dir,
|
251 |
report_to, seed):
|
252 |
+
text_cell = nbf.v4.new_markdown_cell("## Setting the TrainingArguments")
|
253 |
to_install = None
|
254 |
if report_to == "all":
|
255 |
to_install = "azure_ml comet_ml mlflow tensorboard wandb"
|
|
|
298 |
|
299 |
def create_sft_trainer_cells(cells: list, max_seq_length, packing):
|
300 |
text_cell = nbf.v4.new_markdown_cell(
|
301 |
+
"""## Setting the Supervised Finetuning Trainer (`SFTTrainer`)
|
302 |
|
303 |
This `SFTTrainer` is a wrapper around the `transformers.Trainer` class and inherits all of its attributes and methods.
|
304 |
The trainer takes care of properly initializing the `PeftModel`.
|
|
|
362 |
|
363 |
def create_free_gpu_cells(cells: list):
|
364 |
text_cell = nbf.v4.new_markdown_cell(
|
365 |
+
"""### Free the GPU Memory to Prepare Merging `LoRA` Adapters with the Base Model
|
366 |
""")
|
367 |
|
368 |
code = f"""
|
|
|
379 |
|
380 |
def create_merge_lora_cells(cells: list, output_dir):
|
381 |
text_cell = nbf.v4.new_markdown_cell(
|
382 |
+
"""## Merging LoRa Adapters into the Original Model
|
383 |
|
384 |
While utilizing `LoRA`, we focus on training the adapters rather than the entire model. Consequently, during the
|
385 |
model saving process, only the `adapter weights` are preserved, not the complete model. If we wish to save the
|
|
|
411 |
|
412 |
def merge_model_cells(cells: list, output_dir):
|
413 |
text_cell = nbf.v4.new_markdown_cell(
|
414 |
+
f"### Copy all result folders from 'temp_{output_dir}' to '{output_dir}'")
|
415 |
|
416 |
code = f"""
|
417 |
import os
|
|
|
433 |
|
434 |
|
435 |
def push_to_hub_cells(cells: list, output_dir):
|
436 |
+
text = f"## Pushing '{output_dir}' to our Hugging Face account."
|
437 |
code = f"""
|
438 |
from huggingface_hub import HfApi, HfFolder, Repository
|
439 |
|