PromptWizard Bot commited on
Commit
543b65a
·
1 Parent(s): 4bdca86

Fix Zero GPU compatibility - remove bitsandbytes and 8-bit quantization

Browse files
Files changed (2) hide show
  1. app.py +10 -9
  2. requirements.txt +0 -1
app.py CHANGED
@@ -12,12 +12,10 @@ from peft import LoraConfig, get_peft_model, TaskType
12
  import json
13
  import os
14
 
15
- # Check if GPU is available
16
  def check_gpu_status():
17
- if torch.cuda.is_available():
18
- return f" GPU Available: {torch.cuda.get_device_name(0)} ({torch.cuda.get_device_properties(0).total_memory / 1e9:.1f}GB)"
19
- else:
20
- return "⚠️ No GPU detected - Zero GPU will allocate when training starts"
21
 
22
  @spaces.GPU(duration=300) # Request GPU for 5 minutes (can extend if needed)
23
  def train_model(model_name, num_epochs, batch_size, learning_rate, progress=gr.Progress()):
@@ -86,15 +84,18 @@ You are a mathematics expert. Solve grade school math problems step by step.
86
  if tokenizer.pad_token is None:
87
  tokenizer.pad_token = tokenizer.eos_token
88
 
89
- # Load model with 8-bit quantization
90
  model = AutoModelForCausalLM.from_pretrained(
91
  model_name,
92
  trust_remote_code=True,
93
- load_in_8bit=True,
94
- device_map="auto",
95
- torch_dtype=torch.float16
96
  )
97
 
 
 
 
 
98
  output_log.append(" Model loaded successfully")
99
 
100
  # Configure LoRA
 
12
  import json
13
  import os
14
 
15
+ # Check if GPU is available (Zero GPU safe)
16
  def check_gpu_status():
17
+ # Don't check CUDA at module load time for Zero GPU compatibility
18
+ return "🚀 Zero GPU Ready - GPU will be allocated when training starts"
 
 
19
 
20
  @spaces.GPU(duration=300) # Request GPU for 5 minutes (can extend if needed)
21
  def train_model(model_name, num_epochs, batch_size, learning_rate, progress=gr.Progress()):
 
84
  if tokenizer.pad_token is None:
85
  tokenizer.pad_token = tokenizer.eos_token
86
 
87
+ # Load model without quantization for Zero GPU compatibility
88
  model = AutoModelForCausalLM.from_pretrained(
89
  model_name,
90
  trust_remote_code=True,
91
+ torch_dtype=torch.float16 if device == "cuda" else torch.float32,
92
+ low_cpu_mem_usage=True
 
93
  )
94
 
95
+ # Move model to GPU if available
96
+ if device == "cuda":
97
+ model = model.to(device)
98
+
99
  output_log.append(" Model loaded successfully")
100
 
101
  # Configure LoRA
requirements.txt CHANGED
@@ -5,6 +5,5 @@ transformers==4.36.2
5
  datasets==2.16.1
6
  peft==0.7.1
7
  accelerate==0.25.0
8
- bitsandbytes==0.41.3
9
  numpy==1.24.3
10
  sentencepiece==0.1.99
 
5
  datasets==2.16.1
6
  peft==0.7.1
7
  accelerate==0.25.0
 
8
  numpy==1.24.3
9
  sentencepiece==0.1.99