Commit
•
884d1b9
1
Parent(s):
32e5b1f
Update README.md
Browse files
README.md
CHANGED
@@ -23,7 +23,45 @@ This model is a fine-tuned version of [google/gemma-7b](https://huggingface.co/g
|
|
23 |
The model was fine-tuned with the following [script using Lora (no, qlora)](https://huggingface.co/philschmid/gemma-7b-dolly-chatml/blob/main/trl-lora.py). I also included a [inference script](https://huggingface.co/philschmid/gemma-7b-dolly-chatml/blob/main/inference.py) to make sure it works since there were some issues with Gemma. Results of the inference test are
|
24 |
|
25 |
```bash
|
|
|
|
|
|
|
|
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
```
|
28 |
|
29 |
|
|
|
23 |
The model was fine-tuned with the following [script using Lora (no, qlora)](https://huggingface.co/philschmid/gemma-7b-dolly-chatml/blob/main/trl-lora.py). I also included a [inference script](https://huggingface.co/philschmid/gemma-7b-dolly-chatml/blob/main/inference.py) to make sure it works since there were some issues with Gemma. Results of the inference test are
|
24 |
|
25 |
```bash
|
26 |
+
prompt:
|
27 |
+
What is the capital of Germany? Explain why thats the case and if it was different in the past?
|
28 |
+
response:
|
29 |
+
Berlin is the capital of Germany. It was the capital of Prussia until 1918, when the monarchy was abolished. It was also the capital of the Weimar Republic. It was the capital of the Third Reich until 1945, when it was liberated by the allies. It has been the capital of the Federal Republic of Germany since 1949. It is the largest city in the country with a population of 3.6 million people. It is also the seat of the government and parliament.
|
30 |
|
31 |
+
prompt:
|
32 |
+
In a town, 60% of the population are adults. Among the adults, 30% have a pet dog and 40% have a pet cat. What percentage of the total population has a pet dog?
|
33 |
+
response:
|
34 |
+
60% of the total population have a pet dog. The calculation is 30% of adults multiplied by 60% of the total population. 30% of adults is 18% of the total population and 18% multiplied by 60% is 10.8% or 60% of the total population.
|
35 |
+
```
|
36 |
+
|
37 |
+
### Run inference
|
38 |
+
|
39 |
+
```python
|
40 |
+
import torch
|
41 |
+
from peft import AutoPeftModelForCausalLM
|
42 |
+
from transformers import AutoTokenizer, pipeline
|
43 |
+
|
44 |
+
peft_model_id = "philschmid/gemma-7b-dolly-chatml"
|
45 |
+
|
46 |
+
# Load Model with PEFT adapter
|
47 |
+
tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
|
48 |
+
model = AutoPeftModelForCausalLM.from_pretrained(peft_model_id, device_map="auto", torch_dtype=torch.float16)
|
49 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
50 |
+
eos_token = tokenizer("<|im_end|>",add_special_tokens=False)["input_ids"][0]
|
51 |
+
print(f"eos_token: {eos_token}")
|
52 |
+
|
53 |
+
# run inference
|
54 |
+
messages = [
|
55 |
+
{
|
56 |
+
"role": "user",
|
57 |
+
"content": "What is the capital of Germany? Explain why thats the case and if it was different in the past?"
|
58 |
+
}
|
59 |
+
]
|
60 |
+
|
61 |
+
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
62 |
+
outputs = pipe(prompt, max_new_tokens=1024, do_sample=True, temperature=0.7, top_k=50, top_p=0.95, eos_token_id=eos_token)
|
63 |
+
print(outputs[0]['generated_text'][len(prompt):])
|
64 |
+
# Berlin is the capital of Germany. It was the capital of Prussia until 1918, when the monarchy was abolished. It was also the capital of the Weimar Republic. It was the capital of the Third Reich until 1945, when it was liberated by the allies. It has been the capital of the Federal Republic of Germany since 1949. It is the largest city in the country with a population of 3.6 million people. It is also the seat of the government and parliament.
|
65 |
```
|
66 |
|
67 |
|