Git Product home page Git Product logo

instruction-tuning-with-rag-example's Introduction

목적

이 코드는 Stanford Alpaca를 기반으로, 데이터 생성, 학습, 평가까지 밑바닥부터 Instruction Tuning을 실습해보는 코드입니다.
참조 논문과 깃허브들은 링크가 걸려있으니, 되도록 원본 문서를 같이 보면서 학습해보면 큰 도움이 될 것 같습니다.

목차

개요
예제 모델
코드 트리
훈련 스펙
Colab 가이드
참조

개요

이 예제 코드 크게 3가지로 구성되어 있습니다.

  1. OpenAI의 GPT API를 통해 데이터를 생성합니다.
  2. 생성한 데이터로 gemma-2b-it 모델을 Fine-Tuning합니다.
  3. 학습한 모델을 LLM으로 평가합니다.

예제 모델

예제 모델은 https://huggingface.co/aiqwe/gemma-2b-it-example-v1를 참조해주세요.

코드 트리

코드의 구성은 다음과 같습니다.

  • utils.py, similarity.py, prompts.py를 커스텀 모듈로 import하여 사용합니다.
  • 데이터 생성과 학습, 평가는 주피터 노트북으로 실행합니다.

preprocess.ipynb
데이터를 전처리하는 과정을 담았습니다. 데이터 생성은 gpt-4-turbo와 gpt-4o API를 사용하였습니다.
(데이터를 개선시키는 막바지에 gpt-4o가 출시되어 원가 절감에 큰 도움이 되었습니다 😆)
preprocess.ipynb 코드는 로컬에서 실행할 수 있게 작성되었습니다.(Colab에서는 별도의 설정으로 사용해야합니다.)

train.ipynb
Dataset 생성 등 데이터 준비과정과 LoRA학습등 Training코드가 담겨 있습니다.
train.ipynb 코드는 Google Colab에서 실행될 수 있게 작성되었습니다.

evaluation.ipynb
LLM으로 부터 Evaluation을 받는 코드가 담겨 있습니다. �evaluation.ipynb 코드는 Google Colab에서 실행될 수 있게 작성되었습니다.

훈련 스펙

학습은 쉽게 실험해 볼 수 있도록 Google Colab을 사용했으며, 예제 모델의 훈련시 스펙은 아래와 같습니다.

구분 내용
환경 Google Colab
GPU L4(22.5GB)
사용 VRAM 약 13.8GB
dtype bfloat16
Attention flash attention2
Tuning Lora(r=4, alpha=32)
Learning Rate 1e-4
LRScheduler Cosine
Optimizer adamw_torch_fused
batch_size 4
gradient_accumulation_steps 2

Colab 가이드

Colab에서 실행하기위해 colab_guide.md를 참조해주세요.

참조

깃허브 및 가이드

논문

instruction-tuning-with-rag-example's People

Contributors

aiqwe avatar

Stargazers

이대겸 avatar Woocheol Cho avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.