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éatoire 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

 

Site axé sur le style de vie

 

→ Doit être accrocheur 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 le ton

$$

  • 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

$$

  • Temperature : contrôle l'aléatoire
  • Top-K : limite le choix aux jetons 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

Temperature

  • Valeurs généralement entre 0 et 1

  • Faible température (p. ex., près de 0) :

    • Réponse plus prévisible
      A smartwatch with a heart rate monitor, GPS, and a long-lasting battery 
      for all-day tracking.
      
  • Haute température (p. ex., près 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 très 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

  • Forte valeur top-p (p. ex., près 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.
      
  • Faible valeur top-p (p. ex., près 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
  • Le nombre de jetons – unités de mots – dans la réponse

  • Faible valeur de max_tokens :

    Stay connected with our sleek smartwatch, featuring fitness tracking 
    and music control.
    
  • Forte valeur de max_tokens :
    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...