Package: lmflow-evaluator
LMFlowEnglish|简体中文|Español|日本語|한국어|हिंदीAn extensible, convenient, and efficient toolbox for finetuning large machine learning models, designed to be user-friendly, speedy and reliable, and accessible to the entire community.Large Model for All. See ourvision.Latest News[2023-05-15] :rocket: ReleaseLMFlow-data, the training dataset of Robin-7B-v2. A newtest datais also released. :rocket:[2023-05-09] :rocket: ReleaseRobin-7B-v2, achieving competitive performance on chitchat, commonsense reasoning and instruction-following tasks. Refer to ourcomprehensive study. :rocket:[2023-05-08] :rocket: ReleaseLMFlow Benchmark, an automatic evaluation framework for open-source chat-style LLMs.Benchmark resultson 31 popular models are reported.Participate in LMFlow Benchmark. :rocket:[2023-04-21] ReleaseRobin-7B(based on LLaMA-7B), and two models for commercial use: Parakeets-2.7B (based on GPT-NEO-2.7B) and Cokatoo-7B (based on StableLM-7B)Download here[2023-04-15] Inference: Support streaming output and ChatGLM.[2023-04-10]We propose a new alignment algorithm: Reward rAnked FineTuning (RAFT), which is more efficient than conventional (PPO-based) RLHF. The movie review demo are available now.[Paper][2023-04-02]Web serviceis online![2023-04-01] Release three instruction-tuned checkpoints and three medical checkpoints in model zoo:LLaMA-7B-tuned, LLaMA-13B-tuned, LLaMA-33B-tuned, LLaMA-7B-medical, LLaMA-13B-medical, and LLaMA-33B-medical.[2023-03-27] Release code and checkpoints -version 0.0.1!Our tasked-tuned model beats ChatGPT on medical domain.DemosWe provide four kinds of demos which includeOnline Service: If you don't want to run any code and just want to try our models, we deploy our instruction-tuned LLaMA you to have a try.Colab Chatbot (shell): An interactive shell-based chatbot for you to easily deploy a chatbot on colab.Colab Chatbot (web): An interactive web-based chatbot for you to easily deploy your own chatbot on colab.Local Deploy: We also provide a way for you to deploy your model/chatbot locally, which means you can deploy much larger model than previous three methods if you have enough resource.Online ServiceWelcome to visit ourweb service. We deploy LLaMA-7B-tuned model online for preview. Due to the high website traffic, sometimes the website may fail to respond. You can also deploy the chatbot followingLocal Deploy.Colab chatbot (shell)We provide a simple shell demo of chatbot with Google Colab's T4/P100/V100 GPU.
Notice that the provided gpt-neo-2.7b model isa rather weak model, which only supports English and may sometimes generate
unsatisfactory responses. To improve the performance, users can use their own
dataset to finetune and obtain a better model with LMFlow. One can also try
other available decoder-only models provided in
🤗Hugging Face, by./scripts/run_chatbot.sh{another-model-name}Colab chatbot (web)We provide a simple web demo of chatbot with Google Colab's T4/P100/V100 GPU.
Notice that the provided gpt-neo-2.7b model isa rather weak model, which only supports English and may sometimes generate
unsatisfactory responses.Local DeployIf you have resources and want to deploy your own model locally. We provide you an easy way to run a flask server to launch a backend (to further provide services to other frontend) and an interactive web frontend (to let you communicate directly) by./scripts/run_app.shWe also provide a gradio-based UI for building chatbots. Running the following command will launch the demo for robin-7b:pipinstallgradio
python./examples/chatbot_gradio.py--deepspeedconfigs/ds_config_chatbot.json--model_name_or_pathYOUR-LLAMA--lora_model_path./robin-7b--prompt_structure"A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.###Human: {input_text}###Assistant:"--end_string"#"--max_new_tokens200We also hosted it on Hugging FaceSpace.Colab RAFT-diffusionWe also provide a simple demo to display the effectiveness of RAFT algorithm on diffusion models.
You can refer to eitherColab linkorexperimental/RAFT-diffusion/SD256-RAFT.ipynb.
The support of multi-modal training of LMFlow is under development.Medical PerformancePubMedQA (ID)MedQA-USMLE (OOD)MedMCQA (ID)AverageHuman (pass)60.050.0Human (expert)78.087.090.085.0InstructGPT 175B73.246.044.054.4ChatGPT63.957.044.755.2LLaMA 7B5.227.124.318.9LLaMA 33B1.843.430.325.2Task-tuned LLaMA 7B (Full)75.144.549.956.5Task-tuned LLaMA 33B (LoRA)74.051.350.258.5The LLaMA 33B (LoRA) performance is achieved with only~16hfinetuning on the training split of PubMedQA and MedMCQA with a single 8 * A100 server.
For more performance, including instruction tuning results, please refer to ourDocumentation.Model ZooWe open-sourced the trained checkpoints to everyone for further training and inference.ModelBase ModelRobin-7B :star:LLaMA-7BRobin-13BLLaMA-13BRobin-33BLLaMA-33BRobin-65BLLaMA-65BModelBase ModelRobin-7B-medicalLLaMA-7BRobin-13B-medicalLLaMA-13BRobin-33B-medicalLLaMA-33BRobin-65B-medicalLLaMA-65BModelBase ModelParakeets-2.7B :star:GPT-NEO-2.7BCockatoo-3BStableLM-3BCockatoo-7B :star:StableLM-7BSupported PipelinesPipelinesStatusTask Tuning:white_check_mark: SupportedInstruction Tuning:white_check_mark: SupportedParameter-Efficient Tuning:white_check_mark: SupportedAlignment Tuning:white_check_mark: SupportedLarge Model Inference:white_check_mark: SupportedSupported ModelsSeamlessly supported all thedecoder modelsin 🤗 Hugging Face.
LLaMA, GPT2, GPT-Neo, Galactica, have been fully tested. We will support encoder models soon.1.SetupOur package has been fully tested on Linux OS (Ubuntu 20.04). Other OS platforms (MacOS, Windows) are not fully tested.
You may encounter some unexpected errors. You may try it first on a Linux machine or use Google Colab to experience it.gitclonehttps://github.com/OptimalScale/LMFlow.gitcdLMFlow
condacreate-nlmflowpython=3.9-y
condaactivatelmflow
condainstallmpi4py
pipinstall-e.2.Prepare DatasetPlease refer to ourdoc.3. Running Scripts3.1 FinetuningYou can runscripts/run_finetune.shto finetune a GPT-2 base model./scripts/run_finetune.shIf you would like to provide arguments for deepspeed to reflect your machine
settings, you may pass the corresponding deepspeed arguments to the script. For
example,./scripts/run_finetune.sh"--num_gpus=8 --master_port 10001"To enable LoRA finetuning, you may refer to./scripts/run_finetune_with_lora.shwhich can be run in similar manner.For detailed configurations, one may modify these scripts directly. These
scripts actually just call python scriptexamples/finetune.py, which can
be run in following manner,deepspeed${deepspeed_args}\examples/finetune.py\--deepspeedconfigs/ds_config_zero3.json\--bf16\--run_namefinetune_with_lora\--model_name_or_pathfacebook/galactica-1.3b\--num_train_epochs0.01\--learning_rate2e-5\--dataset_path${dataset_path}\--per_device_train_batch_size1\--per_device_eval_batch_size1\--validation_split_percentage0\--logging_steps20\--block_size512\--do_train\--output_diroutput_models/finetune\--overwrite_output_dir\--ddp_timeout72000\--save_steps5000\--dataloader_num_workers1Here we set number of epochs--num_train_epochsto0.01so that the
finetuning process can be finished quickly. If you wish to obtain a model with
better performance, feel free to adjust those hyperparameters. You may runpythonexamples/finetune.py-hto view all possible finetuning arguments. The finetuned model checkpoint will
be saved in the argument specified by--output_dir, which isoutput_models/finetunein the above example.
We followAlpacaandVicunain the model tuning process and serve the model in our web service.3.2 EvaluationOne can directly run evaluation with an existing Hugging Face model, e.g. to run
GPT2 large, one may execute./scripts/run_evaluation.shor run the corresponding python scriptCUDA_VISIBLE_DEVICES=0\deepspeedexamples/evaluate.py\--answer_typemedmcqa\--model_name_or_pathgpt2-large\--dataset_pathdata/MedQA-USMLE/validation\--deepspeedexamples/ds_config.jsonTo load the finetuned model, specify--model_name_or_pathwith the saved
model checkpoint directory path.For LoRA finetuned models, one may refer to./scripts/run_evaluation_with_lora.shThose scripts invoke the examplesexamples/*.pybuilt based on our APIs. For
more API-related examples, one may refer to the methods in the unittesttests.3.3 LMFlow BenchmarkLMFlow Benchmark is an automatic evaluation framework for open-source large language models.
We use negative log likelihood (NLL) as the metric to evaluate different aspects of a language model: chitchat, commonsense reasoning, and instruction following abilities.You can directly run the LMFlow benchmark evaluation to obtain the results to participate in theLLM comparision.
For example, to run GPT2 XL, one may execute./scripts/run_benchmark.sh--model_name_or_pathgpt2-xl--model_name_or_pathis required, you may fill in huggingface model name or local model path here.To check the evaluation results, you may checkbenchmark.login./output_dir/gpt2-xl_lmflow_chat_nll_eval,./output_dir/gpt2-xl_all_nll_evaland./output_dir/gpt2-xl_commonsense_qa_eval.4. Additional Notes4.1 LLaMA CheckpointPlease refer to ourdoc.4.2 DeepSpeed ConfigYou can config the deepspeed under configs. Details can be referred atDeepSpeed Configuration4.3 LLaMA Inference on CPUThanks to the great efforts ofllama.cpp. It is possible for everyone to run their LLaMA models on CPU by 4-bit quantization. We provide a script to convert LLaMA LoRA weights to.ptfiles. You only need to useconvert-pth-to-ggml.pyin llama.cpp to perform quantization.5. Model Release5.1 Medical Model CheckpointsYou can run following script to download our medical model checkpoints :cdoutput_models
bashdownload.shmedical_ckptcd-You can also directly download our model via google drive link :medical_ckpt.tar.gz5.2 Instruction Model CheckpointsSimilarly, you can run following script to download our instruction model checkpoints :cdoutput_models
bashdownload.shinstruction_ckptcd-You can also directly download our model via google drive link :instruction_ckpt.tar.gz5.3 Reproduce the resultAfter downloading the model checkpoints, you can merge the lora model into the base model viapython examples/merge_lora.py \
    --model_name_or_path {huggingface-model-name-or-path-to-base-model} \
    --lora_model_path {path-to-lora-model} \
    --output_model_path {path-to-merged-model}Or you can replace the--lora_model_pathwithoutput_models/instruction_ckpt/llama7b-lora(example for llama-7b for instruction) and replace--model_name_or_pathwith your converted llama model insideLMFlow/scripts/run_evaluation_with_lora.shand run this shell script to reproduce the result.For full model deltas, such as robin-7b-v2-delta, you may use the delta merge script to obtain the full model,python utils/apply_delta.py \
    --base-model-path {huggingface-model-name-or-path-to-base-model} \
    --delta-path {path-to-delta-model} \
    --target-model-path {path-to-merged-model}Then you can check the model performance at ourDoc.DocumentationPlease refer to ourDocumentationfor more API reference and experimental results.VisionHello there! We are excited to announce the upcoming release of our code repository that includes a complete LLM training process, enabling users to quickly build their own language models and train them effectively.Our code repository is not just a simple model; it includes the complete training workflow, model optimization, and testing tools. You can use it to build various types of language models, including conversation models, question-answering models, and text generation models, among others.Moreover, we aim to create an open and democratic LLM sharing platform where people can share their checkpoints and experiences to collectively improve the skills of the community. We welcome anyone who is interested in LLM to participate and join us in building an open and friendly community!Whether you are a beginner or an expert, we believe that you can benefit from this platform. Let's work together to build a vibrant and innovative LLM community!AcknowledgementLMFlow draws inspiration from various studies, including but not limited to:Alpaca:https://github.com/tatsu-lab/stanford_alpacaVicuna:https://github.com/lm-sys/FastChatSupportIf you need any help, please submit aGithubissue.ContributorsCitationIf you find this repository useful, please consider giving ⭐ and citing:@misc{lmflow,
  author = {Shizhe Diao and Rui Pan and Hanze Dong and KaShun Shum and Jipeng Zhang and Wei Xiong and Tong Zhang},
  title = {LMFlow: An Extensible Toolkit for Finetuning and Inference of Large Foundation Models},
  year = {2023},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://optimalscale.github.io/LMFlow/}},
}