머신러닝/Tool

Unsloth: LLM을 빠르고 가볍게 사용할 수 있는 라이브러리

byoelcardi 2025. 4. 21. 18:21

Unsloth는 2025년 현재 가장 빠르고 효율적인 LLM(대규모 언어 모델) 파인튜닝 프레임워크 중 하나로, 특히 저사양 GPU 환경에서도 뛰어난 성능을 발휘합니다. 최근 업데이트를 통해 LLaMA 4, Gemma 3, Phi 4, Mistral 등 최신 모델을 지원하며, Flash Attention 2 대비 최대 30배 빠른 학습 속도와 최대 90%의 메모리 절감을 제공합니다 .

주소는 아래와 같습니다.

https://huggingface.co/unsloth/gemma-3-27b-it-GGUF

 

unsloth/gemma-3-27b-it-GGUF · Hugging Face

Gemma 3 model card Model Page: Gemma Resources and Technical Documentation: Terms of Use: Terms Authors: Google DeepMind Model Information Summary description and brief definition of inputs and outputs. Description Gemma is a family of lightweight, state-o

huggingface.co

 

위의 주소는 gemma3-27b 모델에 대한 huggingface 주소입니다.

 

Unsloth는 다음과 같은 기능을 제공합니다:

  • LoRA 및 QLoRA 지원: 4bit 및 16bit 양자화 지원으로 메모리 사용량 절감
  • 커스텀 GPU 커널: OpenAI의 Triton 언어로 작성된 커널을 통해 연산 최적화
  • 다양한 저장 형식 지원: GGUF, vLLM, Hugging Face Hub 등 다양한 형식으로 모델 저장 가능
  • 빠른 추론 속도: 학습뿐만 아니라 추론 속도도 최대 2배 향상

model을 추론하는 코드를 보면 아래와 같습니다.

from unsloth import FastModel
import torch

fourbit_models = [
    # 4bit dynamic quants for superior accuracy and low memory use
    "unsloth/gemma-3-1b-it-unsloth-bnb-4bit",
    "unsloth/gemma-3-4b-it-unsloth-bnb-4bit",
    "unsloth/gemma-3-12b-it-unsloth-bnb-4bit",
    "unsloth/gemma-3-27b-it-unsloth-bnb-4bit",

    # Other popular models!
    "unsloth/Llama-3.1-8B",
    "unsloth/Llama-3.2-3B",
    "unsloth/Llama-3.3-70B",
    "unsloth/mistral-7b-instruct-v0.3",
    "unsloth/Phi-4",
] # More models at https://huggingface.co/unsloth

model, tokenizer = FastModel.from_pretrained(
    model_name = "unsloth/gemma-3-4b-it",
    max_seq_length = 2048, # Choose any for long context!
    load_in_4bit = True,  # 4 bit quantization to reduce memory
    load_in_8bit = False, # [NEW!] A bit more accurate, uses 2x memory
    full_finetuning = False, # [NEW!] We have full finetuning now!
    # token = "hf_...", # use one if using gated models
)

 

자세한 Finetunning 코드는 아래 주소를 참고하시면 됩니다.

https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Gemma3_(4B).ipynb#scrollTo=LjY75GoYUCB8

 

단점은 리눅스, WSL과 같은 환경에서는 작동이 쉽지만 맥과 윈도우 같은 환경에서는 작동이 쉽지않다는 점인데요. 

이것이 해결되는 방안을 unsloth쪽에서 발표한다면 다시 블로그 포스팅 진행하겠습니다.

 

감사합니다!