File size: 1,798 Bytes
bec0fa2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
import subprocess
import threading
import time

def run_training(model_name, progress=gr.Progress()):
    progress(0, desc="Starting Training...")
    
    command = ["python", "train.py", "--model_name", model_name]
    
    # Start the training process
    process = subprocess.Popen(
        command, 
        stdout=subprocess.PIPE, 
        stderr=subprocess.STDOUT, 
        text=True, 
        bufsize=1, 
        universal_newlines=True
    )

    # Stream the output
    output = ""
    for line in process.stdout:
        output += line
        # Update progress based on keywords in the output
        if "Starting training..." in line:
            progress(0.1, desc="Training Started...")
        elif "loss" in line:
             progress(0.5, desc=line.strip())
        
        yield output
    
    process.wait()
    
    if process.returncode == 0:
        progress(1, desc="Training Complete!")
        yield output + "\nTraining finished successfully!"
    else:
        yield output + f"\nTraining failed with error code {process.returncode}."


with gr.Blocks() as demo:
    gr.Markdown("# Llama Model Fine-Tuning")
    gr.Markdown("Select a model and click 'Start Fine-Tuning' to begin.")

    models = [
        'meta-llama/Meta-Llama-3-8B-Instruct',
        'meta-llama/Meta-Llama-3-70B-Instruct',
        'meta-llama/Llama-3.3-70B-Instruct'
    ]
    model_dropdown = gr.Dropdown(models, label="Select Model to Fine-Tune", value='meta-llama/Meta-Llama-3-8B-Instruct')
    
    start_button = gr.Button("Start Fine-Tuning")
    
    output_textbox = gr.Textbox(label="Training Log", lines=20, interactive=False)
    
    start_button.click(
        fn=run_training,
        inputs=[model_dropdown],
        outputs=[output_textbox]
    )

demo.launch()