Ajuster les paramètres de Llama 3

Travailler avec Llama 3

Imtihan Ahmed

Machine Learning Engineer

À quoi servent les paramètres ?

from llama_cpp import Llama
llm = Llama(model_path="path/to/model.gguf")
output = llm("What are some ways to improve customer retention?")

Contrôler la qualité, l’aléa et la longueur

Travailler avec Llama 3

À quoi servent les paramètres ?

  • Exemple : générer des descriptions de produits

professional_site.png

→ Doit être factuel et concis

 

Orienté style de vie

 

→ Doit être engageant et créatif

Travailler avec Llama 3

Paramètres de décodage de Llama 3

$$

  • Ajuster le comportement de Llama

$$

  • Utiliser des paramètres de décodage pour adapter les tons

$$

  • Transformer la sortie brute en texte lisible

Ajuster le comportement de Llama avec des paramètres

Travailler avec Llama 3

Paramètres de décodage de Llama 3

$$

  • Température : contrôle l’aléa
  • Top-K : limite la sélection aux tokens les plus probables
  • Top-P : ajuste selon la probabilité cumulée
  • Max tokens : limite la longueur de la réponse

$$

Screenshot 2025-02-26 at 12.51.27.png

Travailler avec Llama 3

Température

  • Valeurs généralement entre 0 et 1

  • Température basse (p. ex. proche de 0) :

    • Réponse plus prévisible
      A smartwatch with a heart rate monitor, GPS, and a long-lasting battery 
      for all-day tracking.
      
  • Température élevée (p. ex. proche de 1) :
    • Réponse plus créative
      Your personal fitness coach on your wrist - track every heartbeat, every step, 
      and every adventure without limits.
      
Travailler avec Llama 3

Top-k

  • Limite combien de mots les plus probables Llama peut choisir

  • Faible valeur k (p. ex. 1) :

    • Réponse plus prévisible
      Track fitness, stream music, and receive notifications with our sleek smartwatch.
      
  • Forte valeur k (p. ex. 50) :

    • Réponse plus variée
      Experience the future with our cutting-edge smartwatch, featuring fitness tracking, music streaming, customizable notifications, personalized insights, and seamless smartphone integration always.
      
Travailler avec Llama 3

Top-p

  • Contrôle le choix des mots selon la confiance

  • Top-p élevé (p. ex. proche de 1) :

    • Réponses plus variées
      Stay connected with our sleek smartwatch, featuring fitness tracking,
      music, and customizable notifications, perfect for fitness 
      enthusiasts and busy professionals.
      
  • Top-p faible (p. ex. proche de 0) :

    • Moins de variation
      Smartwatch with fitness tracking and music control, perfect for workouts.
      
Travailler avec Llama 3

Max tokens

  • Sert à limiter la longueur de la réponse
  • Nombre de tokens — unités de mots — dans la réponse

  • Valeur max_tokens faible :

    Stay connected with our sleek smartwatch, featuring fitness tracking 
    and music control.
    
  • Valeur max_tokens élevée :
    Stay connected with our sleek smartwatch, featuring fitness tracking, 
    music control, customizable notifications, and seamless smartphone 
    integration. Monitor your health, track your progress, and receive 
    alerts on your wrist. Perfect for fitness enthusiasts.
    
Travailler avec Llama 3

Combiner différents paramètres

llm = Llama(model_path="path/to/model.gguf")

output_concise = llm(
    "Describe an electric car.",

temperature=0.2,
top_k=1,
top_p=0.4,
max_tokens=20
)
A fast, eco-friendly electric car with a long range and cutting-edge technology.
Travailler avec Llama 3

Combiner différents paramètres

output_creative = llm(
    "Describe an electric car.",

temperature=0.8,
top_k=10,
top_p=0.9,
max_tokens=100
)
Glide into the future with an electric car that blends speed, luxury,
and sustainability. Silent yet powerful, it redefines the road ...
Travailler avec Llama 3

Passons à la pratique !

Travailler avec Llama 3

Preparing Video For Download...