spring cleaning
Browse filesFiles changed (3)
- alpaca-loraDeleted-1
- requirements.txtAdded+53
- train.pyAdded+117
1Subproject commit 8bb8579e403dc78e37fe81ffbb253c413007323f1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253accelerate==0.18.0aiohttp==3.8.4aiosignal==1.3.1altgraph @ 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.whlasync-timeout==4.0.2attrs==23.1.0beautifulsoup4==4.12.2bitsandbytes==0.38.1certifi==2022.9.24charset-normalizer==2.1.1datasets==2.11.0dill==0.3.6Faker==18.4.0filelock==3.12.0frozenlist==1.3.3fsspec==2023.4.0future @ 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.whlhuggingface-hub==0.13.4idna==3.4Jinja2==3.1.2loralib==0.1.1macholib @ 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.whlMarkupSafe==2.1.2mpmath==1.3.0multidict==6.0.4multiprocess==0.70.14networkx==3.1numpy==1.24.2packaging==23.1pandas==2.0.0peft @ git+https://github.com/huggingface/peft.git@2822398fbe896f25d4dac5e468624dc5fd65a51bpsutil==5.9.5pyarrow==11.0.0python-dateutil==2.8.2pytz==2023.3PyYAML==6.0regex==2023.3.23requests==2.28.1responses==0.18.0sentencepiece==0.1.98six @ 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.whlslack-sdk==3.19.1soupsieve==2.4.1sympy==1.11.1tokenizers==0.13.3torch==2.0.0tqdm==4.65.0transformers @ git+https://github.com/zphang/transformers@c3dc391da81e6ed7efce42be06413725943b3920typing_extensions==4.5.0tzdata==2023.3urllib3==1.26.12xxhash==3.2.0yarl==1.9.1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117import osimport torchimport torch.nn as nnimport torch.distributed as distimport torch.multiprocessing as mpimport bitsandbytes as bnbfrom datasets import load_datasetimport transformersfrom transformers import AutoTokenizer, AutoConfig, LLaMAForCausalLM, LLaMATokenizerfrom peft import prepare_model_for_int8_training, LoraConfig, get_peft_model
def setup(rank, world_size): os.environ['MASTER_ADDR'] = 'localhost' os.environ['MASTER_PORT'] = '12355'
# Initialize the process group dist.init_process_group("nccl", rank=rank, world_size=world_size)
def cleanup(): dist.destroy_process_group()
def train(rank, world_size): setup(rank, world_size)
# os.system("nvidia-smi") # os.system("git clone https://github.com/tloen/alpaca-lora.git") # os.chdir("alpaca-lora/") # os.system("pip install -q datasets loralib sentencepiece") # os.system("pip uninstall -y transformers") # os.system("pip install -q git+https://github.com/zphang/transformers@c3dc391") # os.system("pip install -q git+https://github.com/huggingface/peft.git") # os.system("pip install bitsandbytes")
# os.system("conda install -y -c conda-forge cudatoolkit")
MICRO_BATCH_SIZE = 8 BATCH_SIZE = 128 GRADIENT_ACCUMULATION_STEPS = BATCH_SIZE // MICRO_BATCH_SIZE EPOCHS = 2 LEARNING_RATE = 2e-5 LORA_R = 4 LORA_ALPHA = 16 LORA_DROPOUT = 0.05
device = torch.device(f"cuda:{rank}") model = LLaMAForCausalLM.from_pretrained( "decapoda-research/llama-7b-hf", load_in_8bit=True, device_map="auto", ).to(device) model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[rank], output_device=rank) tokenizer = LLaMATokenizer.from_pretrained( "decapoda-research/llama-7b-hf", add_eos_token=True )
model = prepare_model_for_int8_training(model.module)
config = LoraConfig( r=LORA_R, lora_alpha=LORA_ALPHA, target_modules=["q_proj", "v_proj"], lora_dropout=LORA_DROPOUT, bias="none", task_type="CAUSAL_LM", ) model.module = get_peft_model(model.module, config) tokenizer.pad_token_id = 0 data = load_dataset("json", data_files="../samples.json")
def generate_prompt(data_point): if data_point["input"]: return f"""### Instruction: {data_point["instruction"]} ### Input: {data_point["input"]} ### Response: {data_point["output"]}""" else: return f"""### Instruction: {data_point["instruction"]} ### Response: {data_point["output"]}"""
data = data.shuffle().map( lambda data_point: tokenizer( generate_prompt(data_point), truncation=False, padding='longest', ) )
trainer = transformers.Trainer( model=model, train_dataset=data["train"], args=transformers.TrainingArguments( per_device_train_batch_size=MICRO_BATCH_SIZE, gradient_accumulation_steps=GRADIENT_ACCUMULATION_STEPS, warmup_steps=100, num_train_epochs=EPOCHS, learning_rate=LEARNING_RATE, fp16=True, logging_steps=1, output_dir=f"lora-smartscraper-{rank}", save_total_limit=3, ), data_collator=transformers.DataCollatorForLanguageModeling(tokenizer, mlm=False), ) model.config.use_cache = False trainer.train(resume_from_checkpoint=False)
model.save_pretrained(f"lora-smartscraper-{rank}")
cleanup()
if __name__ == "__main__": world_size = torch.cuda.device_count() mp.spawn(train, args=(world_size,), nprocs=world_size, join=True)alpaca-loraDeleted-1
requirements.txtAdded+53
train.pyAdded+117