Locutusque commited on
Commit
4a7bb50
·
verified ·
1 Parent(s): 7833173

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -24,20 +24,15 @@ def _unload_current():
24
  CURRENT["pipe"] = None
25
  CURRENT["name"] = None
26
  gc.collect()
27
- torch.cuda.empty_cache()
28
 
29
  def get_model(model_name):
30
  if CURRENT["name"] != model_name:
31
  _unload_current()
32
  task = "image-text-to-text" if model_name == "Locutusque/Esmeralda-31B" else "text-generation"
33
- model_kwargs = dict(torch_dtype=torch.bfloat16)
34
  from transformers import BitsAndBytesConfig
35
- model_kwargs["quantization_config"] = BitsAndBytesConfig(
36
- load_in_4bit=True,
37
- bnb_4bit_compute_dtype=torch.bfloat16,
38
- bnb_4bit_quant_type="nf4",
39
- )
40
- model_kwargs["device_map"] = "cuda"
41
  pipe = pipeline(
42
  task,
43
  model=model_name,
@@ -45,10 +40,12 @@ def get_model(model_name):
45
  trust_remote_code=True,
46
  token=os.environ["token"],
47
  use_fast=True,
 
 
 
 
 
48
  )
49
- pipe.model.to("cuda")
50
- pipe.device = torch.device("cuda")
51
- tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, token=os.environ["token"])
52
  tokenizer.eos_token = "<|im_end|>"
53
  pipe.tokenizer = tokenizer
54
  CURRENT["name"] = model_name
 
24
  CURRENT["pipe"] = None
25
  CURRENT["name"] = None
26
  gc.collect()
 
27
 
28
  def get_model(model_name):
29
  if CURRENT["name"] != model_name:
30
  _unload_current()
31
  task = "image-text-to-text" if model_name == "Locutusque/Esmeralda-31B" else "text-generation"
 
32
  from transformers import BitsAndBytesConfig
33
+ quant = BitsAndBytesConfig(
34
+ load_in_8bit=True,
35
+ )
 
 
 
36
  pipe = pipeline(
37
  task,
38
  model=model_name,
 
40
  trust_remote_code=True,
41
  token=os.environ["token"],
42
  use_fast=True,
43
+ device_map="auto",
44
+ model_kwargs={"quantization_config": quant},
45
+ )
46
+ tokenizer = AutoTokenizer.from_pretrained(
47
+ model_name, trust_remote_code=True, token=os.environ["token"]
48
  )
 
 
 
49
  tokenizer.eos_token = "<|im_end|>"
50
  pipe.tokenizer = tokenizer
51
  CURRENT["name"] = model_name