macadeliccc
commited on
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
|
5 |
+
![image/webp](https://cdn-uploads.huggingface.co/production/uploads/6455cc8d679315e4ef16fbec/wZ0eCzTn2CzYB44cmaE6L.webp)
|
6 |
+
|
7 |
+
## Code example
|
8 |
+
|
9 |
+
```python
|
10 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
11 |
+
|
12 |
+
def generate_response(prompt):
|
13 |
+
"""
|
14 |
+
Generate a response from the model based on the input prompt.
|
15 |
+
|
16 |
+
Args:
|
17 |
+
prompt (str): Prompt for the model.
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
str: The generated response from the model.
|
21 |
+
"""
|
22 |
+
# Tokenize the input prompt
|
23 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
24 |
+
|
25 |
+
# Generate output tokens
|
26 |
+
outputs = model.generate(**inputs, max_new_tokens=256, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id)
|
27 |
+
|
28 |
+
# Decode the generated tokens to a string
|
29 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
30 |
+
|
31 |
+
return response
|
32 |
+
|
33 |
+
# Load the model and tokenizer
|
34 |
+
model_id = "macadeliccc/laser-dolphin-mixtral-4x7b-dpo"
|
35 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
36 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True)
|
37 |
+
|
38 |
+
prompt = "Write a quicksort algorithm in python"
|
39 |
+
|
40 |
+
# Generate and print responses for each language
|
41 |
+
print("Response:")
|
42 |
+
print(generate_response(prompt), "\n")
|
43 |
+
```
|