Transformers documentation

Unsloth

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v5.22.2).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Unsloth

Unsloth은 대규모 언어 모델의 학습 속도를 높이고 메모리 사용량을 줄이는 파인튜닝 및 강화 학습 프레임워크입니다. 커스텀 RoPE와 Triton 커널을 지원하여 4-bit, 8-bit, 16-bit 정밀도로 학습할 수 있습니다. Unsloth는 Llama, Mistral, Gemma, Qwen 및 기타 모델 계열과 함께 사용할 수 있습니다.

from datasets import load_dataset
from transformers import TrainingArguments
from unsloth import FastLanguageModel
from unsloth.trainer import UnslothTrainer

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="unsloth/Llama-3.2-1B-Instruct",
    max_seq_length=2048,
    load_in_4bit=True,
)

model = FastLanguageModel.get_peft_model(
    model,
    r=16,
    lora_alpha=16,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"],
)

dataset = load_dataset("trl-lib/Capybara", split="train[:500]")
dataset = dataset.map(lambda x: {"text": x["conversations"][0]["value"]})

trainer = UnslothTrainer(
    model=model,
    tokenizer=tokenizer,
    train_dataset=dataset,
    dataset_text_field="text",
    max_seq_length=2048,
    args=TrainingArguments(
        output_dir="outputs",
        per_device_train_batch_size=2,
        num_train_epochs=1,
    ),
)

trainer.train()

Transformers 통합

Unsloth은 Transformers API를 래핑하고 내부 메서드를 패치하여 속도를 높입니다.

리소스

Update on GitHub