Spaces:
Sleeping
Sleeping
random
Browse files
app.py
CHANGED
@@ -4,12 +4,14 @@ import torch
|
|
4 |
|
5 |
model_id = "ytu-ce-cosmos/Turkish-Llama-8b-DPO-v0.1"
|
6 |
|
|
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
8 |
model = AutoModelForCausalLM.from_pretrained(
|
9 |
model_id,
|
10 |
torch_dtype=torch.bfloat16,
|
11 |
device_map="auto",
|
12 |
)
|
|
|
13 |
|
14 |
# bu mesaj değiştirilebilir ve chatbotun başlangıç mesajı olarak kullanılabilir
|
15 |
initial_message = [
|
@@ -18,6 +20,7 @@ initial_message = [
|
|
18 |
]
|
19 |
|
20 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
21 |
|
22 |
app = FastAPI()
|
23 |
|
@@ -29,11 +32,13 @@ def home():
|
|
29 |
|
30 |
@app.get('/ask')
|
31 |
def ask(prompt: str):
|
32 |
-
|
33 |
messages = initial_message.copy()
|
34 |
messages.append({"role": "user",
|
35 |
"content": f"{prompt}"})
|
36 |
|
|
|
|
|
37 |
input_ids = tokenizer.apply_chat_template(
|
38 |
messages,
|
39 |
add_generation_prompt=True,
|
@@ -44,6 +49,8 @@ def ask(prompt: str):
|
|
44 |
tokenizer.eos_token_id,
|
45 |
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
46 |
]
|
|
|
|
|
47 |
print("Model process started")
|
48 |
outputs = model.generate(
|
49 |
input_ids,
|
|
|
4 |
|
5 |
model_id = "ytu-ce-cosmos/Turkish-Llama-8b-DPO-v0.1"
|
6 |
|
7 |
+
print("Model loading started")
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
9 |
model = AutoModelForCausalLM.from_pretrained(
|
10 |
model_id,
|
11 |
torch_dtype=torch.bfloat16,
|
12 |
device_map="auto",
|
13 |
)
|
14 |
+
print("Model loading completed")
|
15 |
|
16 |
# bu mesaj değiştirilebilir ve chatbotun başlangıç mesajı olarak kullanılabilir
|
17 |
initial_message = [
|
|
|
20 |
]
|
21 |
|
22 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
23 |
+
print("Selected device:", device)
|
24 |
|
25 |
app = FastAPI()
|
26 |
|
|
|
32 |
|
33 |
@app.get('/ask')
|
34 |
def ask(prompt: str):
|
35 |
+
print("Device of the model:", model.device)
|
36 |
messages = initial_message.copy()
|
37 |
messages.append({"role": "user",
|
38 |
"content": f"{prompt}"})
|
39 |
|
40 |
+
print("Messages:", messages)
|
41 |
+
print("Tokenizer process started")
|
42 |
input_ids = tokenizer.apply_chat_template(
|
43 |
messages,
|
44 |
add_generation_prompt=True,
|
|
|
49 |
tokenizer.eos_token_id,
|
50 |
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
51 |
]
|
52 |
+
print("Tokenizer process completed")
|
53 |
+
|
54 |
print("Model process started")
|
55 |
outputs = model.generate(
|
56 |
input_ids,
|