aurora

Форк
0
69 строк · 2.4 Кб
1
import gradio as gr
2
from typing import TYPE_CHECKING, Dict
3

4
from llmtuner.data.template import templates
5
from llmtuner.extras.constants import METHODS, SUPPORTED_MODELS
6
from llmtuner.webui.common import get_model_path, get_template, list_checkpoint, save_config
7
from llmtuner.webui.utils import can_quantize
8

9
if TYPE_CHECKING:
10
    from gradio.components import Component
11

12

13
def create_top() -> Dict[str, "Component"]:
14
    available_models = list(SUPPORTED_MODELS.keys()) + ["Custom"]
15

16
    with gr.Row():
17
        lang = gr.Dropdown(choices=["en", "zh"], scale=1)
18
        model_name = gr.Dropdown(choices=available_models, scale=3)
19
        model_path = gr.Textbox(scale=3)
20

21
    with gr.Row():
22
        finetuning_type = gr.Dropdown(choices=METHODS, value="lora", scale=1)
23
        checkpoints = gr.Dropdown(multiselect=True, scale=5)
24
        refresh_btn = gr.Button(scale=1)
25

26
    with gr.Accordion(label="Advanced config", open=False) as advanced_tab:
27
        with gr.Row():
28
            quantization_bit = gr.Dropdown(choices=["none", "8", "4"], value="none")
29
            template = gr.Dropdown(choices=list(templates.keys()), value="default")
30
            rope_scaling = gr.Radio(choices=["none", "linear", "dynamic"], value="none")
31

32
            with gr.Column():
33
                flash_attn = gr.Checkbox(value=False)
34
                shift_attn = gr.Checkbox(value=False)
35

36
    model_name.change(
37
        list_checkpoint, [model_name, finetuning_type], [checkpoints], queue=False
38
    ).then(
39
        get_model_path, [model_name], [model_path], queue=False
40
    ).then(
41
        get_template, [model_name], [template], queue=False
42
    ) # do not save config since the below line will save
43

44
    model_path.change(save_config, inputs=[lang, model_name, model_path], queue=False)
45

46
    finetuning_type.change(
47
        list_checkpoint, [model_name, finetuning_type], [checkpoints], queue=False
48
    ).then(
49
        can_quantize, [finetuning_type], [quantization_bit], queue=False
50
    )
51

52
    refresh_btn.click(
53
        list_checkpoint, [model_name, finetuning_type], [checkpoints], queue=False
54
    )
55

56
    return dict(
57
        lang=lang,
58
        model_name=model_name,
59
        model_path=model_path,
60
        finetuning_type=finetuning_type,
61
        checkpoints=checkpoints,
62
        refresh_btn=refresh_btn,
63
        advanced_tab=advanced_tab,
64
        quantization_bit=quantization_bit,
65
        template=template,
66
        rope_scaling=rope_scaling,
67
        flash_attn=flash_attn,
68
        shift_attn=shift_attn
69
    )
70

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.