Fine-tuning Llama 2 on Your Own Dataset | Train an LLM for Your Use Case with QLoRA on a Single GPU

Поділитися
Вставка
  • Опубліковано 18 тра 2024
  • Full text tutorial (requires MLExpert Pro): www.mlexpert.io/prompt-engine...
    Learn how to fine-tune the Llama 2 7B base model on a custom dataset (using a single T4 GPU). We'll use the QLoRa technique to train an LLM for text summarization of conversations between support agents and customers over Twitter.
    Discord: / discord
    Prepare for the Machine Learning interview: mlexpert.io
    Subscribe: bit.ly/venelin-subscribe
    GitHub repository: github.com/curiousily/Get-Thi...
    Join this channel to get access to the perks and support my work:
    / @venelin_valkov
    00:00 - When to Fine-tune an LLM?
    00:30 - Fine-tune vs Retrieval Augmented Generation (Custom Knowledge Base)
    03:38 - Text Summarization (our example)
    04:14 - Text Tutorial on MLExpert.io
    04:47 - Dataset Selection
    05:36 - Choose a Model (Llama 2)
    06:22 - Google Colab Setup
    07:26 - Process data
    10:08 - Load Llama 2 Model & Tokenizer
    11:18 - Training
    14:49 - Compare Base Model with Fine-tuned Model
    18:08 - Conclusion
    #llama2 #llm #promptengineering #chatgpt #chatbot #langchain #gpt4 #summarization

