| 3 | |
| 4 | |
| 5 | class MyModelWorker(BaseWorker): |
| 6 | |
| 7 | def load_model_and_tokenizer(self, load_config): |
| 8 | # TODO: load your model here |
| 9 | hf_model_config = {"pretrained_model_name_or_path": load_config['config_dir'],'trust_remote_code': True, 'low_cpu_mem_usage': True} |
| 10 | hf_tokenizer_config = {"pretrained_model_name_or_path": load_config['config_dir'], 'padding_side': 'left', 'trust_remote_code': True} |
| 11 | precision = load_config.get('precision', 'fp16') |
| 12 | device = load_config.get('device', 'cuda') |
| 13 | assert device == "cuda", 'only supports CUDA inference' |
| 14 | |
| 15 | if precision == 'fp16': |
| 16 | hf_model_config.update({"torch_dtype": torch.float16}) |
| 17 | |
| 18 | model = AutoModelForCausalLM.from_pretrained(**hf_model_config) |
| 19 | tokenizer = AutoTokenizer.from_pretrained(**hf_tokenizer_config) |
| 20 | |
| 21 | model.eval() |
| 22 | return model, tokenizer |
| 23 | |
| 24 | @property |
| 25 | def system_prompt(self): |
| 26 | return "一位用户和智能医疗大模型HuatuoGPT之间的对话。对于用户的医疗问诊,HuatuoGPT给出准确的、详细的、温暖的指导建议。对于用户的指令问题,HuatuoGPT给出有益的、详细的、有礼貌的回答。" |
| 27 | @property |
| 28 | def instruction_template(self): |
| 29 | return self.system_prompt + '问:{instruction}\n答:' |
| 30 | @property |
| 31 | def instruction_template_with_fewshot(self,): |
| 32 | return self.system_prompt + '{fewshot_examples}问:{instruction}\n答:' |
| 33 | @property |
| 34 | def fewshot_template(self): |
| 35 | return "问:{user}\n答:{gpt}\n" |
| 36 | |
| 37 | def collate_conv(self, data): |
| 38 | raise NotImplementedError |
| 39 | |
| 40 |
nothing calls this directly
no outgoing calls
no test coverage detected