Vitrous commited on
Commit
38c5d6c
·
verified ·
1 Parent(s): 637b32d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -4,13 +4,14 @@ import os
4
  import torch
5
  from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
6
 
7
- # Set environment variables for GPU usage and memory allocation
8
- os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
9
- torch.cuda.empty_cache()
10
- torch.cuda.set_per_process_memory_fraction(0.5) # Adjust the fraction as needed
11
-
12
- # Define device
13
- device = "cuda" # The device to load the model onto
 
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 = ""