Views
No views yet
!pip install --upgrade \
"transformers==4.36.2" \
"datasets==2.16.1" \
"accelerate==0.26.1" \
"evaluate==0.4.1" \
"bitsandbytes==0.42.0" \
# "trl==0.7.10" # \
# "peft==0.7.1" \
# install peft & trl from github
!pip install git+https://github.com/huggingface/trl@a3c5b7178ac4f65569975efadc97db2f3749c65e --upgrade
!pip install git+https://github.com/huggingface/peft@4a1559582281fc3c9283892caea8ccef1d6f5a4f --upgrade
import torch; assert torch.cuda.get_device_capability()[0] >= 8, 'Hardware not supported for Flash Attention'
# install flash-attn
!pip install ninja packaging
!MAX_JOBS=4 pip install flash-attn --no-build-isolation1import torch
2from peft import PeftModel
3from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
4model_path = "meta-llama/Llama-2-7b-chat-hf"
5peft_path = "jhlim8/ListenerLM"
6
7# needed for access to llama 2, can just directly apply here https://huggingface.co/meta-llama/Llama-2-7b
8# and then get the token from https://huggingface.co/settings/tokens
9huggingface_token = ''
10
11bnb_config = BitsAndBytesConfig(
12 load_in_4bit = True,
13 bnb_4bit_quant_type="nf4",
14 bnb_4bit_compute_dtype=torch.bfloat16,
15 bnb_4bit_use_double_quant = True
16)
17model = AutoModelForCausalLM.from_pretrained(
18 model_path,
19 quantization_config=bnb_config,
20 attn_implementation="flash_attention_2",
21 device_map={'':'cuda:0'}, # have to specifically set each layer to device 0 when training with single gpu (sus i know)
22 torch_dtype=torch.bfloat16,
23 token=huggingface_token
24)
25model = PeftModel.from_pretrained(model, peft_path, is_trainable=False, token=huggingface_token)
26model.to("cuda:0")
27model.eval()
28tok = AutoTokenizer.from_pretrained(peft_path, token=huggingface_token)