首页 > 其他分享 >An Introductory Guide to Fine-Tuning LLMs

An Introductory Guide to Fine-Tuning LLMs

时间:2024-08-03 10:55:17浏览次数:16  
标签:tuning Qwen LLMs fine Introductory -- models model Fine

An Introductory Guide to Fine-Tuning LLMs

https://www.datacamp.com/tutorial/fine-tuning-large-language-models

Fine-tuning Large Language Models (LLMs) has revolutionized Natural Language Processing (NLP), offering unprecedented capabilities in tasks like language translation, sentiment analysis, and text generation. This transformative approach leverages pre-trained models like GPT-2, enhancing their performance on specific domains through the fine-tuning process.

 

Over the last year and a half, the field of natural language processing (NLP) has undergone a significant transformation due to the popularization of Large Language Models (LLMs). The natural language skills that these models present have allowed applications that seemed impossible to achieve a few years ago.

LLMs are pushing the boundaries of what was previously considered achievable with capabilities ranging from language translation to sentiment analysis and text generation.

However, we all know training such models is time-consuming and expensive. This is why, fine-tuning large language models is important for tailoring these advanced algorithms to specific tasks or domains.

This process enhances the model's performance on specialized tasks and significantly broadens its applicability across various fields. This means we can take advantage of the Natural Language Processing capacity of pre-trained LLMs and further train them to perform our specific tasks.

Today, explore the essence of pre-trained language models and further delve into the fine-tuning process.

So, let’s navigate through practical steps for fine-tuning a model like GPT-2 using Hugging Face.

 

Fine-tuning vs. RAG

RAG combines the strengths of retrieval-based models and generative models. In RAG, a retriever component searches a large database or knowledge base to find relevant information based on the input query. This retrieved information is then used by a generative model to produce a more accurate and contextually relevant response. Key benefits of RAG include:

  • Dynamic knowledge integration: Incorporates real-time information from external sources, making it suitable for tasks requiring up-to-date or specific knowledge.
  • Contextual relevance: Enhances the generative model’s responses by providing additional context from the retrieved documents.
  • Versatility: Can handle a wider range of queries, including those requiring specific or rare information that the model may not have been trained on.

Choosing between fine-tuning and RAG

When deciding whether to use fine-tuning or RAG, consider the following factors:

  • Nature of the task: For tasks that benefit from highly specialized models (e.g., domain-specific applications), fine-tuning is often the preferred approach. RAG is ideal for tasks that require integration of external knowledge or real-time information retrieval.
  • Data availability: Fine-tuning requires a substantial amount of labeled data specific to the task. If such data is scarce, RAG’s retrieval component can compensate by providing relevant information from external sources.
  • Resource constraints: Fine-tuning can be computationally intensive, whereas RAG leverages existing databases to supplement the generative model, potentially reducing the need for extensive training.

 

 

微调框架

moreh

https://docs.moreh.io/tutorials/

Fine-tuning Tutorials

This tutorial is for anyone who wants to fine-tune powerful large language models such as Llama2, Mistral for their own projects. We will walk you through the steps to fine-tune these large language models (LLMs) with MoAI Platform.

Fine-tuning in machine learning involves adjusting a pre-trained machine learning model's weight on new data to enhance task-specific performance. Essentially, when you want to apply an AI model to a new task, you take an existing model and optimize it with new datasets. This allows you to customize the model to meet your specific needs and domain requirements.

A pre-trained model has a large number of parameters designed for general-purpose use, and effectively fine-tuning such a large model requires a sufficient amount of training data.

With the MoAI Platform, you can easily apply optimized parallelization techniques that consider the GPU's memory size, significantly reducing the time and effort needed before starting training.

#What you will learn here:

  1. Loading datasets, models, and tokenizers
  2. Running training and checking results
  3. Applying automatic parallelization
  4. Choosing the right training environment and AI accelerators

 

LLaMA-Factory

https://github.com/hiyouga/LLaMA-Factory

Features

  • Various models: LLaMA, LLaVA, Mistral, Mixtral-MoE, Qwen, Yi, Gemma, Baichuan, ChatGLM, Phi, etc.
  • Integrated methods: (Continuous) pre-training, (multimodal) supervised fine-tuning, reward modeling, PPO, DPO, KTO, ORPO, etc.
  • Scalable resources: 16-bit full-tuning, freeze-tuning, LoRA and 2/3/4/5/6/8-bit QLoRA via AQLM/AWQ/GPTQ/LLM.int8/HQQ/EETQ.
  • Advanced algorithms: GaLore, BAdam, DoRA, LongLoRA, LLaMA Pro, Mixture-of-Depths, LoRA+, LoftQ, PiSSA and Agent tuning.
  • Practical tricks: FlashAttention-2, Unsloth, RoPE scaling, NEFTune and rsLoRA.
  • Experiment monitors: LlamaBoard, TensorBoard, Wandb, MLflow, etc.
  • Faster inference: OpenAI-style API, Gradio UI and CLI with vLLM worker.

 

swift

https://github.com/modelscope/swift

SWIFT supports training(PreTraining/Fine-tuning/RLHF), inference, evaluation and deployment of 300+ LLMs and 50+ MLLMs (multimodal large models). Developers can directly apply our framework to their own research and production environments to realize the complete workflow from model training and evaluation to application. In addition to supporting the lightweight training solutions provided by PEFT, we also provide a complete Adapters library to support the latest training techniques such as NEFTune, LoRA+, LLaMA-PRO, etc. This adapter library can be used directly in your own custom workflow without our training scripts.

