orionweller commited on
Commit
2ded88b
1 Parent(s): 26c9c90
Files changed (2) hide show
  1. app.py +33 -9
  2. requirements.txt +5 -4
app.py CHANGED
@@ -1,13 +1,33 @@
 
 
 
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  # Model loading and setup
6
  model_name = "jhu-clsp/FollowIR-7B"
7
- model = AutoModelForCausalLM.from_pretrained(model_name)
8
- if torch.cuda.is_available():
9
- model = model.cuda()
10
- tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side="left")
 
 
 
 
 
11
  tokenizer.pad_token = tokenizer.eos_token
12
  tokenizer.padding_side = "left"
13
  token_false_id = tokenizer.get_vocab()["false"]
@@ -31,11 +51,11 @@ def check_relevance(query, instruction, passage):
31
  pad_to_multiple_of=None,
32
  )
33
 
34
- if torch.cuda.is_available():
35
- for key in tokens:
36
- tokens[key] = tokens[key].cuda()
37
 
38
- batch_scores = model(**tokens).logits[:, -1, :]
 
39
  true_vector = batch_scores[:, token_true_id]
40
  false_vector = batch_scores[:, token_false_id]
41
  batch_scores = torch.stack([false_vector, true_vector], dim=1)
@@ -65,4 +85,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
65
  outputs=[output]
66
  )
67
 
68
- demo.launch()
 
 
 
 
 
1
+ import sys
2
+ import warnings
3
+ print("Warning: This application requires specific library versions. Please ensure you have the correct versions installed.")
4
+
5
  import gradio as gr
6
  from transformers import AutoTokenizer, AutoModelForCausalLM
7
  import torch
8
+ import numpy as np
9
+
10
+ print(f"NumPy version: {np.__version__}")
11
+ print(f"PyTorch version: {torch.__version__}")
12
+
13
+ # Suppress CUDA initialization warning
14
+ warnings.filterwarnings("ignore", category=UserWarning, message="Can't initialize NVML")
15
+
16
+ # Check for GPU availability
17
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
18
+ print(f"Using device: {device}")
19
 
20
  # Model loading and setup
21
  model_name = "jhu-clsp/FollowIR-7B"
22
+
23
+ try:
24
+ model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
25
+ tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side="left")
26
+ except ValueError as e:
27
+ print(f"Error loading model or tokenizer: {e}")
28
+ print("Please ensure you have the correct versions of transformers and sentencepiece installed.")
29
+ sys.exit(1)
30
+
31
  tokenizer.pad_token = tokenizer.eos_token
32
  tokenizer.padding_side = "left"
33
  token_false_id = tokenizer.get_vocab()["false"]
 
51
  pad_to_multiple_of=None,
52
  )
53
 
54
+ for key in tokens:
55
+ tokens[key] = tokens[key].to(device)
 
56
 
57
+ with torch.no_grad():
58
+ batch_scores = model(**tokens).logits[:, -1, :]
59
  true_vector = batch_scores[:, token_true_id]
60
  false_vector = batch_scores[:, token_false_id]
61
  batch_scores = torch.stack([false_vector, true_vector], dim=1)
 
85
  outputs=[output]
86
  )
87
 
88
+ if __name__ == "__main__":
89
+ if np.__version__.startswith("2."):
90
+ print("Error: This application is not compatible with NumPy 2.x. Please downgrade to NumPy < 2.0.0.")
91
+ sys.exit(1)
92
+ demo.launch()
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  gradio
2
- --extra-index-url https://download.pytorch.org/whl/cu117
3
- torch
4
- transformers
5
- numpy<2.0.0
 
 
1
  gradio
2
+ transformers==4.35.2
3
+ numpy==1.24.3
4
+ sentencepiece==0.1.99
5
+ torch==2.0.1
6
+ --extra-index-url https://download.pytorch.org/whl/cu117