Spaces:
Running
on
Zero
Running
on
Zero
cutechicken
commited on
Commit
โข
cf528b4
1
Parent(s):
0cdcb4f
Update app.py
Browse files
app.py
CHANGED
@@ -70,28 +70,35 @@ class ModelManager:
|
|
70 |
prompt += f"Assistant: {content}\n"
|
71 |
prompt += "Assistant: "
|
72 |
|
73 |
-
# ํ ํฌ๋์ด์ง
|
74 |
-
|
75 |
prompt,
|
76 |
return_tensors="pt",
|
77 |
padding=True,
|
78 |
truncation=True,
|
79 |
max_length=4096
|
80 |
-
).input_ids
|
81 |
-
|
82 |
-
# ์์ฑ
|
83 |
-
outputs = self.model.generate(
|
84 |
-
input_ids,
|
85 |
-
max_new_tokens=max_tokens,
|
86 |
-
do_sample=True,
|
87 |
-
temperature=temperature,
|
88 |
-
top_p=top_p,
|
89 |
-
pad_token_id=self.tokenizer.pad_token_id,
|
90 |
-
eos_token_id=self.tokenizer.eos_token_id,
|
91 |
-
num_return_sequences=1
|
92 |
)
|
|
|
|
|
|
|
|
|
93 |
|
94 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
generated_text = self.tokenizer.decode(
|
96 |
outputs[0][input_ids.shape[1]:],
|
97 |
skip_special_tokens=True
|
|
|
70 |
prompt += f"Assistant: {content}\n"
|
71 |
prompt += "Assistant: "
|
72 |
|
73 |
+
# ํ ํฌ๋์ด์ง ๋ฐ device ์ค์
|
74 |
+
inputs = self.tokenizer(
|
75 |
prompt,
|
76 |
return_tensors="pt",
|
77 |
padding=True,
|
78 |
truncation=True,
|
79 |
max_length=4096
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
)
|
81 |
+
|
82 |
+
# ๋ชจ๋ ํ
์๋ฅผ GPU๋ก ์ด๋
|
83 |
+
input_ids = inputs.input_ids.to(self.model.device)
|
84 |
+
attention_mask = inputs.attention_mask.to(self.model.device)
|
85 |
|
86 |
+
# ์์ฑ
|
87 |
+
with torch.no_grad():
|
88 |
+
outputs = self.model.generate(
|
89 |
+
input_ids=input_ids,
|
90 |
+
attention_mask=attention_mask,
|
91 |
+
max_new_tokens=max_tokens,
|
92 |
+
do_sample=True,
|
93 |
+
temperature=temperature,
|
94 |
+
top_p=top_p,
|
95 |
+
pad_token_id=self.tokenizer.pad_token_id,
|
96 |
+
eos_token_id=self.tokenizer.eos_token_id,
|
97 |
+
num_return_sequences=1
|
98 |
+
)
|
99 |
+
|
100 |
+
# ๋์ฝ๋ฉ ์ ์ CPU๋ก ์ด๋
|
101 |
+
outputs = outputs.cpu()
|
102 |
generated_text = self.tokenizer.decode(
|
103 |
outputs[0][input_ids.shape[1]:],
|
104 |
skip_special_tokens=True
|