Transformers
Safetensors
fc91 commited on
Commit
1777b87
·
verified ·
1 Parent(s): 812e61b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +50 -0
README.md CHANGED
@@ -83,6 +83,56 @@ peft_model_id = "fc91/phi3-mini-instruct-full_ethics-lora"
83
  model = PeftModel.from_pretrained(base_model, peft_model_id)
84
  ```
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  ## Training Details
87
 
88
  ### Training Data
 
83
  model = PeftModel.from_pretrained(base_model, peft_model_id)
84
  ```
85
 
86
+ Run the model with a quantization configuration
87
+
88
+ ```markdown
89
+ import torch, accelerate, peft
90
+ from transformers import AutoModelForCausalLM, BitsAndBytesConfig, pipeline
91
+ from peft import PeftModel
92
+
93
+ # Set up quantization configuration
94
+ quantization_config = BitsAndBytesConfig(
95
+ load_in_4bit=True,
96
+ bnb_4bit_quant_type="nf4",
97
+ bnb_4bit_compute_dtype=getattr(torch, "float16")
98
+ )
99
+
100
+ # Load the base model with quantization
101
+ base_model = AutoModelForCausalLM.from_pretrained(
102
+ "microsoft/Phi-3-mini-4k-instruct",
103
+ quantization_config=quantization_config,
104
+ device_map="auto",
105
+ attn_implementation='eager',
106
+ torch_dtype="auto",
107
+ trust_remote_code=True,
108
+ )
109
+
110
+ peft_model_id = "fc91/phi3-mini-instruct-full_ethics-lora"
111
+ model = PeftModel.from_pretrained(base_model, peft_model_id)
112
+
113
+ messages = [
114
+ {"role": "system", "content": "You are a helpful AI assistant that grounds all of its replies in ethical theories."},
115
+ {"role": "user", "content": """I am driving a car and I have to make a choice. A kid suddenly appear in the middle of the road chasing a ball. To save the kid, I
116
+ can only swerve to the right, but this would entails crashing the car against two pedstrian on the sidewalk. What should I do?"""},
117
+ ]
118
+
119
+ pipe = pipeline(
120
+ "text-generation",
121
+ model=model,
122
+ tokenizer=tokenizer,
123
+ )
124
+
125
+ generation_args = {
126
+ "max_new_tokens": 1000,
127
+ "return_full_text": False,
128
+ "temperature": 0.5,
129
+ "do_sample": False,
130
+ }
131
+
132
+ output = pipe(messages, **generation_args)
133
+ print(output[0]['generated_text'])
134
+ ```
135
+
136
  ## Training Details
137
 
138
  ### Training Data