Ajuste de parámetros de Llama 3

Trabajar con Llama 3

Imtihan Ahmed

Machine Learning Engineer

¿Para qué sirven los parámetros?

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

Control the quality, randomness, and length

Trabajar con Llama 3

¿Para qué sirven los parámetros?

  • Ejemplo: generar descripciones de productos

professional_site.png

→ Debe ser factual y concisa

 

Sitio orientado al estilo de vida

 

→ Debe ser atractivo y creativo

Trabajar con Llama 3

Parámetros de decodificación de Llama 3

$$

  • Ajustan el comportamiento de Llama

$$

  • Usa parámetros de decodificación para adaptar tonos

$$

  • Transforman la salida bruta en texto legible

Ajustar el comportamiento de Llama con parámetros

Trabajar con Llama 3

Parámetros de decodificación de Llama 3

$$

  • Temperature: controla la aleatoriedad
  • Top-K: limita la selección a los tokens más probables
  • Top-P: ajusta según probabilidad acumulada
  • Max tokens: limita la longitud de la respuesta

$$

Screenshot 2025-02-26 at 12.51.27.png

Trabajar con Llama 3

Temperatura

  • Valores normalmente entre 0 y 1

  • Temperatura baja (p. ej., cerca de 0):

    • Respuesta más predecible
      A smartwatch with a heart rate monitor, GPS, and a long-lasting battery 
      for all-day tracking.
      
  • Temperatura alta (p. ej., cerca de 1):
    • Respuesta más creativa
      Your personal fitness coach on your wrist - track every heartbeat, every step, 
      and every adventure without limits.
      
Trabajar con Llama 3

Top-k

  • Limita cuántas de las palabras más probables puede elegir Llama

  • Valor k bajo (p. ej., 1):

    • Respuesta más predecible
      Track fitness, stream music, and receive notifications with our sleek smartwatch.
      
  • Valor k alto (p. ej., 50):

    • Respuesta más diversa
      Experience the future with our cutting-edge smartwatch, featuring fitness tracking, music streaming, customizable notifications, personalized insights, and seamless smartphone integration always.
      
Trabajar con Llama 3

Top-p

  • Controla la elección de palabras según la confianza

  • Valor de top-p alto (p. ej., cerca de 1):

    • Respuestas más variadas
      Stay connected with our sleek smartwatch, featuring fitness tracking,
      music, and customizable notifications, perfect for fitness 
      enthusiasts and busy professionals.
      
  • Valor de top-p bajo (p. ej., cerca de 0):

    • Menos variación
      Smartwatch with fitness tracking and music control, perfect for workouts.
      
Trabajar con Llama 3

Max tokens

  • Sirve para limitar la longitud de la respuesta
  • Recuento de tokens (unidades de palabras) en la respuesta

  • Valor de max_tokens bajo:

    Stay connected with our sleek smartwatch, featuring fitness tracking 
    and music control.
    
  • Valor de max_tokens alto:
    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.
    
Trabajar con Llama 3

Combinando distintos parámetros

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.
Trabajar con Llama 3

Combinando distintos parámetros

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 ...
Trabajar con Llama 3

¡Vamos a practicar!

Trabajar con Llama 3

Preparing Video For Download...