Views
No views yet
1!pip install -q -U bitsandbytes
2!pip install -q -U git+https://github.com/huggingface/transformers.git
3!pip install -q -U git+https://github.com/huggingface/peft.git1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
4model_id = "EleutherAI/gpt-neox-20b"
5bnb_config = BitsAndBytesConfig(
6 load_in_4bit=True,
7 bnb_4bit_use_double_quant=True,
8 bnb_4bit_quant_type="nf4",
9 bnb_4bit_compute_dtype=torch.bfloat16
10)
11
12tokenizer = AutoTokenizer.from_pretrained(model_id)
13model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config, device_map={"":0})1from peft import LoraConfig, get_peft_model
2
3lora_config = LoraConfig.from_pretrained('suarkadipa/gpt-neox-20b-Medical-reports-Splits')
4model = get_peft_model(model, lora_config)1text = "The lungs "
2device = "cuda:0"
3
4inputs = tokenizer(text, return_tensors="pt").to(device)
5outputs = model.generate(**inputs, max_new_tokens=100)
6print(tokenizer.decode(outputs[0], skip_special_tokens=True))
7
8#output example: The lungs are the organs that are most affected by the disease. The disease can cause the lungs to become inflamed, which can lead to pneumonia.