----------------------
Fine-tuning a Language Learning Model (LLM) with LlamaIndex involves several steps. Here are some examples of how you can do it:
- Fine-tuning for better retrieval performance:
from llama_index.finetuning import OpenAIFinetuneEngine
finetune_engine = OpenAIFinetuneEngine(
"gpt-3.5-turbo",
"data_rag/qa_pairs_openai.jsonl",
# start_job_id="<start-job-id>" # if you have an existing job, can specify id here
)
finetune_engine.finetune()
ft_model = finetune_engine.get_finetuned_model()
# Use fine-tuned model in RAG system
from llama_index import ServiceContext
ft_context = ServiceContext.from_defaults(
llm=ft_model,
callback_manager=callback_manager,
system_prompt="You are a helpful assistant helping to answer questions about the Llama 2 paper.",
)
# fine-tuned RAG system
ft_query_engine = vector_index.as_query_engine(
similarity_top_k=1, service_context=ft_context
)
Source ()
- Fine-tuning for Text-to-SQL with Gradient.ai:
```python
from llama_index.finetuning import GradientFinetuneEngine
base_model_slug = "nous-hermes2"
base_model_slug = "llama2-7b-chat"
base_llm = GradientBaseModelLLM(
base_model_slug=base_model_slug, max_tokens=300
)
step max steps to 20 just for testing purposes
NOTE: can only specify one of base_model_slug or model_adapter_id
finetune_engine = GradientFinetuneEngine(
base_model_slug=base_model_slug,
# model_adapter_id='805c6fd6-daa8-4fc8-a509-bebb2f2c1024_model_adapter',
name="text_to_sql",
data_path="train_data.jsonl",
verbose=True,
max_steps=200,
batch_size=4,
)
finetune_engine.finetune()