Views
No views yet
ml.g5.48xlarge instances from AWS (NVIDIA A10G GPU x 32ea). For pre-training, we used a sample set from Wikipedia.
Note that performance is not guaranteed since only a small number of datasets were used for the experiment. The number of samples for training set is just around 1.5 million after tokenization.
For distributed training, all weights were trained without adapter techniques, and sharding parallelization was performed with ZeRO-2. The presets are as follows.1{
2 "fp16": {
3 "enabled": "auto",
4 "loss_scale": 0,
5 "loss_scale_window": 1000,
6 "initial_scale_power": 16,
7 "hysteresis": 2,
8 "min_loss_scale": 1
9 },
10
11 "bf16": {
12 "enabled": "auto"
13 },
14
15 "optimizer": {
16 "type": "AdamW",
17 "params": {
18 "lr": "auto",
19 "betas": "auto",
20 "eps": "auto",
21 "weight_decay": "auto"
22 }
23 },
24
25 "scheduler": {
26 "type": "WarmupLR",
27 "params": {
28 "warmup_min_lr": "auto",
29 "warmup_max_lr": "auto",
30 "warmup_num_steps": "auto"
31 }
32 },
33
34 "zero_optimization": {
35 "stage": 2,
36 "allgather_partitions": true,
37 "allgather_bucket_size": 2e8,
38 "overlap_comm": true,
39 "reduce_scatter": true,
40 "reduce_bucket_size": 2e8,
41 "contiguous_gradients": true,
42 "cpu_offload": true
43 },
44
45 "gradient_accumulation_steps": "auto",
46 "gradient_clipping": "auto",
47 "train_batch_size": "auto",
48 "train_micro_batch_size_per_gpu": "auto"
49}batch_size: 2
num_epochs: 1
learning_rate: 3e-4
gradient_accumulation_steps: 8
lr_scheduler_type: "linear"
group_by_length: Falseml.g5.24xlarge (NVIDIA A10G GPU x 4ea). The dataset used for instruction tuning is a sample set of the OpenOrca dataset, and the dataset used for alignment tuning is Intel's orca_dpo_pairs dataset.
All fine-tuning was learned using QLoRA, and the batch sizes were set to 3 and 1, respectively. We used 1,024 for the context length. 2,048 is also possible, but applying DPO often runs out of memory on 24GB GPU memory, so we settled on 1,024.
Please see below for relevant code snippets.1peft_config = LoraConfig(
2 r=8,
3 lora_alpha=16,
4 target_modules=["q_proj", "k_proj", "v_proj", "fc1", "fc2"],
5 lora_dropout=0.05,
6 bias="none",
7 task_type="CAUSAL_LM",
8)
9training_arguments = TrainingArguments(
10 output_dir="logs",
11 num_train_epochs=1,
12 per_device_train_batch_size=batch_size,
13 gradient_accumulation_steps=4,
14 optim="paged_adamw_8bit",
15 learning_rate=3e-4,
16 weight_decay=0.001,
17 bf16=True,
18 max_grad_norm=0.3,
19 max_steps=-1,
20 warmup_ratio=0.03,
21 group_by_length=True,
22 lr_scheduler_type="cosine",
23 report_to="wandb", ...
24)1def create_inference_prompt(text):
2 string = f"""<|im_start|>system
3You are a helpful AI assistant.<|im_end|>
4<|im_start|>user
5{text}<|im_end|>
6<|im_start|>assistant
7"""
8 return string1from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
2import torch
3torch.set_default_device("cuda")
4model_path = "daekeun-ml/phi-2-upscaled-4B-instruct-v0.1"
5
6model = AutoModelForCausalLM.from_pretrained(
7 model_path,
8 torch_dtype="auto",
9 trust_remote_code=True)
10
11tokenizer = AutoTokenizer.from_pretrained(
12 model_path,
13 use_fast=True,
14 trust_remote_code=True
15)
16
17# Format prompt
18message = [
19 {"role": "system", "content": "You are a helpful AI assistant. Generate appropriate answers to given questions."},
20 {"role": "user", "content": "What is a Large Language Model?"}
21]
22
23prompt = tokenizer.apply_chat_template(message, add_generation_prompt=True, tokenize=False)
24inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=False)
25
26outputs = model.generate(**inputs, max_new_tokens=200, do_sample=True, top_p=0.9, temperature=0.5, repetition_penalty=1.2)
27text = tokenizer.batch_decode(outputs)[0]
28print(text)