-
Notifications
You must be signed in to change notification settings - Fork 28
/
meta.py
36 lines (31 loc) · 1.04 KB
/
meta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import os
from transformers import AutoConfig
class Meta:
def __init__(
self,
model_path: str,
model_name: str,
use_sentence_transformer_vectorizer: bool,
trust_remote_code: bool,
):
if use_sentence_transformer_vectorizer:
if os.path.exists(f"{model_path}/model_config"):
with open(f"{model_path}/model_config", "r") as f:
self.config = json.loads(f.read())
else:
self.config = {"model_name": model_name, "model_type": None}
else:
self.config = AutoConfig.from_pretrained(
model_path, trust_remote_code=trust_remote_code
).to_dict()
def get(self):
return {"model": self.config}
def get_model_type(self):
return self.config["model_type"]
def get_architecture(self):
architecture = None
conf = self.config
if "architectures" in conf:
architecture = conf["architectures"][0]
return architecture