CoolFace
Modelpublic

argilla/phi2-lora-distilabel-intel-orca-dpo-pairs

sourceHugging Facemitupdated 3y agoView on Hugging Face
2likes13downloads
Model Card

<!-- This model card has been generated automatically according to the information the Trainer had access to. You should probably proofread and complete it, then remove this comment. -->

phi2-lora-quantized-distilabel-intel-orca-dpo-pairs

This model is a fine-tuned version of microsoft/phi-2 on distilabel-intel-orca-dpo-pairs. The full training notebook can be found here.

It achieves the following results on the evaluation set:

  • —Loss: 0.4537
  • —Rewards/chosen: -0.0837
  • —Rewards/rejected: -1.2628
  • —Rewards/accuracies: 0.8301
  • —Rewards/margins: 1.1791
  • —Logps/rejected: -224.8409
  • —Logps/chosen: -203.2228
  • —Logits/rejected: 0.4773
  • —Logits/chosen: 0.3062

Model description

The adapter was fine-tuned on a Google Colab A100 GPU using DPO and the distilabel-intel-orca-dpo-pairs. In order to scale LoRa approached for LLMs, I recommend looking at predibase/lorax.

You can play around with the model shown below. We load the LoRa adapter and bitsnbytes config (only when CUDA is available).

python
import torch
import torch
from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    BitsAndBytesConfig
)
from peft import PeftModel

# template used for fine-tune
# template = """\
# Instruct: {instruction}\n
# Output: {response}"""

if torch.cuda.is_available():
    device = torch.device("cuda")
    print(f"Using {torch.cuda.get_device_name(0)}")
    bnb_config = BitsAndBytesConfig(
        load_in_4bit=True,
        bnb_4bit_quant_type='nf4',
        bnb_4bit_compute_dtype='float16',
        bnb_4bit_use_double_quant=False,
    )
elif torch.backends.mps.is_available():
    device = torch.device("mps")
    bnb_config = None
else:
    device = torch.device("cpu")
    bnb_config = None
    print("No GPU available, using CPU instead.")

config = PeftConfig.from_pretrained("davidberenstein1957/phi2-lora-quantized-distilabel-intel-orca-dpo-pairs")
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype=torch.float16, quantization_config=bnb_config)
model = PeftModel.from_pretrained(model, "davidberenstein1957/phi2-lora-quantized-distilabel-intel-orca-dpo-pairs").to(device)

prompt = "Instruct: What is the capital of France? \nOutput:""
inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=False)

outputs = model.generate(**inputs)
text = tokenizer.batch_decode(outputs)[0]

Intended uses & limitations

This is a LoRa adapter fine-tine for phi-2 and not a full fine-tune of the model. Additionally, I did not spend time updating parameters.

Training and evaluation data

The adapter was fine-tuned on a Google Colab A100 GPU using DPO and the distilabel-intel-orca-dpo-pairs. The full training notebook can be found here. Underneath, there are some configs for the adapter and the trainer.

python
peft_config = LoraConfig(
    lora_alpha=16,
    lora_dropout=0.5,
    r=32,
    target_modules=['k_proj', 'q_proj', 'v_proj', 'fc1', 'fc2'],
    bias="none",
    task_type="CAUSAL_LM",
)
python
training_arguments = TrainingArguments(
    output_dir=f"./{model_name}",
    evaluation_strategy="steps",
    do_eval=True,
    optim="paged_adamw_8bit",
    per_device_train_batch_size=2,
    gradient_accumulation_steps=16,
    per_device_eval_batch_size=2,
    log_level="debug",
    save_steps=20,
    logging_steps=20,
    learning_rate=1e-5,
    eval_steps=20,
    num_train_epochs=1, # Modified for tutorial purposes
    max_steps=100,
    warmup_steps=20,
    lr_scheduler_type="linear",
)

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • —learning_rate: 1e-05
  • —trainbatchsize: 2
  • —evalbatchsize: 2
  • —seed: 42
  • —gradientaccumulationsteps: 16
  • —totaltrainbatch_size: 32
  • —optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • —lrschedulertype: linear
  • —lrschedulerwarmup_steps: 20
  • —num_epochs: 1

Training results

Training LossEpochStepValidation LossRewards/chosenRewards/rejectedRewards/accuraciesRewards/marginsLogps/rejectedLogps/chosenLogits/rejectedLogits/chosen
0.68530.06200.67010.0133-0.03680.69050.0501-212.5803-202.25220.38530.2532
0.63120.12400.58840.0422-0.22080.81380.2630-214.4207-201.96380.42540.2816
0.5470.19600.51460.0172-0.57860.82780.5958-217.9983-202.21320.46990.3110
0.43880.25800.4893-0.0808-1.07890.82930.9981-223.0014-203.19340.51580.3396
0.48710.311000.4818-0.1298-1.23460.82971.1048-224.5586-203.68370.51330.3340
0.48630.371200.4723-0.1230-1.17180.83011.0488-223.9305-203.61590.49100.3167
0.45780.441400.4666-0.1257-1.17720.83011.0515-223.9844-203.64280.47950.3078
0.45870.51600.4625-0.0746-1.12720.83011.0526-223.4841-203.13100.48570.3139
0.46880.561800.4595-0.0584-1.11940.82971.0610-223.4062-202.96920.48900.3171
0.41890.622000.4579-0.0666-1.16470.82971.0982-223.8598-203.05110.48580.3138
0.43920.682200.4564-0.0697-1.19150.83011.1219-224.1278-203.08230.48240.3110
0.46590.752400.4554-0.0826-1.22450.83011.1419-224.4574-203.21120.47610.3052
0.40750.812600.4544-0.0823-1.23280.83011.1504-224.5403-203.20890.47490.3044
0.40150.872800.4543-0.0833-1.25900.83011.1757-224.8026-203.21880.47790.3067
0.43650.933000.4539-0.0846-1.26580.83011.1812-224.8702-203.23130.47800.3067
0.45891.03200.4537-0.0837-1.26280.83011.1791-224.8409-203.22280.47730.3062

Framework versions

  • —PEFT 0.7.1
  • —Transformers 4.37.1
  • —Pytorch 2.1.0+cu121
  • —Datasets 2.16.1
  • —Tokenizers 0.15.1