Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from transformers import GPT2LMHeadModel, GPT2Tokenizer, AutoTokenizer, AutoMode
|
|
7 |
from huggingface_hub import HfFolder
|
8 |
from io import StringIO
|
9 |
from tqdm import tqdm
|
|
|
10 |
|
11 |
# Access the Hugging Face API token from environment variables
|
12 |
hf_token = os.getenv('HF_API_TOKEN')
|
@@ -27,12 +28,14 @@ text_generator = pipeline("text-generation", model=model_gpt2, tokenizer=tokeniz
|
|
27 |
|
28 |
# Load the Llama-3 model and tokenizer once during startup
|
29 |
tokenizer_llama = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B", token=hf_token)
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
|
37 |
# Define your prompt template
|
38 |
prompt_template = """\
|
|
|
7 |
from huggingface_hub import HfFolder
|
8 |
from io import StringIO
|
9 |
from tqdm import tqdm
|
10 |
+
from accelerate import init_empty_weight
|
11 |
|
12 |
# Access the Hugging Face API token from environment variables
|
13 |
hf_token = os.getenv('HF_API_TOKEN')
|
|
|
28 |
|
29 |
# Load the Llama-3 model and tokenizer once during startup
|
30 |
tokenizer_llama = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B", token=hf_token)
|
31 |
+
|
32 |
+
with init_empty_weights():
|
33 |
+
model_llama = AutoModelForCausalLM.from_pretrained(
|
34 |
+
"meta-llama/Meta-Llama-3-8B",
|
35 |
+
torch_dtype='auto',
|
36 |
+
device_map='auto',
|
37 |
+
token=hf_token
|
38 |
+
)
|
39 |
|
40 |
# Define your prompt template
|
41 |
prompt_template = """\
|