Skip to content

Commit

Permalink
add alpaca
Browse files Browse the repository at this point in the history
  • Loading branch information
jianzhnie committed May 25, 2023
1 parent a256bdf commit b754fa5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 63 deletions.
98 changes: 50 additions & 48 deletions examples/alpaca/generate_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def main(args):
args.lora_model_name_or_path,
load_8bit=args.load_8bit)

if not args.load_8bit:
model.half() # seems to fix bugs for some users.
# unwind broken decapoda-research config
model.config.pad_token_id = tokenizer.pad_token_id = 0 # unk
model.config.bos_token_id = 1
Expand Down Expand Up @@ -160,54 +162,54 @@ def generate_with_streaming(**kwargs):
output = tokenizer.decode(s)
yield prompter.get_response(output)

description = 'Alpaca-LoRA is a 7B-parameter LLaMA model finetuned to follow instructions. '
'It is trained on the [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) '
'dataset and makes use of the Huggingface LLaMA implementation. For more information, '
"please visit [the project's website](https://github.com/tloen/alpaca-lora).",

server = gr.Interface(
fn=evaluate,
inputs=[
gr.components.Textbox(lines=2,
label='Instruction',
placeholder='Tell me about alpacas.'),
gr.components.Textbox(lines=2,
label='Input',
placeholder='none'),
gr.components.Slider(minimum=0,
maximum=1,
value=0.1,
label='Temperature'),
gr.components.Slider(minimum=0,
maximum=1,
value=0.75,
label='Top p'),
gr.components.Slider(minimum=0,
maximum=100,
step=1,
value=40,
label='Top k'),
gr.components.Slider(minimum=1,
maximum=4,
step=1,
value=4,
label='Beams'),
gr.components.Slider(minimum=1,
maximum=2000,
step=1,
value=128,
label='Max tokens'),
gr.components.Checkbox(label='Stream output'),
],
outputs=[gr.inputs.Textbox(
lines=5,
label='Output',
)],
title='🦙🌲 Alpaca-LoRA',
description=description,
)

server.queue().launch(server_name='0.0.0.0', share=False)
description = 'Alpaca-LoRA is a 7B-parameter LLaMA model finetuned to follow instructions. '
'It is trained on the [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) '
'dataset and makes use of the Huggingface LLaMA implementation. For more information, '
"please visit [the project's website](https://github.com/tloen/alpaca-lora).",

server = gr.Interface(
fn=evaluate,
inputs=[
gr.components.Textbox(lines=2,
label='Instruction',
placeholder='Tell me about alpacas.'),
gr.components.Textbox(lines=2,
label='Input',
placeholder='none'),
gr.components.Slider(minimum=0,
maximum=1,
value=0.1,
label='Temperature'),
gr.components.Slider(minimum=0,
maximum=1,
value=0.75,
label='Top p'),
gr.components.Slider(minimum=0,
maximum=100,
step=1,
value=40,
label='Top k'),
gr.components.Slider(minimum=1,
maximum=4,
step=1,
value=4,
label='Beams'),
gr.components.Slider(minimum=1,
maximum=2000,
step=1,
value=128,
label='Max tokens'),
gr.components.Checkbox(label='Stream output'),
],
outputs=[gr.inputs.Textbox(
lines=5,
label='Output',
)],
title='🦙🌲 Alpaca-LoRA',
description=description,
)

server.queue().launch(server_name='0.0.0.0', share=False)


if __name__ == '__main__':
Expand Down
5 changes: 5 additions & 0 deletions examples/alpaca/infer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ python generate_server.py \
--model_name_or_path decapoda-research/llama-7b-hf \
--lora_model_name_or_path tloen/alpaca-lora-7b \
--load_8bit

python generate_server.py \
--model_name_or_path decapoda-research/llama-7b-hf \
--lora_model_name_or_path ./work_dir_lora \
--load_8bit
12 changes: 1 addition & 11 deletions examples/alpaca/run.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
nohup sh scripts/run_alpaca_ds.sh > run2.log 2>&1 &
nohup sh scripts/run_alpaca_lora.sh > run2.log 2>&1 &


python generate.py \
--model_name_or_path decapoda-research/llama-7b-hf \
--lora_model_name_or_path \
--temperature 1.0 \
--repetition_penalty 1.0 \
--top_k 40 \
--top_p 0.9 \
--num_beams 4 \
nohup sh scripts/run_alpaca_lora.sh > run2.log 2>&1 &
8 changes: 5 additions & 3 deletions examples/alpaca/scripts/run_alpaca_lora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ python train_alpaca_lora.py \
--gradient_accumulation_steps 8 \
--evaluation_strategy "no" \
--save_strategy "steps" \
--save_steps 2000 \
--save_steps 500 \
--save_total_limit 5 \
--learning_rate 2e-5 \
--learning_rate 1e-4 \
--weight_decay 0. \
--warmup_ratio 0.03 \
--lr_scheduler_type "cosine" \
--logging_steps 1
--model_max_length 2048 \
--logging_steps 1 \
--fp16 True
2 changes: 1 addition & 1 deletion examples/alpaca/train_alpaca_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,4 @@ def train(load_in_8bit=False) -> None:


if __name__ == '__main__':
train()
train(load_in_8bit=True)

0 comments on commit b754fa5

Please sign in to comment.