AI · Tip

Synthetic Preference Data Generation with Distilabel and Llama 3.1

Pipeline pattern for building preference datasets using Distilabel and local LLMs

A Distilabel workflow pattern that automates the generation of synthetic instruction-response datasets. It prompts two different Llama 3.1 models via Ollama and uses a larger model as an UltraFeedback judge to score and rank outputs. It is designed to quickly produce domain-specific preference pairs for fine-tuning smaller models.

How it works

Use Distilabel (open-source framework) with Llama 3.1 via Ollama to generate synthetic datasets. Pattern: two LLMs (llama3.1 8B and llama3.1:70b-instruct) each generate a response to an instruction loaded from the Hub; responses are combined into one column; an LLM-as-judge (UltraFeedback, aspect 'overall-rating') rates them; the best response is paired with the instruction. Pipeline: load_dataset >> generate >> combine >> evaluate. Code imports: from distilabel.llms import OllamaLLM; from distilabel.pipeline import Pipeline; from distilabel.steps import LoadDataFromHub, CombineColumns, tasks. Key snippets: llama8B=OllamaLLM(model="llama3.1", host=host_llama_8b); llama70B=OllamaLLM(model="llama3.1:70b-instruct-q2_k", host=host_llama_70b); with Pipeline(name="preference-datagen-llama3.1") as pipeline: load_dataset=LoadDataFromHub(name="load_dataset", output_mappings={"prompt":"instruction"}); generate=[tasks.TextGeneration(name='text_generation_8B', llm=llama8B), tasks.TextGeneration(name='text_generation_70B', llm=llama70B)]; combine=CombineColumns(columns=["generation","model_name"], output_columns=["generations","model_names"]); evaluate=tasks.UltraFeedback(aspect="overall-rating", llm=llama70B).

What it's for

  • Generate preference datasets for DPO or RLHF fine-tuning
  • Compare outputs between smaller and larger quantized LLM variants
  • Run automated LLM-as-a-judge scoring on synthetic data pipelines

Key points

  • Loads seed prompts directly from Hugging Face Hub using LoadDataFromHub
  • Runs multi-model inference simultaneously via OllamaLLM backends
  • Combines multi-model outputs into unified tabular records using CombineColumns
  • Evaluates candidate responses using the UltraFeedback task for automated ranking
  • Runs fully locally or self-hosted to keep dataset generation private

Pricing

Open source

Details

Type
Tip
Category
AI
Topic
Data Curation
Open source
Yes
Platforms
Code library, Linux, macOS
For
Machine learning engineers and researchers fine-tuning open-weight LLMs
Tags
distilabel, synthetic data, llama3, rlhf, dpo, ollama

Why it was saved

  • @akshay_pachaar, 9 December 2024: Produces (instruction, response) pairs and judge-rated preferences for fine-tuning small LLMs.

Related

  • Local Deep Researcher

    Fully local web research and report writing assistant using Ollama or LMStudio

  • AgenticSeek

    Open-source, fully local autonomous AI agent that browses and writes code

  • Browser Use WebUI

    Open-source graphical interface for running autonomous AI browser agents locally.

  • Dolphin 3.0

    Uncensored, open-source fine-tuned LLM designed for local execution without guardrails

  • Llama-3.1-Nemotron-70B-Instruct

    NVIDIA alignment fine-tune of Llama 3.1 70B for enhanced instruction following

  • OpenRAG

    All-in-one local stack for building and running RAG applications

Updated