DongfuJiang commited on
Commit
bf0e8d1
1 Parent(s): abbe14c
Files changed (1) hide show
  1. app.py +192 -192
app.py CHANGED
@@ -20,11 +20,11 @@ DEFAULT_FUSER_MAX_NEW_TOKENS = 256
20
 
21
 
22
  # MIX-INSTRUCT
23
- EXAMPLES_DATASET = load_dataset("llm-blender/mix-instruct", split='validation')
24
  SHUFFLED_EXAMPLES_DATASET = EXAMPLES_DATASET.shuffle(seed=42)
25
  MIX_INSTRUCT_EXAMPLES = []
26
  CANDIDATE_MAP = {}
27
- for i, example in enumerate(SHUFFLED_EXAMPLES_DATASET):
28
  MIX_INSTRUCT_EXAMPLES.append([
29
  example['instruction'],
30
  example['input'],
@@ -88,7 +88,7 @@ def get_mt_bench_human_judge_examples(model_a, model_b, conversation_a, conversa
88
 
89
  blender = llm_blender.Blender()
90
  blender.loadranker("llm-blender/PairRM")
91
- blender.loadfuser("llm-blender/gen_fuser_3b")
92
 
93
  def update_base_llms_num(k, llm_outputs):
94
  k = int(k)
@@ -214,9 +214,9 @@ with gr.Blocks(theme='ParityError/Anime') as demo:
214
  outputs=[compare_result, compare_result_prob],
215
  )
216
  clear_button.click(
217
- fn=lambda: ["", ""],
218
  inputs=[],
219
- outputs=[compare_result, compare_result_prob],
220
  )
221
 
222
  hhh_dummy_textbox1 = gr.Textbox(lines=1, label="subset", placeholder="", show_label=False, visible=False)
@@ -328,207 +328,207 @@ with gr.Blocks(theme='ParityError/Anime') as demo:
328
  )
329
 
330
 
331
- with gr.Tab("LLM-Blender"):
332
- # llm-blender interface
333
- with gr.Row():
334
- gr.Markdown(descriptions.LLM_BLENDER_OVERALL_DESC)
335
- gr.Image("https://github.com/yuchenlin/LLM-Blender/blob/main/docs/llm_blender.png?raw=true", height=300)
336
- gr.Markdown("## Input and Base LLMs")
337
- with gr.Row():
338
- with gr.Column():
339
- inst_textbox = gr.Textbox(lines=1, label="Instruction", placeholder="Enter instruction here", show_label=True)
340
- input_textbox = gr.Textbox(lines=4, label="Input Context", placeholder="Enter input context here", show_label=True)
341
- with gr.Column():
342
- saved_llm_outputs = gr.State(value={})
343
- with gr.Group():
344
- selected_base_llm_name_dropdown = gr.Dropdown(label="Base LLM",
345
- choices=[f"LLM-{i+1}" for i in range(MIN_BASE_LLM_NUM)], value="LLM-1", show_label=True)
346
- selected_base_llm_output = gr.Textbox(lines=4, label="LLM-1 (Click Save to save current content)",
347
- placeholder="Enter LLM-1 output here", show_label=True)
348
- with gr.Row():
349
- base_llm_outputs_save_button = gr.Button('Save', variant='primary')
350
 
351
- base_llm_outputs_clear_single_button = gr.Button('Clear Single', variant='primary')
352
 
353
- base_llm_outputs_clear_all_button = gr.Button('Clear All', variant='primary')
354
- base_llms_num = gr.Slider(
355
- label='Number of base llms',
356
- minimum=MIN_BASE_LLM_NUM,
357
- maximum=MAX_BASE_LLM_NUM,
358
- step=1,
359
- value=MIN_BASE_LLM_NUM,
360
- )
361
 
362
- blender_state = gr.State(value={})
363
- saved_rank_outputs = gr.State(value=[])
364
- saved_fuse_outputs = gr.State(value=[])
365
- gr.Markdown("## Blender Outputs")
366
- with gr.Group():
367
- rank_outputs = gr.Textbox(lines=1, label="Ranking outputs", placeholder="Ranking outputs", show_label=True)
368
- fuser_outputs = gr.Textbox(lines=4, label="Fusing outputs", placeholder="Fusing outputs", show_label=True)
369
- with gr.Row():
370
- rank_button = gr.Button('Rank LLM Outputs', variant='primary')
371
- fuse_button = gr.Button('Fuse Top-K ranked outputs', variant='primary')
372
- clear_button = gr.Button('Clear Blender Outputs', variant='primary')
373
- blender_config = gr.State(value={
374
- "source_max_length": DEFAULT_SOURCE_MAX_LENGTH,
375
- "candidate_max_length": DEFAULT_CANDIDATE_MAX_LENGTH,
376
- "top_k_for_fuser": 3,
377
- "max_new_tokens": DEFAULT_FUSER_MAX_NEW_TOKENS,
378
- "temperature": 0.7,
379
- "top_p": 1.0,
380
- })
381
 
382
- with gr.Accordion(label='Advanced options', open=False):
383
- source_max_length = gr.Slider(
384
- label='Max length of Instruction + Input',
385
- minimum=1,
386
- maximum=SOURCE_MAX_LENGTH,
387
- step=1,
388
- value=DEFAULT_SOURCE_MAX_LENGTH,
389
- )
390
- candidate_max_length = gr.Slider(
391
- label='Max length of LLM-Output Candidate',
392
- minimum=1,
393
- maximum=CANDIDATE_MAX_LENGTH,
394
- step=1,
395
- value=DEFAULT_CANDIDATE_MAX_LENGTH,
396
- )
397
- top_k_for_fuser = gr.Slider(
398
- label='Top-k ranked candidates to fuse',
399
- minimum=1,
400
- maximum=3,
401
- step=1,
402
- value=3,
403
- )
404
- max_new_tokens = gr.Slider(
405
- label='Max new tokens fuser can generate',
406
- minimum=1,
407
- maximum=FUSER_MAX_NEW_TOKENS,
408
- step=1,
409
- value=DEFAULT_FUSER_MAX_NEW_TOKENS,
410
- )
411
- temperature = gr.Slider(
412
- label='Temperature of fuser generation',
413
- minimum=0.1,
414
- maximum=2.0,
415
- step=0.1,
416
- value=0.7,
417
- )
418
- top_p = gr.Slider(
419
- label='Top-p of fuser generation',
420
- minimum=0.05,
421
- maximum=1.0,
422
- step=0.05,
423
- value=1.0,
424
- )
425
 
426
- examples_dummy_textbox = gr.Textbox(lines=1, label="", placeholder="", show_label=False, visible=False)
427
- batch_examples = gr.Examples(
428
- examples=MIX_INSTRUCT_EXAMPLES,
429
- fn=get_preprocess_examples,
430
- cache_examples=True,
431
- examples_per_page=5,
432
- inputs=[inst_textbox, input_textbox],
433
- outputs=[inst_textbox, input_textbox, base_llms_num, examples_dummy_textbox],
434
- )
435
 
436
- base_llms_num.input(
437
- fn=update_base_llms_num,
438
- inputs=[base_llms_num, saved_llm_outputs],
439
- outputs=[selected_base_llm_name_dropdown, saved_llm_outputs],
440
- )
441
 
442
- examples_dummy_textbox.change(
443
- fn=update_base_llm_dropdown_along_examples,
444
- inputs=[inst_textbox, input_textbox],
445
- outputs=[saved_llm_outputs, rank_outputs, fuser_outputs, selected_base_llm_name_dropdown],
446
- ).then(
447
- fn=display_llm_output,
448
- inputs=[saved_llm_outputs, selected_base_llm_name_dropdown],
449
- outputs=selected_base_llm_output,
450
- )
451
 
452
- selected_base_llm_name_dropdown.change(
453
- fn=display_llm_output,
454
- inputs=[saved_llm_outputs, selected_base_llm_name_dropdown],
455
- outputs=selected_base_llm_output,
456
- )
457
 
458
- base_llm_outputs_save_button.click(
459
- fn=save_llm_output,
460
- inputs=[selected_base_llm_name_dropdown, selected_base_llm_output, saved_llm_outputs],
461
- outputs=saved_llm_outputs,
462
- )
463
- base_llm_outputs_clear_all_button.click(
464
- fn=lambda: [{}, ""],
465
- inputs=[],
466
- outputs=[saved_llm_outputs, selected_base_llm_output],
467
- )
468
- base_llm_outputs_clear_single_button.click(
469
- fn=lambda: "",
470
- inputs=[],
471
- outputs=selected_base_llm_output,
472
- )
473
 
474
 
475
- rank_button.click(
476
- fn=check_save_ranker_inputs,
477
- inputs=[inst_textbox, input_textbox, saved_llm_outputs, blender_config],
478
- outputs=blender_state,
479
- ).success(
480
- fn=llms_rank,
481
- inputs=[inst_textbox, input_textbox, saved_llm_outputs, blender_config],
482
- outputs=[saved_rank_outputs, rank_outputs],
483
- )
484
 
485
- fuse_button.click(
486
- fn=check_fuser_inputs,
487
- inputs=[blender_state, blender_config, saved_rank_outputs],
488
- outputs=[],
489
- ).success(
490
- fn=llms_fuse,
491
- inputs=[blender_state, blender_config, saved_rank_outputs],
492
- outputs=[saved_fuse_outputs, fuser_outputs],
493
- )
494
 
495
- clear_button.click(
496
- fn=lambda: ["", "", {}, []],
497
- inputs=[],
498
- outputs=[rank_outputs, fuser_outputs, blender_state, saved_rank_outputs],
499
- )
500
 
501
- # update blender config
502
- source_max_length.change(
503
- fn=lambda x, y: y.update({"source_max_length": x}) or y,
504
- inputs=[source_max_length, blender_config],
505
- outputs=blender_config,
506
- )
507
- candidate_max_length.change(
508
- fn=lambda x, y: y.update({"candidate_max_length": x}) or y,
509
- inputs=[candidate_max_length, blender_config],
510
- outputs=blender_config,
511
- )
512
- top_k_for_fuser.change(
513
- fn=lambda x, y: y.update({"top_k_for_fuser": x}) or y,
514
- inputs=[top_k_for_fuser, blender_config],
515
- outputs=blender_config,
516
- )
517
- max_new_tokens.change(
518
- fn=lambda x, y: y.update({"max_new_tokens": x}) or y,
519
- inputs=[max_new_tokens, blender_config],
520
- outputs=blender_config,
521
- )
522
- temperature.change(
523
- fn=lambda x, y: y.update({"temperature": x}) or y,
524
- inputs=[temperature, blender_config],
525
- outputs=blender_config,
526
- )
527
- top_p.change(
528
- fn=lambda x, y: y.update({"top_p": x}) or y,
529
- inputs=[top_p, blender_config],
530
- outputs=blender_config,
531
- )
532
 
533
 
534
 
 
20
 
21
 
22
  # MIX-INSTRUCT
23
+ EXAMPLES_DATASET = load_dataset("llm-blender/mix-instruct", split='validation', streaming=True)
24
  SHUFFLED_EXAMPLES_DATASET = EXAMPLES_DATASET.shuffle(seed=42)
25
  MIX_INSTRUCT_EXAMPLES = []
26
  CANDIDATE_MAP = {}
27
+ for i, example in enumerate(SHUFFLED_EXAMPLES_DATASET.take(100)):
28
  MIX_INSTRUCT_EXAMPLES.append([
29
  example['instruction'],
30
  example['input'],
 
88
 
89
  blender = llm_blender.Blender()
90
  blender.loadranker("llm-blender/PairRM")
91
+ # blender.loadfuser("llm-blender/gen_fuser_3b")
92
 
93
  def update_base_llms_num(k, llm_outputs):
94
  k = int(k)
 
214
  outputs=[compare_result, compare_result_prob],
215
  )
216
  clear_button.click(
217
+ fn=lambda: ["", "", "", "", ""],
218
  inputs=[],
219
+ outputs=[instruction, response1, response2, compare_result, compare_result_prob],
220
  )
221
 
222
  hhh_dummy_textbox1 = gr.Textbox(lines=1, label="subset", placeholder="", show_label=False, visible=False)
 
328
  )
329
 
330
 
331
+ # with gr.Tab("LLM-Blender"):
332
+ # # llm-blender interface
333
+ # with gr.Row():
334
+ # gr.Markdown(descriptions.LLM_BLENDER_OVERALL_DESC)
335
+ # gr.Image("https://github.com/yuchenlin/LLM-Blender/blob/main/docs/llm_blender.png?raw=true", height=300)
336
+ # gr.Markdown("## Input and Base LLMs")
337
+ # with gr.Row():
338
+ # with gr.Column():
339
+ # inst_textbox = gr.Textbox(lines=1, label="Instruction", placeholder="Enter instruction here", show_label=True)
340
+ # input_textbox = gr.Textbox(lines=4, label="Input Context", placeholder="Enter input context here", show_label=True)
341
+ # with gr.Column():
342
+ # saved_llm_outputs = gr.State(value={})
343
+ # with gr.Group():
344
+ # selected_base_llm_name_dropdown = gr.Dropdown(label="Base LLM",
345
+ # choices=[f"LLM-{i+1}" for i in range(MIN_BASE_LLM_NUM)], value="LLM-1", show_label=True)
346
+ # selected_base_llm_output = gr.Textbox(lines=4, label="LLM-1 (Click Save to save current content)",
347
+ # placeholder="Enter LLM-1 output here", show_label=True)
348
+ # with gr.Row():
349
+ # base_llm_outputs_save_button = gr.Button('Save', variant='primary')
350
 
351
+ # base_llm_outputs_clear_single_button = gr.Button('Clear Single', variant='primary')
352
 
353
+ # base_llm_outputs_clear_all_button = gr.Button('Clear All', variant='primary')
354
+ # base_llms_num = gr.Slider(
355
+ # label='Number of base llms',
356
+ # minimum=MIN_BASE_LLM_NUM,
357
+ # maximum=MAX_BASE_LLM_NUM,
358
+ # step=1,
359
+ # value=MIN_BASE_LLM_NUM,
360
+ # )
361
 
362
+ # blender_state = gr.State(value={})
363
+ # saved_rank_outputs = gr.State(value=[])
364
+ # saved_fuse_outputs = gr.State(value=[])
365
+ # gr.Markdown("## Blender Outputs")
366
+ # with gr.Group():
367
+ # rank_outputs = gr.Textbox(lines=1, label="Ranking outputs", placeholder="Ranking outputs", show_label=True)
368
+ # fuser_outputs = gr.Textbox(lines=4, label="Fusing outputs", placeholder="Fusing outputs", show_label=True)
369
+ # with gr.Row():
370
+ # rank_button = gr.Button('Rank LLM Outputs', variant='primary')
371
+ # fuse_button = gr.Button('Fuse Top-K ranked outputs', variant='primary')
372
+ # clear_button = gr.Button('Clear Blender Outputs', variant='primary')
373
+ # blender_config = gr.State(value={
374
+ # "source_max_length": DEFAULT_SOURCE_MAX_LENGTH,
375
+ # "candidate_max_length": DEFAULT_CANDIDATE_MAX_LENGTH,
376
+ # "top_k_for_fuser": 3,
377
+ # "max_new_tokens": DEFAULT_FUSER_MAX_NEW_TOKENS,
378
+ # "temperature": 0.7,
379
+ # "top_p": 1.0,
380
+ # })
381
 
382
+ # with gr.Accordion(label='Advanced options', open=False):
383
+ # source_max_length = gr.Slider(
384
+ # label='Max length of Instruction + Input',
385
+ # minimum=1,
386
+ # maximum=SOURCE_MAX_LENGTH,
387
+ # step=1,
388
+ # value=DEFAULT_SOURCE_MAX_LENGTH,
389
+ # )
390
+ # candidate_max_length = gr.Slider(
391
+ # label='Max length of LLM-Output Candidate',
392
+ # minimum=1,
393
+ # maximum=CANDIDATE_MAX_LENGTH,
394
+ # step=1,
395
+ # value=DEFAULT_CANDIDATE_MAX_LENGTH,
396
+ # )
397
+ # top_k_for_fuser = gr.Slider(
398
+ # label='Top-k ranked candidates to fuse',
399
+ # minimum=1,
400
+ # maximum=3,
401
+ # step=1,
402
+ # value=3,
403
+ # )
404
+ # max_new_tokens = gr.Slider(
405
+ # label='Max new tokens fuser can generate',
406
+ # minimum=1,
407
+ # maximum=FUSER_MAX_NEW_TOKENS,
408
+ # step=1,
409
+ # value=DEFAULT_FUSER_MAX_NEW_TOKENS,
410
+ # )
411
+ # temperature = gr.Slider(
412
+ # label='Temperature of fuser generation',
413
+ # minimum=0.1,
414
+ # maximum=2.0,
415
+ # step=0.1,
416
+ # value=0.7,
417
+ # )
418
+ # top_p = gr.Slider(
419
+ # label='Top-p of fuser generation',
420
+ # minimum=0.05,
421
+ # maximum=1.0,
422
+ # step=0.05,
423
+ # value=1.0,
424
+ # )
425
 
426
+ # examples_dummy_textbox = gr.Textbox(lines=1, label="", placeholder="", show_label=False, visible=False)
427
+ # batch_examples = gr.Examples(
428
+ # examples=MIX_INSTRUCT_EXAMPLES,
429
+ # fn=get_preprocess_examples,
430
+ # cache_examples=True,
431
+ # examples_per_page=5,
432
+ # inputs=[inst_textbox, input_textbox],
433
+ # outputs=[inst_textbox, input_textbox, base_llms_num, examples_dummy_textbox],
434
+ # )
435
 
436
+ # base_llms_num.input(
437
+ # fn=update_base_llms_num,
438
+ # inputs=[base_llms_num, saved_llm_outputs],
439
+ # outputs=[selected_base_llm_name_dropdown, saved_llm_outputs],
440
+ # )
441
 
442
+ # examples_dummy_textbox.change(
443
+ # fn=update_base_llm_dropdown_along_examples,
444
+ # inputs=[inst_textbox, input_textbox],
445
+ # outputs=[saved_llm_outputs, rank_outputs, fuser_outputs, selected_base_llm_name_dropdown],
446
+ # ).then(
447
+ # fn=display_llm_output,
448
+ # inputs=[saved_llm_outputs, selected_base_llm_name_dropdown],
449
+ # outputs=selected_base_llm_output,
450
+ # )
451
 
452
+ # selected_base_llm_name_dropdown.change(
453
+ # fn=display_llm_output,
454
+ # inputs=[saved_llm_outputs, selected_base_llm_name_dropdown],
455
+ # outputs=selected_base_llm_output,
456
+ # )
457
 
458
+ # base_llm_outputs_save_button.click(
459
+ # fn=save_llm_output,
460
+ # inputs=[selected_base_llm_name_dropdown, selected_base_llm_output, saved_llm_outputs],
461
+ # outputs=saved_llm_outputs,
462
+ # )
463
+ # base_llm_outputs_clear_all_button.click(
464
+ # fn=lambda: [{}, ""],
465
+ # inputs=[],
466
+ # outputs=[saved_llm_outputs, selected_base_llm_output],
467
+ # )
468
+ # base_llm_outputs_clear_single_button.click(
469
+ # fn=lambda: "",
470
+ # inputs=[],
471
+ # outputs=selected_base_llm_output,
472
+ # )
473
 
474
 
475
+ # rank_button.click(
476
+ # fn=check_save_ranker_inputs,
477
+ # inputs=[inst_textbox, input_textbox, saved_llm_outputs, blender_config],
478
+ # outputs=blender_state,
479
+ # ).success(
480
+ # fn=llms_rank,
481
+ # inputs=[inst_textbox, input_textbox, saved_llm_outputs, blender_config],
482
+ # outputs=[saved_rank_outputs, rank_outputs],
483
+ # )
484
 
485
+ # fuse_button.click(
486
+ # fn=check_fuser_inputs,
487
+ # inputs=[blender_state, blender_config, saved_rank_outputs],
488
+ # outputs=[],
489
+ # ).success(
490
+ # fn=llms_fuse,
491
+ # inputs=[blender_state, blender_config, saved_rank_outputs],
492
+ # outputs=[saved_fuse_outputs, fuser_outputs],
493
+ # )
494
 
495
+ # clear_button.click(
496
+ # fn=lambda: ["", "", {}, []],
497
+ # inputs=[],
498
+ # outputs=[rank_outputs, fuser_outputs, blender_state, saved_rank_outputs],
499
+ # )
500
 
501
+ # # update blender config
502
+ # source_max_length.change(
503
+ # fn=lambda x, y: y.update({"source_max_length": x}) or y,
504
+ # inputs=[source_max_length, blender_config],
505
+ # outputs=blender_config,
506
+ # )
507
+ # candidate_max_length.change(
508
+ # fn=lambda x, y: y.update({"candidate_max_length": x}) or y,
509
+ # inputs=[candidate_max_length, blender_config],
510
+ # outputs=blender_config,
511
+ # )
512
+ # top_k_for_fuser.change(
513
+ # fn=lambda x, y: y.update({"top_k_for_fuser": x}) or y,
514
+ # inputs=[top_k_for_fuser, blender_config],
515
+ # outputs=blender_config,
516
+ # )
517
+ # max_new_tokens.change(
518
+ # fn=lambda x, y: y.update({"max_new_tokens": x}) or y,
519
+ # inputs=[max_new_tokens, blender_config],
520
+ # outputs=blender_config,
521
+ # )
522
+ # temperature.change(
523
+ # fn=lambda x, y: y.update({"temperature": x}) or y,
524
+ # inputs=[temperature, blender_config],
525
+ # outputs=blender_config,
526
+ # )
527
+ # top_p.change(
528
+ # fn=lambda x, y: y.update({"top_p": x}) or y,
529
+ # inputs=[top_p, blender_config],
530
+ # outputs=blender_config,
531
+ # )
532
 
533
 
534