الضبط الدقيق الفعّال / Efficient fine-tuning

الترتيب / Order
8 من 14 / 8 of 14
آخر تحديث / Updated
8 أكتوبر 2026 / 8 October 2026

المستوى: متوسط · الدرس 8 من 14

أهداف الدرس

  1. أن تضبط نموذجاً مفتوحاً بموارد قليلة.
  2. أن تختار بين LoRA والتكميم والتقطير.

بدل تعديل مليارات الأوزان، تضيف LoRA مصفوفتين صغيرتين بجانب الأوزان المجمّدة، وتدرّبهما وحدهما. فتحتاج ذاكرة أقل بكثير، ويمكن أن تحفظ لكل مهمة «محوّلاً» صغيراً.

مصفوفتان صغيرتان بدل كل الأوزان
مصفوفتان صغيرتان بدل كل الأوزان
Python
from transformers import AutoModelForCausalLM
from peft import LoraConfig, get_peft_model

model = AutoModelForCausalLM.from_pretrained("path/to/an-open-model")
config = LoraConfig(r=16, lora_alpha=32, lora_dropout=0.05,
                    target_modules=["q_proj", "v_proj"], task_type="CAUSAL_LM")
model = get_peft_model(model, config)
model.print_trainable_parameters()   # a fraction of 1% of the weights
التقنيةماذا تفعلمتى
LoRAتدرّب جزءاً صغيراًأسلوب أو شكل أو مهمة محدّدة
QLoRALoRA فوق نموذج مضغوطذاكرة رسومية محدودة
التكميميضغط الأوزان إلى 8 أو 4 بتتشغيل أسرع وأرخص
التقطيرنموذج كبير يعلّم نموذجاً صغيراًنموذج صغير على جهاز أو هاتف

الضبط الدقيق يعلّم الأسلوب والشكل أفضل مما يعلّم المعرفة الجديدة. لمعرفة تتغيّر — لوائح ومواعيد — استعمل الاسترجاع (RAG) في الدرس العاشر.

تمرين

تريد مساعداً يكتب بأسلوب الكلية الرسمي. ضبط دقيق أم RAG؟

الإجابة

ضبط دقيق بـ LoRA: الأسلوب شكلٌ ثابت يتعلّمه النموذج جيداً.

Level: Intermediate · Lesson 8 of 14

Lesson goals

  1. Fine-tune an open model on modest hardware.
  2. Choose between LoRA, quantization and distillation.

Instead of changing billions of weights, LoRA adds two small matrices beside the frozen weights and trains only those. You need far less memory, and can keep a small «adapter» per task.

Two small matrices instead of all the weights
Two small matrices instead of all the weights
Python
from transformers import AutoModelForCausalLM
from peft import LoraConfig, get_peft_model

model = AutoModelForCausalLM.from_pretrained("path/to/an-open-model")
config = LoraConfig(r=16, lora_alpha=32, lora_dropout=0.05,
                    target_modules=["q_proj", "v_proj"], task_type="CAUSAL_LM")
model = get_peft_model(model, config)
model.print_trainable_parameters()   # a fraction of 1% of the weights
TechniqueWhat it doesWhen
LoRATrains a small partA style, format or narrow task
QLoRALoRA on top of a compressed modelLimited GPU memory
QuantizationCompresses weights to 8 or 4 bitsFaster, cheaper running
DistillationA big model teaches a small oneA small model on a device or phone

Fine-tuning teaches style and format better than new knowledge. For knowledge that changes — rules and dates — use retrieval (RAG) in lesson 10.

Exercise

You want an assistant that writes in the college's formal style. Fine-tuning or RAG?

Answer

LoRA fine-tuning: style is a stable shape the model learns well.

التعليقات / Comments

لا تعليقات بعد. كن أول من يسأل. / No comments yet. Be the first to ask.

تعليق الطالب يظهر فوراً، وتعليق الزائر بعد موافقة المدرّس. / A student's comment shows at once; a visitor's once the teacher approves it.

في «الذكاء الاصطناعي: من الصفر إلى الاحتراف» / In “AI: from zero to hero”

  1. 1ما الذكاء الاصطناعي التوليدي؟ / What is generative AI?فيها صور / has picturesالتعليقات مفتوحة / comments open
  2. 2الرموز والتضمينات / Tokens and embeddingsفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  3. 3المحوّل والانتباه / Transformers and attentionفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  4. 4التدريب المسبق / Pre-trainingفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  5. 5الضبط بالتعليمات / Instruction tuning (SFT)فيها كود / has codeالتعليقات مفتوحة / comments open
  6. 6التعلّم من التفضيلات / Learning from preferencesفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  7. 7نماذج الاستدلال / Reasoning modelsفيها كود / has codeالتعليقات مفتوحة / comments open
  8. 8الضبط الدقيق الفعّال / Efficient fine-tuningفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  9. 9هندسة الأوامر والسياق / Prompt and context engineeringفيها كود / has codeالتعليقات مفتوحة / comments open
  10. 10الاسترجاع المعزّز (RAG) من الصفر / RAG from scratchفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  11. 11RAG المتقدّم / Advanced RAGفيها كود / has codeالتعليقات مفتوحة / comments open
  12. 12الوكلاء والأدوات / Agents and toolsفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  13. 13التقييم والأمان / Evaluation and safetyفيها كود / has codeفيها صور / has picturesالتعليقات مفتوحة / comments open
  14. 14مشروع ختامي: مساعد عربي / Capstone: an Arabic assistantفيها كود / has codeفيها صور / has picturesفيها نموذج / has a formالتعليقات مفتوحة / comments open

↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق↑ ↓ to move · Enter to open · Esc to close