Update README.md
Browse files
README.md
CHANGED
|
@@ -22,6 +22,41 @@ This model is a fine-tuned version of [TinyLlama/TinyLlama-1.1B-Chat-v1.0](https
|
|
| 22 |
|
| 23 |
This model has been fine tuned with mosaicml/instruct-v3 dataset with 2 epoch only. Mainly this model is useful for RAG based application
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
## Intended uses & limitations
|
| 26 |
|
| 27 |
More information needed
|
|
|
|
| 22 |
|
| 23 |
This model has been fine tuned with mosaicml/instruct-v3 dataset with 2 epoch only. Mainly this model is useful for RAG based application
|
| 24 |
|
| 25 |
+
## How to use?
|
| 26 |
+
from peft import PeftModel
|
| 27 |
+
|
| 28 |
+
# load the base model
|
| 29 |
+
model_path = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
|
| 30 |
+
tokenizer=AutoTokenizer.from_pretrained(model_path)
|
| 31 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 32 |
+
model_path,
|
| 33 |
+
torch_dtype = torch.bfloat16,
|
| 34 |
+
device_map = "auto",
|
| 35 |
+
trust_remote_code = True
|
| 36 |
+
)
|
| 37 |
+
#load the adapter
|
| 38 |
+
model_peft = PeftModel.from_pretrained(model, "azam25/TinyLlama_instruct_generation")
|
| 39 |
+
|
| 40 |
+
messages = [{
|
| 41 |
+
"role": "user",
|
| 42 |
+
"content": "Act as a gourmet chef. I have a friend coming over who is a vegetarian. \
|
| 43 |
+
I want to impress my friend with a special vegetarian dish. \
|
| 44 |
+
What do you recommend? \
|
| 45 |
+
Give me two options, along with the whole recipe for each"
|
| 46 |
+
}]
|
| 47 |
+
|
| 48 |
+
def generate_response(message, model):
|
| 49 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False)
|
| 50 |
+
encoded_input = tokenizer(prompt, return_tensors="pt", add_special_tokens=True)
|
| 51 |
+
model_inputs = encoded_input.to('cuda')
|
| 52 |
+
generated_ids = model.generate(**model_inputs, max_new_tokens=1000, do_sample=True, pad_token_id=tokenizer.eos_token_id)
|
| 53 |
+
decoded_output = tokenizer.batch_decode(generated_ids)
|
| 54 |
+
return decoded_output[0]
|
| 55 |
+
|
| 56 |
+
response = generate_response(messages, model)
|
| 57 |
+
print(response)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
## Intended uses & limitations
|
| 61 |
|
| 62 |
More information needed
|