I want to fine tune a model locally, not using HuggingFace or any other third party tool. Basically, I want:

Download a trained model (Llama-2, Falcon, whatever is easiest). Fine-tune it locally with my own data (maybe a set of mathematical theorems with proofs or customer service interactions, whatever) Then be able to ask questions on the new trained data without losing what the model had pre-learned I want to understand what model I should download (this is to learn, so it does not have to be the best available). Can I do it on a regular PC (I understand it may run for several hours)? How do I test to see if it has learned correctly?

I understand this is more than can be answered here, so I am asking for links, videos, something that addresses this exercise explicitly. I am not looking for a generic course on LLMs or Transformers. I know the theory, I want practical steps on how to fine-tune a model, locally, on my own machine, with some data I have or downloaded from the internet. Something that can go further than the videos by Andrej Karpathy that I have already seen, suggesting a pre-trained LLM and going through the steps I described.

  • 1
    $\begingroup$ I would say "not using HuggingFace or any other third party tool" is impossible, because you need at least a deep learning library to support the finetuning; please, clarify the cutting point. Also, "without losing what the model had pre-learned", is not something black-or-white; the model changes during fine-tuning, so it will not behave the same afterwards, and will possibly loose some of it's previous abilities in favor of the bias toward the finetuning data; also, it would be difficult to characterize what "has been lost". $\endgroup$
    – noe
    Commented Nov 12, 2023 at 8:45
  • 1
    $\begingroup$ @noe Thank you for the comment. What I meant is "without sharing data with third parties". Using a library, as long as the data remains local, is fine. $\endgroup$
    – user
    Commented Nov 12, 2023 at 13:08

1 Answer 1


Can I do it on a regular PC (I understand it may run for several hours)?

As a general guideline, you need a powerful workstation to perform this task. You should certainly consider having a cuda/gpu card installed on your local workstation. Both host and cuda device would need tens of GB of memory to start with. Of course you need enough disk space for the storage of training and validation datasets.

How do I test to see if it has learned correctly?

This involves an evaluation step after you are done fine-tuning (training) the model. Basically, you would split your traing dataset into 2 separate parts: one for the actural fine-tuning (training) and the other smaller one for test. So you evaluate the fine-tuned model on that separate test set to assess its performance.

General Steps for Fine-tuning a Pre-trained Model

Fine-tuning a large language model involves training a pre-trained model on a specific dataset related to your task or domain. Keep in mind that the specific implementation might vary depending on the library or framework you are using. Here is an outline of general steps to hopefully guide you through the process.

  1. Choose a Pre-trained Model: Select a pre-trained language model that suits your needs. Popular choices include OpenAI's GPT models, BERT, RoBERTa, etc.

  2. Set Up Environment: Install the necessary libraries and frameworks. For example, if you're using TensorFlow or PyTorch, install the relevant packages.

  3. Prepare Your Dataset: Format your dataset to match the input requirements of the pre-trained model. This often involves tokenizing and encoding text data. For example, there are many python libraries that provide the tokenizing tools,

  1. Fine-tuning Configuration: Define hyperparameters such as learning rate, batch size, and the number of training epochs. These may vary based on your specific task.

  2. Model Modification: Depending on your task, you may need to modify the architecture of the pre-trained model. For example, you may have to adapt the output layer to match your desired outputs that are required by the specific domain or tasks.

  3. Fine-tuning Model: Start the fine-tuning process using your prepared dataset. Monitor training metrics and adjust hyperparameters if needed.

  4. Evaluation: Evaluate the fine-tuned model on a validation set or a separate test set to assess its performance.

  5. Save Fine-tuned Model: Once you are satisfied with the performance from the evaluation, save the weights and configurations of the fine-tuned model for later use.

Last but not the least, fast-bert might be a good jump start to get your hands dirty.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.