1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| from datasets import load_dataset train_dataset = load_dataset("tatsu-lab/alpaca", split="train") train_dataset
print(train_dataset[0]) print(train_dataset[0]['text'])
print(tokenizer) print(model.model.embed_tokens) model.resize_token_embeddings(len(tokenizer))
from peft import LoraConfig, get_peft_model, prepare_model_for_int8_training model = prepare_model_for_int8_training(model) peft_config = LoraConfig(r=16, lora_alpha=32, lora_dropout=0.05, bias="none", task_type="CAUSAL_LM") model = get_peft_model(model, peft_config) training_args = TrainingArguments( output_dir="xgen-7b-tuned-alpaca-l1", per_device_train_batch_size=4, optim="adamw_torch", logging_steps=10, learning_rate=2e-4, fp16=True, warmup_ratio=0.1, lr_scheduler_type="linear", num_train_epochs=1, save_strategy="epoch", push_to_hub=False, ) trainer = SFTTrainer( model=model, train_dataset=train_dataset, dataset_text_field="text", max_seq_length=1024, tokenizer=tokenizer, args=training_args, packing=True, peft_config=peft_config, ) trainer.train()
|