Skip to content

Commit c0a45e6

Browse files
authored
Merge pull request #47 from codefuse-ai/modelcache_dev
Modelcache dev
2 parents 31da4b7 + a2c6390 commit c0a45e6

File tree

5 files changed

+8
-16
lines changed

5 files changed

+8
-16
lines changed

modelcache/adapter/adapter.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# -*- coding: utf-8 -*-
22
import logging
3-
4-
import openai
53
from modelcache.adapter.adapter_query import adapt_query
64
from modelcache.adapter.adapter_insert import adapt_insert
75
from modelcache.adapter.adapter_remove import adapt_remove
86
from modelcache.adapter.adapter_register import adapt_register
97

108

11-
class ChatCompletion(openai.ChatCompletion):
9+
class ChatCompletion(object):
1210
"""Openai ChatCompletion Wrapper"""
1311

1412
@classmethod

modelcache/adapter/adapter_query.py

-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ def adapt_query(cache_data_convert, *args, **kwargs):
2222
extra_param=context.get("pre_embedding_func", None),
2323
prompts=chat_cache.config.prompts,
2424
)
25-
2625
if cache_enable:
2726
embedding_data = time_cal(
2827
chat_cache.embedding_func,
2928
func_name="embedding",
3029
report_func=chat_cache.report.embedding,
3130
)(pre_embedding_data)
32-
3331
if cache_enable:
3432
cache_data_list = time_cal(
3533
chat_cache.data_manager.search,
@@ -64,7 +62,6 @@ def adapt_query(cache_data_convert, *args, **kwargs):
6462
if rank_threshold_long < min_rank
6563
else rank_threshold_long
6664
)
67-
6865
if cache_data_list is None or len(cache_data_list) == 0:
6966
rank_pre = -1.0
7067
else:

modelcache/embedding/data2vec.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,23 @@ def mean_pooling(model_output, attention_mask):
1414

1515

1616
class Data2VecAudio(BaseEmbedding):
17-
def __init__(self, model: str = "model/text2vec-base-chinese/"):
17+
def __init__(self, model):
1818
current_dir = os.path.dirname(os.path.abspath(__file__))
1919
parent_dir = os.path.dirname(current_dir)
2020
model_dir = os.path.dirname(parent_dir)
21-
model = os.path.join(model_dir, model)
21+
model_path = os.path.join(model_dir, model)
22+
23+
self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
24+
self.tokenizer = BertTokenizer.from_pretrained(model_path, local_files_only=True)
25+
self.model = BertModel.from_pretrained(model_path, local_files_only=True)
2226

2327
try:
2428
self.__dimension = self.model.config.hidden_size
2529
except Exception:
2630
from transformers import AutoConfig
27-
2831
config = AutoConfig.from_pretrained(model)
2932
self.__dimension = config.hidden_size
3033

31-
self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
32-
self.tokenizer = BertTokenizer.from_pretrained(model, local_files_only=True)
33-
self.model = BertModel.from_pretrained(model, local_files_only=True)
34-
3534
def to_embeddings(self, data, **_):
3635
encoded_input = self.tokenizer(data, padding=True, truncation=True, return_tensors='pt')
3736
num_tokens = sum(map(len, encoded_input['input_ids']))

modelcache_mm/manager/vector_data/faiss.py

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ def add(self, datas: List[VectorData], model=None, mm_type=None):
2525
data_array, id_array = map(list, zip(*((data.data, data.id) for data in datas)))
2626
np_data = np.array(data_array).astype("float32")
2727
ids = np.array(id_array)
28-
print('insert_np_data: {}'.format(np_data))
29-
print('insert_np_data: {}'.format(np_data.shape))
3028
self._index.add_with_ids(np_data, ids)
3129

3230
def search(self, data: np.ndarray, top_k: int, model, mm_type='mm'):

modelcache_mm/manager/vector_data/manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from modelcache_mm.utils.error import NotFoundError, ParamError
33

44
TOP_K = 1
5-
FAISS_INDEX_PATH = "faiss.index"
5+
FAISS_INDEX_PATH = "mm_faiss.index"
66
DIMENSION = 0
77
MILVUS_HOST = "localhost"
88
MILVUS_PORT = 19530

0 commit comments

Comments
 (0)