Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -4,13 +4,14 @@ import os
|
|
4 |
import torch
|
5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
# System message (placeholder, adjust as needed)
|
16 |
system_message = ""
|
|
|
4 |
import torch
|
5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
6 |
|
7 |
+
# Check if CUDA is available and set device accordingly
|
8 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
+
|
10 |
+
# Set environment variables for GPU usage and memory allocation if CUDA is available
|
11 |
+
if device == "cuda":
|
12 |
+
os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
|
13 |
+
torch.cuda.empty_cache()
|
14 |
+
torch.cuda.set_per_process_memory_fraction(0.8) # Adjust the fraction as needed
|
15 |
|
16 |
# System message (placeholder, adjust as needed)
|
17 |
system_message = ""
|