Skip to content

Commit

Permalink
feat(huixiangdou/service/feature_store.py): support language option
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisonooo committed Jan 15, 2024
1 parent 68bd522 commit 93ed059
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ models/
repodir/
workdir/
write_toml.py
modeling_internlm2.py
config.ini
config-template.ini
logs/
Expand Down
7 changes: 5 additions & 2 deletions huixiangdou/service/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class FeatureStore:

def __init__(self,
device: str = 'cuda',
config_path: str = 'config.ini') -> None:
config_path: str = 'config.ini',
language: str = 'zh') -> None:
"""Init with model device type and config."""
self.config_path = config_path
self.reject_throttle = -1
self.language = language
with open(config_path, encoding='utf8') as f:
config = pytoml.load(f)['feature_store']
model_path = config['model_path']
Expand Down Expand Up @@ -153,7 +155,8 @@ def ingress_response(self, markdown_dir: str, work_dir: str):
full_text = str(p).rsplit('/_',
maxsplit=1)[-1] + '\n' + f.read()
if '.md' in str(p):
if not self.is_chinese_doc(full_text):
if self.language == 'zh' and not self.is_chinese_doc(
full_text): # noqa E501
continue

full_texts.append(full_text)
Expand Down
2 changes: 1 addition & 1 deletion huixiangdou/service/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, work_dir: str, config_path: str, language: str = 'zh'):
language (str, optional): Specifies the language to be used. Defaults to 'zh' (Chinese). # noqa E501
"""
self.llm = ChatClient(config_path=config_path)
self.fs = FeatureStore(config_path=config_path)
self.fs = FeatureStore(config_path=config_path, language=language)
self.fs.load_feature(work_dir=work_dir)
self.config_path = config_path
self.config = None
Expand Down
2 changes: 0 additions & 2 deletions tests/test_internlm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
device_map='auto',
torch_dtype='auto').eval()

# 不能像某些 LLM 一样 AutoModelForCausalLM.from_pretrained(.. fp16=True) 这样写,会 Internlm2Config.__init__() 报错

queries = ['how to install mmdeploy ?']
for query in queries:
pdb.set_trace()
Expand Down

0 comments on commit 93ed059

Please sign in to comment.