Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,22 +17,13 @@ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
17 |
print('Using device:', device)
|
18 |
print()
|
19 |
|
20 |
-
# 讬爪讬专转 讛诪谞讜注 注诐
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
device_map="auto")
|
28 |
-
else:
|
29 |
-
from accelerate import init_empty_weights, infer_auto_device_map
|
30 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
31 |
-
|
32 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=should_use_fast)
|
33 |
-
with init_empty_weights():
|
34 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
35 |
-
generator = pipeline('text-generation', model=model, tokenizer=tokenizer, device=device)
|
36 |
|
37 |
# 驻讜谞拽爪讬讬转 讬爪讬专转 讛讟拽住讟
|
38 |
def chat_with_model(history):
|
|
|
17 |
print('Using device:', device)
|
18 |
print()
|
19 |
|
20 |
+
# 讬爪讬专转 讛诪谞讜注 注诐 pipeline
|
21 |
+
generator = pipeline('text-generation', model=model_id,
|
22 |
+
tokenizer=model_id,
|
23 |
+
torch_dtype=torch.float16 if device.type == 'cuda' else torch.float32,
|
24 |
+
use_fast=should_use_fast,
|
25 |
+
trust_remote_code=True,
|
26 |
+
device_map="auto" if device.type == 'cuda' else None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# 驻讜谞拽爪讬讬转 讬爪讬专转 讛讟拽住讟
|
29 |
def chat_with_model(history):
|