Find answers from the community

Updated last year

fine-tunning LLM with LlamaIndex

@kapa.ai fine-tunning LLM with LlamaIndex
k
3 comments
Please stand by @Matthews as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
Fine-tuning a Language Learning Model (LLM) with LlamaIndex involves several steps. Here are some examples of how you can do it:

  1. Fine-tuning for better retrieval performance:
Plain Text
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 ()

  1. 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()
ft_llm = finetune_engine.get_finetuned_model(max_tokens=300)
```
Source ()

Please note that the specific steps and parameters may vary depending on your specific use case and the model you are fine-tuning.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord