LoRA weights only and trained for research - nothing from the foundation model. Trained using Open-Assistant's dataset. Shout-out to Open-Assistant and LAION for giving us early research access to the dataset.
1import torch
2import os
3import transformers
4from peft import PeftModel
5from transformers import LlamaTokenizer, LlamaForCausalLM
6
7model_path = "decapoda-research/llama-30b-hf"
8peft_path = 'serpdotai/llama-oasst-lora-30B'
9tokenizer_path = 'decapoda-research/llama-30b-hf'
10
11model = LlamaForCausalLM.from_pretrained(model_path, load_in_8bit=True, device_map="auto") # or something like {"": 0}
12model = PeftModel.from_pretrained(model, peft_path, torch_dtype=torch.float16, device_map="auto") # or something like {"": 0}
13tokenizer = LlamaTokenizer.from_pretrained(tokenizer_path)
14
15batch = tokenizer("\n\nUser: Are you sentient?\n\nAssistant:", return_tensors="pt")
16
17with torch.no_grad():
18 out = model.generate(
19 input_ids=batch["input_ids"].cuda(),
20 attention_mask=batch["attention_mask"].cuda(),
21 max_length=100,
22 do_sample=True,
23 top_k=50,
24 top_p=1.0,
25 temperature=1.0
26 )
27print(tokenizer.decode(out[0]))
The model will continue the conversation between the user and itself. If you want to use as a chatbot you can alter the generate method to include stop sequences for 'User:' and 'Assistant:' or strip off anything past the assistant's original response before returning.
Trained for 4 epochs with a sequence length of 2048 on 8 A6000s with an effective batch size of 120.
1lr: 2.0e-04
2lr_scheduler_type: linear
3warmup_ratio: 0.06
4weight_decay: 0.1
5optimizer: adamw_torch
6LoRA config:
7
8target_modules: ['q_proj', 'k_proj', 'v_proj', 'o_proj']
9r: 64
10lora_alpha: 32
11lora_dropout: 0.05
12bias: "none"
13task_type: "CAUSAL_LM"