Update README.md
Browse files
README.md
CHANGED
|
@@ -46,25 +46,35 @@ from transformers import AutoTokenizer
|
|
| 46 |
import transformers
|
| 47 |
import torch
|
| 48 |
|
|
|
|
| 49 |
model = "Kumar955/Hemanth-llm"
|
|
|
|
|
|
|
|
|
|
| 50 |
messages = [{"role": "user", "content": "What is a large language model?"}]
|
| 51 |
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
prompt =
|
| 59 |
|
| 60 |
-
pipeline
|
|
|
|
| 61 |
"text-generation",
|
| 62 |
model=model,
|
| 63 |
torch_dtype=torch.float16,
|
| 64 |
device_map="auto",
|
| 65 |
)
|
| 66 |
|
|
|
|
| 67 |
outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
|
|
|
|
|
|
| 68 |
print(outputs[0]["generated_text"])
|
| 69 |
|
|
|
|
| 70 |
```
|
|
|
|
| 46 |
import transformers
|
| 47 |
import torch
|
| 48 |
|
| 49 |
+
# Load tokenizer and model
|
| 50 |
model = "Kumar955/Hemanth-llm"
|
| 51 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
| 52 |
+
|
| 53 |
+
# Define the messages from the conversation
|
| 54 |
messages = [{"role": "user", "content": "What is a large language model?"}]
|
| 55 |
|
| 56 |
+
# Define the chat template for formatting the conversation
|
| 57 |
+
chat_template = """<s><|user|>{{ user_message }}<|assistant|>"""
|
| 58 |
|
| 59 |
+
# Extract the user message content
|
| 60 |
+
user_message = messages[0]["content"]
|
| 61 |
|
| 62 |
+
# Format the prompt using the chat template
|
| 63 |
+
prompt = chat_template.replace("{{ user_message }}", user_message)
|
| 64 |
|
| 65 |
+
# Load the pipeline with the specified model
|
| 66 |
+
pipeline = pipeline(
|
| 67 |
"text-generation",
|
| 68 |
model=model,
|
| 69 |
torch_dtype=torch.float16,
|
| 70 |
device_map="auto",
|
| 71 |
)
|
| 72 |
|
| 73 |
+
# Generate output with the model
|
| 74 |
outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
| 75 |
+
|
| 76 |
+
# Print the generated response
|
| 77 |
print(outputs[0]["generated_text"])
|
| 78 |
|
| 79 |
+
|
| 80 |
```
|