Hi,👋 we have updated the app and fixed multiple bugs. We are lacking funds, request to free user not to use Adblock. Ads are non intrusive. 😊

@_avichawla: Let's fine-tune DeepSeek-R1 (d...

@_avichawla
9 views Jan 28, 2025
1
Let's fine-tune DeepSeek-R1 (distilled Llama) 100% locally:
2
Before we begin, here's what we'll be doing.

We'll fine-tune our private and locally running DeepSeek-R1 (distilled Llama variant).

To do this, we'll use:
- @UnslothAI for efficient fine-tuning.
- @ollama to run it locally.

Let's begin!
3
1) Load the model

We start by loading the Distilled Llama-8B model and the tokenizer of DeepSeek-R1 using Unsloth:
Media image
4
2) Define LoRA config

We must use efficient techniques like LoRA to avoid fine-tuning the entire model weights.

In this code, we use Unsloth's PEFT by specifying:
- The model
- LoRA low-rank (r)
- Modules for fine-tuning
- and a few more parameters.
Media image
5
3) Prepare dataset

Next, we use the Alpaca dataset to prepare a conversation dataset.

The conversation_extension parameter defines the number of user messages in a single conversation.
Media image
6
4) Define Trainer

Here, we create a Trainer object by specifying the training config like learning rate, model, tokenizer, and more.

Check this out👇
Media image
7
5) Train

With that done, we initiate training. We notice a decreasing loss, which means the model is fine-tuning well.

Check this code and output👇
Media image
8
6) Export to Ollama

Finally, we export the model to Ollama as follows.

Done!
Media image
9
We have fine-tuned DeepSeek (distilled Llama).

Now we can interact with it like any other model running on Ollama using:

- The CLI
- Ollama's Python package
- Ollama's LlamaIndex integration, etc.
Media image
10
That's a wrap!

If you enjoyed this tutorial:

Find me → @_avichawla

Every day, I share tutorials and insights on DS, ML, LLMs, and RAGs.
Actions
Visual Editor Carousel Maker NEW
Update Thread
What You Can Do
  • Download as PDF
  • Save to Notion
  • Export as Markdown
  • Visual Editor
  • LinkedIn & Instagram Carousel Maker
Create Free Account

Includes 7-day Premium trial