Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,49 +30,51 @@ HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
| 30 |
model_id = 'meta-llama/Meta-Llama-3-8B'
|
| 31 |
device = f'cuda:{cuda.current_device()}' if cuda.is_available() else 'cpu'
|
| 32 |
|
| 33 |
-
# set quantization configuration to load large model with less GPU memory
|
| 34 |
-
# this requires the `bitsandbytes` library
|
| 35 |
-
# bnb_config = transformers.BitsAndBytesConfig(
|
| 36 |
-
# load_in_4bit=True,
|
| 37 |
-
# bnb_4bit_quant_type='nf4',
|
| 38 |
-
# bnb_4bit_use_double_quant=True,
|
| 39 |
-
# bnb_4bit_compute_dtype=bfloat16
|
| 40 |
-
# )
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
"""
|
| 78 |
Setting up the stop list to define stopping criteria.
|
|
|
|
| 30 |
model_id = 'meta-llama/Meta-Llama-3-8B'
|
| 31 |
device = f'cuda:{cuda.current_device()}' if cuda.is_available() else 'cpu'
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
"""set quantization configuration to load large model with less GPU memory
|
| 35 |
+
this requires the `bitsandbytes` library"""
|
| 36 |
+
bnb_config = transformers.BitsAndBytesConfig(
|
| 37 |
+
load_in_4bit=True,
|
| 38 |
+
bnb_4bit_quant_type='nf4',
|
| 39 |
+
bnb_4bit_use_double_quant=True,
|
| 40 |
+
bnb_4bit_compute_dtype=bfloat16
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct",token=HF_TOKEN)
|
| 44 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct", device_map="auto",token=HF_TOKEN) # to("cuda:0")
|
| 45 |
+
terminators = [
|
| 46 |
+
tokenizer.eos_token_id,
|
| 47 |
+
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
"""CPU"""
|
| 51 |
+
|
| 52 |
+
# model_config = transformers.AutoConfig.from_pretrained(
|
| 53 |
+
# model_id,
|
| 54 |
+
# token=HF_TOKEN,
|
| 55 |
+
# # use_auth_token=hf_auth
|
| 56 |
+
# )
|
| 57 |
+
# model = transformers.AutoModelForCausalLM.from_pretrained(
|
| 58 |
+
# model_id,
|
| 59 |
+
# trust_remote_code=True,
|
| 60 |
+
# config=model_config,
|
| 61 |
+
# # quantization_config=bnb_config,
|
| 62 |
+
# token=HF_TOKEN,
|
| 63 |
+
# # use_auth_token=hf_auth
|
| 64 |
+
# )
|
| 65 |
+
# model.eval()
|
| 66 |
+
# tokenizer = transformers.AutoTokenizer.from_pretrained(
|
| 67 |
+
# model_id,
|
| 68 |
+
# token=HF_TOKEN,
|
| 69 |
+
# # use_auth_token=hf_auth
|
| 70 |
+
# )
|
| 71 |
+
# generate_text = transformers.pipeline(
|
| 72 |
+
# model=self.model, tokenizer=self.tokenizer,
|
| 73 |
+
# return_full_text=True,
|
| 74 |
+
# task='text-generation',
|
| 75 |
+
# temperature=0.01,
|
| 76 |
+
# max_new_tokens=512
|
| 77 |
+
# )
|
| 78 |
|
| 79 |
"""
|
| 80 |
Setting up the stop list to define stopping criteria.
|