Update app.py
Browse files
app.py
CHANGED
|
@@ -246,8 +246,9 @@ class Translators:
|
|
| 246 |
def rosetta(self):
|
| 247 |
model = AutoModelForCausalLM.from_pretrained(
|
| 248 |
self.model_name,
|
| 249 |
-
dtype=torch.bfloat16
|
| 250 |
-
|
|
|
|
| 251 |
tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
| 252 |
context = {"tone": "Formal and precise"}
|
| 253 |
system = f"Translate the user's text to {self.tl}. Provide the final translation in a formal tone immediately immediately without any other text."
|
|
@@ -259,6 +260,7 @@ class Translators:
|
|
| 259 |
print(prompt)
|
| 260 |
inputs = tokenizer(prompt, return_tensors="pt").to(self.device)
|
| 261 |
input_length = inputs["input_ids"].shape[1]
|
|
|
|
| 262 |
with torch.inference_mode():
|
| 263 |
outputs = model.generate(
|
| 264 |
**inputs,
|
|
|
|
| 246 |
def rosetta(self):
|
| 247 |
model = AutoModelForCausalLM.from_pretrained(
|
| 248 |
self.model_name,
|
| 249 |
+
dtype=torch.float32, # bfloat16
|
| 250 |
+
low_cpu_mem_usage=True,
|
| 251 |
+
device_map="auto")
|
| 252 |
tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
| 253 |
context = {"tone": "Formal and precise"}
|
| 254 |
system = f"Translate the user's text to {self.tl}. Provide the final translation in a formal tone immediately immediately without any other text."
|
|
|
|
| 260 |
print(prompt)
|
| 261 |
inputs = tokenizer(prompt, return_tensors="pt").to(self.device)
|
| 262 |
input_length = inputs["input_ids"].shape[1]
|
| 263 |
+
model.eval()
|
| 264 |
with torch.inference_mode():
|
| 265 |
outputs = model.generate(
|
| 266 |
**inputs,
|