SungJoo commited on
Commit
f7c47db
1 Parent(s): 58dd169

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +22 -3
README.md CHANGED
@@ -48,10 +48,29 @@ While this model aims to reduce toxicity, it may still generate biased or harmfu
48
  Use the code below to get started with the model:
49
 
50
  ```python
51
- from transformers import AutoTokenizer, AutoModelForCausalLM
 
52
 
53
- tokenizer = AutoTokenizer.from_pretrained("SungJoo/llama2-7b-sft-dpo-detox")
54
- model = AutoModelForCausalLM.from_pretrained("SungJoo/llama2-7b-sft-dpo-detox")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  ```
56
 
57
  ## Training Details
 
48
  Use the code below to get started with the model:
49
 
50
  ```python
51
+ import torch
52
+ from transformers import AutoTokenizer, AutoPeftModelForCausalLM
53
 
54
+ # Set device
55
+ DEV = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
56
+
57
+ # Set model and tokenizer path
58
+ adapter_path = "SungJoo/llama2-7b-sft-detox-DPO"
59
+
60
+ # Load model
61
+ model = AutoPeftModelForCausalLM.from_pretrained(
62
+ adapter_path,
63
+ torch_dtype=torch.bfloat16
64
+ ).to(DEV)
65
+
66
+ # Load tokenizer
67
+ tokenizer = AutoTokenizer.from_pretrained(adapter_path)
68
+
69
+ # Example usage
70
+ input_text = "Your input text here"
71
+ inputs = tokenizer(input_text, return_tensors="pt").to(DEV)
72
+ outputs = model.generate(**inputs)
73
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
74
  ```
75
 
76
  ## Training Details