Adding logs for model loading
Browse files- src/service/service.py +14 -13
src/service/service.py
CHANGED
|
@@ -36,7 +36,7 @@ try:
|
|
| 36 |
if getattr(sys, 'frozen', False):
|
| 37 |
application_path = sys._MEIPASS
|
| 38 |
else:
|
| 39 |
-
application_path = os.path.
|
| 40 |
|
| 41 |
|
| 42 |
log=CustomLogger()
|
|
@@ -59,34 +59,35 @@ try:
|
|
| 59 |
# print(os.listdir())
|
| 60 |
check_point = 'toxic_debiased-c7548aa0.ckpt'
|
| 61 |
log.info(f"device is: {device}")
|
| 62 |
-
|
| 63 |
-
#remove later
|
| 64 |
-
value = "/Responsible-Ai-Moderation-Models/", 'models/detoxify/'+ check_point
|
| 65 |
-
log.info(f"test log: {value}")
|
| 66 |
-
|
| 67 |
log.info(f"checkpoint Path is: {os.path.join(application_path, 'models/detoxify/'+ check_point)}")
|
| 68 |
-
|
| 69 |
-
log.info(
|
| 70 |
-
toxicityModel = Detoxify(checkpoint=os.path.join(
|
| 71 |
device=device,
|
| 72 |
-
huggingface_config_path=os.path.join(
|
| 73 |
-
tokenizer = AutoTokenizer.from_pretrained(os.path.join(
|
| 74 |
-
|
| 75 |
|
|
|
|
| 76 |
PromptModel_dberta = AutoModelForSequenceClassification.from_pretrained(os.path.join(application_path, "models/dbertaInjection")).to(device)
|
| 77 |
Prompttokens_dberta = AutoTokenizer.from_pretrained(os.path.join(application_path, "models/dbertaInjection"))
|
| 78 |
promtModel = pipeline("text-classification", model=PromptModel_dberta, tokenizer=Prompttokens_dberta, device=device)
|
|
|
|
| 79 |
|
| 80 |
#topictokenizer_Facebook = AutoTokenizer.from_pretrained("../models/facebook")
|
| 81 |
#topicmodel_Facebook = AutoModelForSequenceClassification.from_pretrained("../models/facebook").to(device)
|
| 82 |
|
|
|
|
| 83 |
topictokenizer_dberta = AutoTokenizer.from_pretrained(os.path.join(application_path,"models/restricted-dberta-base-zeroshot-v2"))
|
| 84 |
topicmodel_dberta = AutoModelForSequenceClassification.from_pretrained(os.path.join(application_path,"models/restricted-dberta-base-zeroshot-v2")).to(device)
|
| 85 |
nlp = pipeline('zero-shot-classification', model=topicmodel_dberta, tokenizer=topictokenizer_dberta,device=gpu)
|
|
|
|
| 86 |
# classifier = pipeline("zero-shot-classification",model="../../models/facebook",device=device)
|
| 87 |
# classifier2 = pipeline("zero-shot-classification",model="../../models/restricted-dberta-large-zeroshot",device=device)
|
| 88 |
-
encoder = SentenceTransformer(os.path.join(application_path, "models/multi-qa-mpnet-base-dot-v1")).to(device)
|
| 89 |
|
|
|
|
|
|
|
|
|
|
| 90 |
jailbreakModel = encoder
|
| 91 |
similarity_model =encoder
|
| 92 |
request_id_var.set("Startup")
|
|
|
|
| 36 |
if getattr(sys, 'frozen', False):
|
| 37 |
application_path = sys._MEIPASS
|
| 38 |
else:
|
| 39 |
+
application_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
|
| 40 |
|
| 41 |
|
| 42 |
log=CustomLogger()
|
|
|
|
| 59 |
# print(os.listdir())
|
| 60 |
check_point = 'toxic_debiased-c7548aa0.ckpt'
|
| 61 |
log.info(f"device is: {device}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
log.info(f"checkpoint Path is: {os.path.join(application_path, 'models/detoxify/'+ check_point)}")
|
| 63 |
+
log.info(f"huggingface_config_path Path is: {os.path.join(application_path, 'models/detoxify/'+ check_point)}")
|
| 64 |
+
log.info("Loading toxicity model")
|
| 65 |
+
toxicityModel = Detoxify(checkpoint=os.path.join(application_path, 'models/detoxify/'+ check_point),
|
| 66 |
device=device,
|
| 67 |
+
huggingface_config_path=os.path.join(application_path, 'models/detoxify'))
|
| 68 |
+
tokenizer = AutoTokenizer.from_pretrained(os.path.join(application_path, "models/detoxify"))
|
| 69 |
+
log.info("Toxicity model loaded")
|
| 70 |
|
| 71 |
+
log.info("Loading prompt injection model")
|
| 72 |
PromptModel_dberta = AutoModelForSequenceClassification.from_pretrained(os.path.join(application_path, "models/dbertaInjection")).to(device)
|
| 73 |
Prompttokens_dberta = AutoTokenizer.from_pretrained(os.path.join(application_path, "models/dbertaInjection"))
|
| 74 |
promtModel = pipeline("text-classification", model=PromptModel_dberta, tokenizer=Prompttokens_dberta, device=device)
|
| 75 |
+
log.info("Loaded prompt injection model")
|
| 76 |
|
| 77 |
#topictokenizer_Facebook = AutoTokenizer.from_pretrained("../models/facebook")
|
| 78 |
#topicmodel_Facebook = AutoModelForSequenceClassification.from_pretrained("../models/facebook").to(device)
|
| 79 |
|
| 80 |
+
log.info("Loading restricted topic model")
|
| 81 |
topictokenizer_dberta = AutoTokenizer.from_pretrained(os.path.join(application_path,"models/restricted-dberta-base-zeroshot-v2"))
|
| 82 |
topicmodel_dberta = AutoModelForSequenceClassification.from_pretrained(os.path.join(application_path,"models/restricted-dberta-base-zeroshot-v2")).to(device)
|
| 83 |
nlp = pipeline('zero-shot-classification', model=topicmodel_dberta, tokenizer=topictokenizer_dberta,device=gpu)
|
| 84 |
+
log.info("Loaded restricted topic model")
|
| 85 |
# classifier = pipeline("zero-shot-classification",model="../../models/facebook",device=device)
|
| 86 |
# classifier2 = pipeline("zero-shot-classification",model="../../models/restricted-dberta-large-zeroshot",device=device)
|
|
|
|
| 87 |
|
| 88 |
+
log.info("Loading similarity model")
|
| 89 |
+
encoder = SentenceTransformer(os.path.join(application_path, "models/multi-qa-mpnet-base-dot-v1")).to(device)
|
| 90 |
+
log.info("Loaded similarity model")
|
| 91 |
jailbreakModel = encoder
|
| 92 |
similarity_model =encoder
|
| 93 |
request_id_var.set("Startup")
|