متقدم
البحث فيالملخصات
طريقة البحث
  • الكلمات تجد عناوين الدروس والنص والكود. صفِّ حسب النوع (أدلة، دورات، برامج، كتب) أو ابقَ في هذا الكتاب.
  • book:rhcsa و ch:8 يضيّقان البحث؛ ‎#code يجد الكلمة داخل أوامر الدروس فقط.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدورة 11الاسم في الدورة: Generative AI Advanced Fine-Tuning for LLMs

Generative AI Advanced Fine-Tuning for LLMs

Course 11 of 13 in the IBM AI Engineering certificate. How instruction tuning turns a base model into an assistant.

Course page: Coursera

  • 6 الدروس
  • 0 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

11.1

What the course covers

How instruction tuning turns a base model into an assistant.

  • How to prepare a dataset and training arguments with Hugging Face.
  • How a reward model scores answers from human preferences.
  • How RLHF and PPO align a model with that feedback.
  • How DPO does the same job in a simpler, more direct way.
ModuleMain focus
Module 1 · about 4 hoursDifferent approaches to fine-tuning: instruction tuning, dataset prep, reward modelling, preference data
Module 2 · about 5 hoursRLHF: LLMs as distributions, policies, PPO, log-derivative trick, DPO, InstructLab

11.2

Module 1: Different Approaches to Fine-Tuning

Different approaches to fine-tuning: instruction tuning, dataset prep, reward modelling, preference data.

  • Instruction tuning is supervised fine-tuning on (instruction, response) pairs. The model learns to follow requests, not just continue text.
  • A good dataset has many task types, clear prompts and correct answers. Quality beats size.
  • Preprocessing: load the data, format each row with one prompt template, tokenize it, and keep the response as the label.
  • In Hugging Face, datasets loads and maps the data. Trainer or SFTTrainer runs the training loop.
  • Training arguments set the learning rate, the number of epochs, the batch size and the evaluation steps.
  • Best practices: a small learning rate, a validation split and early stopping. Too many epochs cause overfitting.
  • A reward model reads a prompt plus a response and gives one number: how good that response is.
  • It is trained on preference pairs: a chosen answer and a rejected answer for the same prompt.
  • The usual loss is a pairwise ranking loss. This comes from the Bradley–Terry model.
  • The reward model often starts from an LLM with a small value head. A LoRA setup keeps the training cheap.

11.3

Module 2: Fine-Tuning Causal LLMs with Human Feedback and Direct Preference

RLHF: LLMs as distributions, policies, PPO, log-derivative trick, DPO, InstructLab.

  • An LLM gives a probability distribution over the next token. The distribution over full answers acts as a policy.
  • RLHF has three steps: supervised fine-tuning, reward modelling, then reinforcement learning to raise the reward.
  • PPO is the RL algorithm used in RLHF. It has a clipped objective, an advantage estimate and a critic.
  • The clip stops one update from changing the policy too much. The KL penalty keeps the model near the reference model.
  • Log-derivative trick: ∇θ E[f] = E[f · ∇θ log πθ]. It lets us estimate a gradient from samples.
  • DPO skips the reward model and the RL loop. It learns directly from chosen and rejected pairs.
  • DPO uses a reference model and a temperature beta. Beta controls how far the policy may drift.
  • In the DPO loss, the partition function Z(x) cancels, so it never has to be computed.
  • DPO is simpler and more stable than PPO. RLHF can still be stronger for complex rewards. DPO was published in 2023.
  • InstructLab fine-tunes a model on your own machine, using data generated from a taxonomy of skills.

11.4

Check yourself

Answer each question first, then open it to check the answer.

1What is instruction tuning? a) Training on instruction-response pairs so the model follows requests · b) Training the tokenizer only · c) Quantizing the weights · d) Searching a vector database

a) Training on instruction-response pairs so the model follows requests. Instruction tuning maps a request to the expected answer, so the model learns to follow it.

2What do training arguments set? a) The tokenizer vocabulary · b) The learning rate, epochs and batch size · c) The number of documents · d) The Gradio theme

b) The learning rate, epochs and batch size. Learning rate, epochs and batch size are the main training settings.

3What is a reward model? a) A model that splits text · b) A vector index · c) A model that gives a score to a response · d) A tokenizer

c) A model that gives a score to a response. The reward model turns a prompt and a response into one quality score.

4What data trains a reward model? a) Only unlabeled text · b) Human preference pairs with a chosen and a rejected response · c) Images with captions · d) SQL tables

b) Human preference pairs with a chosen and a rejected response. Two answers for the same prompt, one chosen and one rejected, give the training signal.

5In RLHF, why add a KL penalty to the reference model? a) To keep the tuned model close to the original and stop it drifting · b) To make training slower · c) To delete the reward model · d) To increase the context window

a) To keep the tuned model close to the original and stop it drifting. The KL term penalizes a policy that moves too far from the reference model.

6What does PPO do in RLHF? a) It stores embeddings · b) It splits documents · c) It updates the policy for higher reward while limiting each update's size · d) It builds the UI

c) It updates the policy for higher reward while limiting each update's size. PPO improves the policy and clips the update so it stays stable.

7Which formula shows the log-derivative trick? a) ∇θ E[f] = E[f · ∇θ log πθ] · b) E = mc² · c) softmax(x_i) = e^(x_i) / Σ e^(x_j) · d) L = -Σ y log ŷ

a) ∇θ E[f] = E[f · ∇θ log πθ]. The trick rewrites the gradient of an expectation as an expectation of a log-probability gradient.

8What is the main idea of DPO? a) Learn directly from preference pairs without a separate reward model or RL loop · b) Train a reward model, then run PPO · c) Quantize the model · d) Retrieve documents

a) Learn directly from preference pairs without a separate reward model or RL loop. DPO uses preference pairs directly, with no reward model and no PPO loop.

9What does the reference model do in DPO? a) It stores the documents · b) It gives baseline log-probabilities so the policy does not drift far · c) It creates the UI · d) It tokenizes the data only

b) It gives baseline log-probabilities so the policy does not drift far. The reference model is the fixed baseline in the DPO ratio.

10In DPO, what happens to the partition function Z(x)? a) It cancels out in the preference difference · b) It is stored in the vector DB · c) It becomes the learning rate · d) It is the batch size

a) It cancels out in the preference difference. The same Z(x) appears in both terms, so it drops out of the difference.

11What does beta control in DPO? a) The number of documents · b) How far the policy may move from the reference model · c) The tokenizer size · d) The Gradio port

b) How far the policy may move from the reference model. A small beta allows a big change; a large beta keeps the policy close to the reference.

12Which comparison of DPO and RLHF is correct? a) DPO needs a reward model; RLHF does not · b) Both need no data · c) DPO is only for images · d) DPO is simpler and needs less compute; RLHF uses a reward model and PPO

d) DPO is simpler and needs less compute; RLHF uses a reward model and PPO. DPO is the simpler path; RLHF is the reward model plus PPO path.

13What does InstructLab let you do? a) Fine-tune a model locally with generated data · b) Build a vector database only · c) Replace the tokenizer · d) Train a reward model with no data

a) Fine-tune a model locally with generated data. InstructLab generates data from a taxonomy and fine-tunes on your own machine.

11.5

Study and exam tips

Remember the RLHF order: supervised fine-tuning, reward model, PPO.

  • Link DPO with three words: no reward model, no RL loop, preference pairs.
  • Keep the losses apart: ranking loss for the reward model, clipped objective for PPO.
  • Beta and the KL penalty both limit how far the model moves from the reference.
  • Write the log-derivative trick once by hand before the quiz.