DDDano333 commited on
Commit
53d6231
·
1 Parent(s): e10b136

spring cleaning

Browse files
Files changed (3) hide show
  1. alpaca-lora +0 -1
  2. requirements.txt +53 -0
  3. train.py +117 -0
alpaca-lora DELETED
@@ -1 +0,0 @@
1
- Subproject commit 8bb8579e403dc78e37fe81ffbb253c413007323f
 
 
requirements.txt ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ accelerate==0.18.0
2
+ aiohttp==3.8.4
3
+ aiosignal==1.3.1
4
+ altgraph @ file:///System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot2/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/python3/python3-124/altgraph-0.17.2-py2.py3-none-any.whl
5
+ async-timeout==4.0.2
6
+ attrs==23.1.0
7
+ beautifulsoup4==4.12.2
8
+ bitsandbytes==0.38.1
9
+ certifi==2022.9.24
10
+ charset-normalizer==2.1.1
11
+ datasets==2.11.0
12
+ dill==0.3.6
13
+ Faker==18.4.0
14
+ filelock==3.12.0
15
+ frozenlist==1.3.3
16
+ fsspec==2023.4.0
17
+ future @ file:///System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot2/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/python3/python3-124/future-0.18.2-py3-none-any.whl
18
+ huggingface-hub==0.13.4
19
+ idna==3.4
20
+ Jinja2==3.1.2
21
+ loralib==0.1.1
22
+ macholib @ file:///System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot2/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/python3/python3-124/macholib-1.15.2-py2.py3-none-any.whl
23
+ MarkupSafe==2.1.2
24
+ mpmath==1.3.0
25
+ multidict==6.0.4
26
+ multiprocess==0.70.14
27
+ networkx==3.1
28
+ numpy==1.24.2
29
+ packaging==23.1
30
+ pandas==2.0.0
31
+ peft @ git+https://github.com/huggingface/peft.git@2822398fbe896f25d4dac5e468624dc5fd65a51b
32
+ psutil==5.9.5
33
+ pyarrow==11.0.0
34
+ python-dateutil==2.8.2
35
+ pytz==2023.3
36
+ PyYAML==6.0
37
+ regex==2023.3.23
38
+ requests==2.28.1
39
+ responses==0.18.0
40
+ sentencepiece==0.1.98
41
+ six @ file:///System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot2/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/python3/python3-124/six-1.15.0-py2.py3-none-any.whl
42
+ slack-sdk==3.19.1
43
+ soupsieve==2.4.1
44
+ sympy==1.11.1
45
+ tokenizers==0.13.3
46
+ torch==2.0.0
47
+ tqdm==4.65.0
48
+ transformers @ git+https://github.com/zphang/transformers@c3dc391da81e6ed7efce42be06413725943b3920
49
+ typing_extensions==4.5.0
50
+ tzdata==2023.3
51
+ urllib3==1.26.12
52
+ xxhash==3.2.0
53
+ yarl==1.9.1
train.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ import torch.nn as nn
4
+ import torch.distributed as dist
5
+ import torch.multiprocessing as mp
6
+ import bitsandbytes as bnb
7
+ from datasets import load_dataset
8
+ import transformers
9
+ from transformers import AutoTokenizer, AutoConfig, LLaMAForCausalLM, LLaMATokenizer
10
+ from peft import prepare_model_for_int8_training, LoraConfig, get_peft_model
11
+
12
+ def setup(rank, world_size):
13
+ os.environ['MASTER_ADDR'] = 'localhost'
14
+ os.environ['MASTER_PORT'] = '12355'
15
+
16
+ # Initialize the process group
17
+ dist.init_process_group("nccl", rank=rank, world_size=world_size)
18
+
19
+ def cleanup():
20
+ dist.destroy_process_group()
21
+
22
+ def train(rank, world_size):
23
+ setup(rank, world_size)
24
+
25
+ # os.system("nvidia-smi")
26
+ # os.system("git clone https://github.com/tloen/alpaca-lora.git")
27
+ # os.chdir("alpaca-lora/")
28
+ # os.system("pip install -q datasets loralib sentencepiece")
29
+ # os.system("pip uninstall -y transformers")
30
+ # os.system("pip install -q git+https://github.com/zphang/transformers@c3dc391")
31
+ # os.system("pip install -q git+https://github.com/huggingface/peft.git")
32
+ # os.system("pip install bitsandbytes")
33
+
34
+ # os.system("conda install -y -c conda-forge cudatoolkit")
35
+
36
+ MICRO_BATCH_SIZE = 8
37
+ BATCH_SIZE = 128
38
+ GRADIENT_ACCUMULATION_STEPS = BATCH_SIZE // MICRO_BATCH_SIZE
39
+ EPOCHS = 2
40
+ LEARNING_RATE = 2e-5
41
+ LORA_R = 4
42
+ LORA_ALPHA = 16
43
+ LORA_DROPOUT = 0.05
44
+
45
+ device = torch.device(f"cuda:{rank}")
46
+ model = LLaMAForCausalLM.from_pretrained(
47
+ "decapoda-research/llama-7b-hf",
48
+ load_in_8bit=True,
49
+ device_map="auto",
50
+ ).to(device)
51
+ model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[rank], output_device=rank)
52
+ tokenizer = LLaMATokenizer.from_pretrained(
53
+ "decapoda-research/llama-7b-hf", add_eos_token=True
54
+ )
55
+
56
+ model = prepare_model_for_int8_training(model.module)
57
+
58
+ config = LoraConfig(
59
+ r=LORA_R,
60
+ lora_alpha=LORA_ALPHA,
61
+ target_modules=["q_proj", "v_proj"],
62
+ lora_dropout=LORA_DROPOUT,
63
+ bias="none",
64
+ task_type="CAUSAL_LM",
65
+ )
66
+ model.module = get_peft_model(model.module, config)
67
+ tokenizer.pad_token_id = 0
68
+ data = load_dataset("json", data_files="../samples.json")
69
+
70
+ def generate_prompt(data_point):
71
+ if data_point["input"]:
72
+ return f"""### Instruction:
73
+ {data_point["instruction"]}
74
+ ### Input:
75
+ {data_point["input"]}
76
+ ### Response:
77
+ {data_point["output"]}"""
78
+ else:
79
+ return f"""### Instruction:
80
+ {data_point["instruction"]}
81
+ ### Response:
82
+ {data_point["output"]}"""
83
+
84
+ data = data.shuffle().map(
85
+ lambda data_point: tokenizer(
86
+ generate_prompt(data_point),
87
+ truncation=False,
88
+ padding='longest',
89
+ )
90
+ )
91
+
92
+ trainer = transformers.Trainer(
93
+ model=model,
94
+ train_dataset=data["train"],
95
+ args=transformers.TrainingArguments(
96
+ per_device_train_batch_size=MICRO_BATCH_SIZE,
97
+ gradient_accumulation_steps=GRADIENT_ACCUMULATION_STEPS,
98
+ warmup_steps=100,
99
+ num_train_epochs=EPOCHS,
100
+ learning_rate=LEARNING_RATE,
101
+ fp16=True,
102
+ logging_steps=1,
103
+ output_dir=f"lora-smartscraper-{rank}",
104
+ save_total_limit=3,
105
+ ),
106
+ data_collator=transformers.DataCollatorForLanguageModeling(tokenizer, mlm=False),
107
+ )
108
+ model.config.use_cache = False
109
+ trainer.train(resume_from_checkpoint=False)
110
+
111
+ model.save_pretrained(f"lora-smartscraper-{rank}")
112
+
113
+ cleanup()
114
+
115
+ if __name__ == "__main__":
116
+ world_size = torch.cuda.device_count()
117
+ mp.spawn(train, args=(world_size,), nprocs=world_size, join=True)