PhantHive commited on
Commit
9641b31
1 Parent(s): 327ad9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -1,8 +1,7 @@
1
  import gradio as gr
2
  from peft import PeftModel, PeftConfig
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
- import
5
- torch
6
 
7
  # Device configuration (prioritize GPU if available)
8
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -10,10 +9,14 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
  # Load models and tokenizer efficiently
11
  config = PeftConfig.from_pretrained("phearion/bigbrain-v0.0.1")
12
  tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
13
- model = PeftModel.from_pretrained(model_id)
 
 
 
14
  model.to(device)
15
 
16
- def greet(text):
 
17
  with torch.no_grad(): # Disable gradient calculation for inference
18
  batch = tokenizer(text, return_tensors='pt').to(device) # Move tensors to device
19
  with torch.cuda.amp.autocast(): # Enable mixed-precision if available
 
1
  import gradio as gr
2
  from peft import PeftModel, PeftConfig
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
+ import torch
 
5
 
6
  # Device configuration (prioritize GPU if available)
7
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
9
  # Load models and tokenizer efficiently
10
  config = PeftConfig.from_pretrained("phearion/bigbrain-v0.0.1")
11
  tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
12
+ model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path)
13
+
14
+ # Load the Lora model
15
+ model = PeftModel.from_pretrained(model, peft_model_id)
16
  model.to(device)
17
 
18
+ def greet(text
19
+ ):
20
  with torch.no_grad(): # Disable gradient calculation for inference
21
  batch = tokenizer(text, return_tensors='pt').to(device) # Move tensors to device
22
  with torch.cuda.amp.autocast(): # Enable mixed-precision if available