To facilitate use by users unfamiliar with deep learning, we provide a Gradio web-ui for controlling training and inference, as well as accompanying deep learning courses and best practices for beginners. SWIFT web-ui is available both on Huggingface space and ModelScope studio, please feel free to try!

SWIFT has rich documentations for users, please feel free to check our documentation website:

xtuner

https://github.com/InternLM/xtuner

https://xtuner.readthedocs.io/zh-cn/latest/training/multi_modal_dataset.html

XTuner is an efficient, flexible and full-featured toolkit for fine-tuning large models.

Efficient

  • Support LLM, VLM pre-training / fine-tuning on almost all GPUs. XTuner is capable of fine-tuning 7B LLM on a single 8GB GPU, as well as multi-node fine-tuning of models exceeding 70B.
  • Automatically dispatch high-performance operators such as FlashAttention and Triton kernels to increase training throughput.
  • Compatible with DeepSpeed

    标签:tuning,Qwen,LLMs,fine,Introductory,--,models,model,Fine
    From: https://www.cnblogs.com/lightsong/p/18340179

相关文章

  • SDN(Software-Defined Networking,软件定义网络),NFV(Network Functions Virtualization,网
    目录SDN(Software-DefinedNetworking,软件定义网络)NFV(NetworkFunctionsVirtualization,网络功能虚拟化)SDN(软件定义网络)NFV(网络功能虚拟化)SDN的优势NFV的优势DC(数据中心)网关与MEC(移动边缘计算)节点DC网关MEC节点DC网关与MEC节点的协同作用SDN(Software-DefinedNet......
  • 微软GraphRAG框架源码解读(LLMs)
    1.引言这几天微软开源了一个新的基于知识图谱构建的检索增强生成(RAG)系统:GraphRAG。该框架旨在利用大型语言模型(LLMs)从非结构化文本中提取结构化数据,构建具有标签的知识图谱,以支持数据集问题生成、摘要问答等多种应用场景。GraphRAG的一大特色是利用图机器学习算法针对数据......
  • 论文翻译:Evaluating Reading Comprehension Exercises Generated by LLMs: A Showcase
    EvaluatingReadingComprehensionExercisesGeneratedbyLLMs:AShowcaseofChatGPTinEducationApplicationshttps://aclanthology.org/2023.bea-1.52.pdfhttps://aclanthology.org/2023.bea-1.52/文章目录由大型语言模型(LLMs)生成的阅读理解练习评估:教育应用......
  • 论文阅读:Evaluating Reading Comprehension Exercises Generated by LLMs: A Showcase
    EvaluatingReadingComprehensionExercisesGeneratedbyLLMs:AShowcaseofChatGPTinEducationApplicationshttps://aclanthology.org/2023.bea-1.52.pdfhttps://aclanthology.org/2023.bea-1.52/这篇论文探讨了如何利用预训练的大型语言模型(LLMs),特别是OpenAI的......
  • 【flash attention安装】成功解决flash attention安装: undefined symbol: _ZN2at4_op
    【大模型-flashattention安装】成功解决flashattention安装site-packages/flash_attn_2_cuda.cpython-310-x86_64-linux-gnu.so:undefinedsymbol:_ZN2at4_ops9_pad_enum4callERKNS_6TensorEN3c108ArrayRefINS5_6SymIntEEElNS5_8optionalIdEE本次修炼方法请往下查看......
  • python高性能计算:cython使用openmp并行 —— 报错:undefined symbol: omp_get_thread_n
    test.pyx文件:fromcython.parallelcimportparallelfromopenmpcimportomp_get_thread_numcpdefvoidlong_running_task1()noexceptnogil:whileTrue:passcpdefvoidlong_running_task2()noexceptnogil:whileTrue:passdefdo......
  • 2024-07-29 如何判断自定义组件中的slot是否被传入值==》defineSlots或this.$slots
    假如你的自定义组件是这样:<template><div><button:class="`btn-${type}`"><slot></slot></button></div></template><script>exportdefault{name:"tButt......
  • 简单聊聊JavaScript 中的原型链、null 和 undefined 的区别
    1.原型链个人观点:原型链和逻辑判断里三段论有些类似,一个大前提、一个小前提、一个结论。比如,动物会吃肉,狗是动物,所以狗会吃肉。这也是继承的思想原型和构造函数JavaScript是基于原型的面向对象编程语言,每个对象都有一个内部链接到另一个对象(即原型)。这个机制被称为原型链。原......
  • refinedet模型介绍
    TwoStage的精度优势二阶段的分类:二步法的第一步在分类时,正负样本是极不平衡的,导致分类器训练比较困难,这也是一步法效果不如二步法的原因之一,也是focalloss的motivation。而第二步在分类时,由于第一步滤掉了绝大部分的负样本,送给第二步分类的proposal中,正负样本比例已经比较平......
  • Profinet远程IO模块:模拟量模块_安装与接线说明
    XD系列插片式远程IO模块是兴达易控技术研发的分布式扩展模块。XD系列成套系统主要由耦合器、各种功能IO模块、电源辅助模块以及终端模块组成。有多种通讯协议总线的耦合器,例如PROFINET、Ether0AT、EthernetIP、00linkIE以及modbusT0P等。IO模块可分为多通道数字量输入模块、数......