Nitzantry1 commited on
Commit
8106ffa
verified
1 Parent(s): c102310

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -16
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
- # 讬爪讬专转 讛诪谞讜注 注诐 Accelerate 讘诪讬讚转 讛爪讜专讱
21
- if device.type == 'cuda':
22
- generator = pipeline('text-generation', model=model_id,
23
- tokenizer=model_id,
24
- torch_dtype=torch.float16,
25
- use_fast=should_use_fast,
26
- trust_remote_code=True,
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):