Update README.md
Browse files
README.md
CHANGED
|
@@ -41,6 +41,38 @@ Format your prompt as
|
|
| 41 |
```
|
| 42 |
where `instruction` is your query.
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
## Training
|
| 45 |
|
| 46 |
The model was fine-tuned on a sanitized version of the single-turn OASST dataset linked above.
|
|
|
|
| 41 |
```
|
| 42 |
where `instruction` is your query.
|
| 43 |
|
| 44 |
+
|
| 45 |
+
Here's a full-fledged example:
|
| 46 |
+
|
| 47 |
+
```
|
| 48 |
+
import torch
|
| 49 |
+
import transformers
|
| 50 |
+
|
| 51 |
+
model_name_or_path = "lxuechen/phi-2-sft"
|
| 52 |
+
|
| 53 |
+
model: transformers.PreTrainedModel = transformers.AutoModelForCausalLM.from_pretrained(
|
| 54 |
+
model_name_or_path,
|
| 55 |
+
low_cpu_mem_usage=True,
|
| 56 |
+
device_map="auto",
|
| 57 |
+
trust_remote_code=True,
|
| 58 |
+
torch_dtype=torch.float16
|
| 59 |
+
)
|
| 60 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name_or_path)
|
| 61 |
+
|
| 62 |
+
input_text = "### Human: Give me a good recipe for a chinese dish\n\n### Assistant:"
|
| 63 |
+
|
| 64 |
+
outputs = model.generate(
|
| 65 |
+
tokenizer(input_text, return_tensors="pt").to(model.device), max_length=1024,
|
| 66 |
+
temperature=0.7,
|
| 67 |
+
top_p=0.9,
|
| 68 |
+
do_sample=True,
|
| 69 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 70 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 71 |
+
max_new_tokens=1024
|
| 72 |
+
)
|
| 73 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
## Training
|
| 77 |
|
| 78 |
The model was fine-tuned on a sanitized version of the single-turn OASST dataset linked above.
|