Update app.py
Browse files
app.py
CHANGED
|
@@ -29,14 +29,21 @@ text_generator = pipeline("text-generation", model=model_gpt2, tokenizer=tokeniz
|
|
| 29 |
|
| 30 |
# Load the Llama-3 model and tokenizer once during startup
|
| 31 |
tokenizer_llama = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B", token=hf_token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
| 41 |
# Define your prompt template
|
| 42 |
prompt_template = """\
|
|
|
|
| 29 |
|
| 30 |
# Load the Llama-3 model and tokenizer once during startup
|
| 31 |
tokenizer_llama = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B", token=hf_token)
|
| 32 |
+
# Define the offload directory
|
| 33 |
+
offload_dir = "./offload"
|
| 34 |
+
os.makedirs(offload_dir, exist_ok=True) # Create the directory if it doesn't exist
|
| 35 |
+
|
| 36 |
+
# Load the Llama model with disk offloading
|
| 37 |
with init_empty_weights():
|
| 38 |
model_llama = AutoModelForCausalLM.from_pretrained(
|
| 39 |
"meta-llama/Meta-Llama-3-8B",
|
| 40 |
torch_dtype='auto',
|
| 41 |
+
device_map='auto',
|
| 42 |
token=hf_token
|
| 43 |
)
|
| 44 |
+
|
| 45 |
+
# Offload the model to the specified directory
|
| 46 |
+
disk_offload(model_llama, offload_dir) # Pass the offload directory
|
| 47 |
|
| 48 |
# Define your prompt template
|
| 49 |
prompt_template = """\
|