Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,9 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
from peft import PeftModel, PeftConfig, LoraConfig
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
-
from datasets import load_dataset
|
6 |
-
from trl import SFTTrainer
|
7 |
# import torch
|
8 |
from transformers import StoppingCriteria, AutoModelForCausalLM, AutoTokenizer, StoppingCriteriaList
|
9 |
-
|
10 |
|
11 |
ref_model = AutoModelForCausalLM.from_pretrained("w601sxs/b1ade-1b", torch_dtype=torch.bfloat16)
|
12 |
|
@@ -29,14 +27,9 @@ stop_ids = [tokenizer.encode(w)[0] for w in stop_words]
|
|
29 |
stop_criteria = KeywordsStoppingCriteria(stop_ids)
|
30 |
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
import numpy as np
|
36 |
-
|
37 |
if tokenizer.pad_token_id is None:
|
38 |
tokenizer.pad_token_id = tokenizer.eos_token_id
|
39 |
-
|
40 |
|
41 |
# Define your color-coding labels; if prob > x, then label = y; Sorted in descending probability order!
|
42 |
probs_to_label = [
|
@@ -46,7 +39,6 @@ probs_to_label = [
|
|
46 |
(0.5, "50%"),
|
47 |
(0.1, "10%"),
|
48 |
(0.01, "1%"),
|
49 |
-
|
50 |
]
|
51 |
|
52 |
|
@@ -78,7 +70,7 @@ def get_tokens_and_labels(prompt):
|
|
78 |
|
79 |
# Important: you might need to find a tokenization character to replace (e.g. "Ġ" for BPE) and get the correct
|
80 |
# spacing into the final output 👼
|
81 |
-
if
|
82 |
highlighted_out = []
|
83 |
else:
|
84 |
input_tokens = tokenizer.convert_ids_to_tokens(inputs.input_ids[0])
|
|
|
2 |
import torch
|
3 |
from peft import PeftModel, PeftConfig, LoraConfig
|
4 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
|
5 |
# import torch
|
6 |
from transformers import StoppingCriteria, AutoModelForCausalLM, AutoTokenizer, StoppingCriteriaList
|
7 |
+
import numpy as np
|
8 |
|
9 |
ref_model = AutoModelForCausalLM.from_pretrained("w601sxs/b1ade-1b", torch_dtype=torch.bfloat16)
|
10 |
|
|
|
27 |
stop_criteria = KeywordsStoppingCriteria(stop_ids)
|
28 |
|
29 |
|
|
|
|
|
|
|
|
|
|
|
30 |
if tokenizer.pad_token_id is None:
|
31 |
tokenizer.pad_token_id = tokenizer.eos_token_id
|
32 |
+
ref_model.config.pad_token_id = ref_model.config.eos_token_id
|
33 |
|
34 |
# Define your color-coding labels; if prob > x, then label = y; Sorted in descending probability order!
|
35 |
probs_to_label = [
|
|
|
39 |
(0.5, "50%"),
|
40 |
(0.1, "10%"),
|
41 |
(0.01, "1%"),
|
|
|
42 |
]
|
43 |
|
44 |
|
|
|
70 |
|
71 |
# Important: you might need to find a tokenization character to replace (e.g. "Ġ" for BPE) and get the correct
|
72 |
# spacing into the final output 👼
|
73 |
+
if ref_model.config.is_encoder_decoder:
|
74 |
highlighted_out = []
|
75 |
else:
|
76 |
input_tokens = tokenizer.convert_ids_to_tokens(inputs.input_ids[0])
|