КОМЕНТАРІ • 59

  • @venelin_valkov
    @venelin_valkov  8 місяців тому +7

    Full text tutorial (requires MLExpert Pro): www.mlexpert.io/prompt-engineering/fine-tuning-llama-2-on-custom-dataset

    • @kiranatmakuri3710
      @kiranatmakuri3710 7 місяців тому

      Can you send me your email pls I have a question can’t ask in public

    • @williamfussell1956
      @williamfussell1956 6 місяців тому +2

      I keep having problems with the model.merge_and_unload()...
      It seems to be a bit different from the documentation on Hugging Face...is there something I am missing here?
      The error says that that 'LlamaForCausalLM' object has no attribute 'merge_and_unload'....
      Any ideas?

    • @pablomeza5932
      @pablomeza5932 6 місяців тому

      @@williamfussell1956 Did you fix that?

    • @fl028
      @fl028 2 місяці тому

      @@williamfussell1956 merged_model = trained_model.merge_and_unload()

  • @vivekjyotibhowmik8008
    @vivekjyotibhowmik8008 8 місяців тому +26

    Can you provide the Google Collab notebook?

  • @christopherbader2222
    @christopherbader2222 7 місяців тому +4

    This is great. A version for question answering would be helpful too.

  • @parisapouya6716
    @parisapouya6716 7 місяців тому +1

    Awesome work! Thanks a ton!

  • @stawils
    @stawils 8 місяців тому +2

    Good stuff coming, thank you in advance ❤

  • @echos01
    @echos01 8 місяців тому +2

    Excellent work! You are the hero!

  • @HeywardLiu
    @HeywardLiu 8 місяців тому +1

    Awesome tutorial!

  • @AbdulBasit-ff6tq
    @AbdulBasit-ff6tq 8 місяців тому +4

    Do you have or plan to make a tutorial for something like bellow?
    Tutorial for the plane text fine-tuning and then tuning that model to make it an instruct tuned one?

  • @NitroBrewbell
    @NitroBrewbell 8 місяців тому +1

    very helpful. Thanks for the videos.

  • @VaibhavPatil-rx7pc
    @VaibhavPatil-rx7pc 8 місяців тому +2

    Super excited

  • @krishchatterjee2819
    @krishchatterjee2819 6 місяців тому +4

    Excellent video! What changes in the input we need to make to use 8 bit quantization instead of 4 bit. Thanks.

  • @GregMatoga
    @GregMatoga 7 місяців тому +5

    Thank you for this! Is finetuning a good approach for a private/proprietary documentation Q&A?

  • @lyovazi8533
    @lyovazi8533 8 місяців тому +1

    very good video

  • @jensonjoy83
    @jensonjoy83 8 місяців тому +1

    will you be able to add a tutorial for llama2-chat model

  • @fabsync
    @fabsync 12 днів тому

    Fantastic video! It will be nice to see a full tutorial on how to do it with pdf locally...

  • @DawnWillTurn
    @DawnWillTurn 8 місяців тому +1

    Any idea how can we deploy llama-2 on huggingface api? just like the falcon one, has some issue with the handler.

  • @williamgomezsantana
    @williamgomezsantana 3 місяці тому +2

    Incredible video!! Thank you very much, I have a question: isn't it mandatory to put characters like EOS at the end of the summary? for the LLM to finish the instruction?

  • @chukypedro818
    @chukypedro818 8 місяців тому +1

    Super🎉

  • @experiment5762
    @experiment5762 6 місяців тому

    Great!! Do some videos regarding RLHF.

  • @shopbc5553
    @shopbc5553 5 місяців тому +1

    Do you have an idea how GPT4 is so good with its responses from its base model when I upload documents to it?
    Could it be the parameter. size only or do you think other technologies are what determine the quality difference?

  • @danieladama8105
    @danieladama8105 8 місяців тому +1

    🔥

  • @sasukeuchiha-ck4hy
    @sasukeuchiha-ck4hy 8 місяців тому +1

    can you train the model on german data?

  • @tarunku9378
    @tarunku9378 8 місяців тому +1

    I still don't get it i have my data locally , how should start finetuning it please tell

  • @ikurious
    @ikurious 8 місяців тому +3

    Great video!
    Is there anyway to build my instruction dataset for instruct fine-tuning from classical text books?

    • @ikurious
      @ikurious 8 місяців тому

      @@user-xt6tu3xt3t but then how to convert in question & answer format?

    • @mauriciososa9722
      @mauriciososa9722 8 місяців тому

      @@ikurious the best way is manualyl by a human

  • @techtraversal219
    @techtraversal219 6 місяців тому +1

    Thanks for sharing, really helpful. Waiting for my Llama model access to follow it step by step. Can I use any other model in place of this?

    • @srushtiharyan2033
      @srushtiharyan2033 3 місяці тому

      Did you get the access? And how long did it take?

  • @williamfussell1956
    @williamfussell1956 6 місяців тому

    Hi there, I am just reading through the repo and Im pretty sure this is the answer...i just wanted to make sure...
    The actual input to the model is only from the [text] field, is that correct? As the [text] field contains the prompt, the conversation and the summary...

  • @GooBello-gr2ls
    @GooBello-gr2ls 7 місяців тому +1

    can i download the finetuned model after finetuning?
    is it in format .bin or .safetensor or else?
    cuz im current trying to do finetuning on textgen, but having troubles. with dataset (format) i guess.

    • @lisab1360
      @lisab1360 7 місяців тому

      do you already know how you can download the finetuned model?

  • @elysiryuu
    @elysiryuu 3 місяці тому

    Thanks for the insight, is it possible to perform training locally, with 8 GB VRAM?

  • @user-xy5re6qh3d
    @user-xy5re6qh3d 5 місяців тому

    Hola, For me the validation log show No log with mistral instruct model. Please help anyone.

  • @tahahuraibb5833
    @tahahuraibb5833 8 місяців тому +2

    default_factory=lambda: ["q_proj", "v_proj"] Why did you not add this? Is it because HF does under the hood?

    • @venelin_valkov
      @venelin_valkov  8 місяців тому +1

      I totally forgot about the `target_modules`. I retrained and updated the notebook/tutorial with those. The results are better!
      Here's the list:
      lora_target_modules = [
      "q_proj",
      "up_proj",
      "o_proj",
      "k_proj",
      "down_proj",
      "gate_proj",
      "v_proj",
      ]
      I composed it from here: github.com/huggingface/transformers/blob/f6301b9a13b8467d1f88a6f419d76aefa15bd9b8/src/transformers/models/llama/convert_llama_weights_to_hf.py#L144
      Thank you!

    • @williamfussell1956
      @williamfussell1956 6 місяців тому

      Is there a good resource for understanding 'target modules' for different models? @@venelin_valkov

  • @karimbaig8573
    @karimbaig8573 6 місяців тому

    When you say you are tracking loss, what loss is that and how is that loss calculated for the task (summarization) at hand?

    • @anuranjankumar2904
      @anuranjankumar2904 4 місяці тому

      I have the same question. @karimbaig8573 were you able to figure out the answer?

    • @karimbaig8573
      @karimbaig8573 4 місяці тому

      Nope.

  • @vitocorleon6753
    @vitocorleon6753 8 місяців тому +1

    I need help please. I just want to be pointed in the right direction since I'm new to this and since I couldn't really find any proper guide to summarize the steps for what I want to accomplish.
    I want to integrate a LLama 2 70B chatbot into my website. I have no idea where to start. I looked into setting up the environment on one of my cloud servers(Has to be private). Now I'm looking into training/fine-tuneing the chat model using our data from our DBs(It's not clear for me here but I assume it involves two steps, first I have to have the data in a CSV format since it's easier for me, second I will need to format it in Alpaca or Openassistant formats). After that, the result should be a deployment-ready model ?
    Just bullet points I'd highly appreciate that.

    • @vitocorleon6753
      @vitocorleon6753 7 місяців тому

      @nty3929 Oh :/ I’m still lost about this but thank you for your effort nevertheless!

    • @GregMatoga
      @GregMatoga 7 місяців тому

      @nty3929 Yeah, bots are ruthless here and youtube is having none of it, even at that cost. Guess they expect to see more technical conversations elsewhere

  • @cancheers
    @cancheers 8 місяців тому +2

    should it be merged_model = trained_model.merge_and_unload()?
    cannot run, it is killed

    • @rone3243
      @rone3243 8 місяців тому

      I have this problem as well😢

    • @kpratik41
      @kpratik41 8 місяців тому

      Were you able to solve this?

    • @fl028
      @fl028 2 місяці тому +1

      merged_model = trained_model.merge_and_unload()

  • @okopyl
    @okopyl 7 місяців тому

    Why do you use that kind of prompt for the training like `### Instruction`? When in fact Llama 2 prompts are like `[INST] `...

    • @g1rlss1mp
      @g1rlss1mp 7 місяців тому

      I think it's a LLaMA2-CHAT prompt. The base model was not finetuned.

  • @MecchaKakkoi
    @MecchaKakkoi 3 місяці тому

    This looks like a great notebook, however, I always get a "CUDA out of memory" error when it executes the SFTTrainer function. It's fine up until then according to nvidia-smi but then memory just instantly maxes out. Does anyone know a way around this?

    • @rishabjain9275
      @rishabjain9275 2 місяці тому +1

      try reducing the sequence length

    • @fl028
      @fl028 2 місяці тому +1

      I reduced per_device_train_batch_size=1,

  • @skahler
    @skahler 7 місяців тому

    omg @ 15:06 😂😂😂

  • @JeeneyAI
    @JeeneyAI 3 місяці тому +1

    ALL of these tutorials require more dependencies. Can't somebody post how to do this in pycharm with your own GPU? I can't make any of the tutorials I've found work and it's just an endless troubleshooting process as to why everything is different in all of them