Update README.md
Browse files
README.md
CHANGED
|
@@ -85,22 +85,25 @@ The model was fine-tuned on a combination of the following datasets:
|
|
| 85 |
```python
|
| 86 |
import torch
|
| 87 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
| 88 |
|
| 89 |
device = "cuda"
|
| 90 |
|
|
|
|
|
|
|
|
|
|
| 91 |
# Load the merged fine-tuned model and tokenizer
|
| 92 |
-
model_dir = "E-Model-V2"
|
| 93 |
model = AutoModelForCausalLM.from_pretrained(
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
)
|
| 98 |
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
| 99 |
|
| 100 |
# Ensure EOS token is set correctly
|
| 101 |
eos_token = tokenizer("<|im_end|>", add_special_tokens=False)["input_ids"][0]
|
| 102 |
if tokenizer.eos_token_id is None:
|
| 103 |
-
|
| 104 |
|
| 105 |
# Move model to device (if not already mapped)
|
| 106 |
model.to(device)
|
|
@@ -113,43 +116,43 @@ print("Merhaba! Size nasıl yardımcı olabilirim? (Çıkmak için 'çık' yazı
|
|
| 113 |
conversation_history = [{"role": "system", "content": system_prompt}] # Initialize with system prompt
|
| 114 |
|
| 115 |
while True:
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
|
| 150 |
# Optional: Clear memory when done
|
| 151 |
del model
|
| 152 |
-
torch.cuda.empty_cache()
|
| 153 |
```
|
| 154 |
|
| 155 |
### 9. Ethical Considerations
|
|
|
|
| 85 |
```python
|
| 86 |
import torch
|
| 87 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 88 |
+
from huggingface_hub import snapshot_download
|
| 89 |
|
| 90 |
device = "cuda"
|
| 91 |
|
| 92 |
+
# Download the model from Hugging Face
|
| 93 |
+
model_dir = snapshot_download("MeowML/E-Model-V2")
|
| 94 |
+
|
| 95 |
# Load the merged fine-tuned model and tokenizer
|
|
|
|
| 96 |
model = AutoModelForCausalLM.from_pretrained(
|
| 97 |
+
model_dir,
|
| 98 |
+
torch_dtype=torch.float16, # Use FP16 for memory efficiency
|
| 99 |
+
device_map="auto" # Automatically map to GPU
|
| 100 |
)
|
| 101 |
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
| 102 |
|
| 103 |
# Ensure EOS token is set correctly
|
| 104 |
eos_token = tokenizer("<|im_end|>", add_special_tokens=False)["input_ids"][0]
|
| 105 |
if tokenizer.eos_token_id is None:
|
| 106 |
+
tokenizer.eos_token_id = eos_token
|
| 107 |
|
| 108 |
# Move model to device (if not already mapped)
|
| 109 |
model.to(device)
|
|
|
|
| 116 |
conversation_history = [{"role": "system", "content": system_prompt}] # Initialize with system prompt
|
| 117 |
|
| 118 |
while True:
|
| 119 |
+
# Get user input
|
| 120 |
+
user_input = input("Siz: ")
|
| 121 |
+
|
| 122 |
+
# Exit condition
|
| 123 |
+
if user_input.lower() == "çık":
|
| 124 |
+
print("Görüşmek üzere!")
|
| 125 |
+
break
|
| 126 |
+
|
| 127 |
+
# Add user input to conversation history
|
| 128 |
+
conversation_history.append({"role": "user", "content": user_input})
|
| 129 |
+
|
| 130 |
+
# Tokenize the conversation history
|
| 131 |
+
encodeds = tokenizer.apply_chat_template(conversation_history, return_tensors="pt")
|
| 132 |
+
model_inputs = encodeds.to(device)
|
| 133 |
+
|
| 134 |
+
# Generate response
|
| 135 |
+
generated_ids = model.generate(
|
| 136 |
+
model_inputs,
|
| 137 |
+
max_new_tokens=1024,
|
| 138 |
+
do_sample=True,
|
| 139 |
+
eos_token_id=eos_token,
|
| 140 |
+
temperature=0.7,
|
| 141 |
+
top_p=0.95
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
# Decode the response
|
| 145 |
+
generated_text = tokenizer.decode(generated_ids[0][model_inputs.shape[1]:], skip_special_tokens=True)
|
| 146 |
+
|
| 147 |
+
# Add assistant response to history
|
| 148 |
+
conversation_history.append({"role": "assistant", "content": generated_text})
|
| 149 |
+
|
| 150 |
+
# Print the response
|
| 151 |
+
print(f"Asistan: {generated_text}")
|
| 152 |
|
| 153 |
# Optional: Clear memory when done
|
| 154 |
del model
|
| 155 |
+
torch.cuda.empty_cache()
|
| 156 |
```
|
| 157 |
|
| 158 |
### 9. Ethical Considerations
|