(model, dataset, output_path, device_num, n = 200, temperature = 0.7, dataset_repo = "test_dataset", prefix = None, suffix = None, chat = False, context_length = None)
| 827 | |
| 828 | |
| 829 | def batch_infer_local_model(model, dataset, output_path, device_num, n = 200, temperature = 0.7, dataset_repo = "test_dataset", prefix = None, suffix = None, chat = False, context_length = None): |
| 830 | if isinstance(model, str): |
| 831 | model = LocalModel(model, device_num) |
| 832 | |
| 833 | if dataset != "mbpp": |
| 834 | dataset = Dataset(dataset, data_path = os.path.join(dataset_repo, dataset.replace("/", "_")), full = False) |
| 835 | else: |
| 836 | dataset = Dataset(dataset, data_path = os.path.join(dataset_repo, dataset.replace("/", "_")), testfile_path = "datasets/MbppPlus.jsonl", full = False) |
| 837 | |
| 838 | if not chat: |
| 839 | prompts, overlong_prompts = dataset.get_all_prompts(model = model, context_length = context_length) |
| 840 | if prefix != None or suffix != None: |
| 841 | new_prompts = [] |
| 842 | for prompt in prompts: |
| 843 | new_prompts.append((prefix if prefix != None else "") + prompt + (suffix if suffix != None else "")) |
| 844 | prompts = new_prompts |
| 845 | print("{} overlong prompts found.".format(len(overlong_prompts))) |
| 846 | else: |
| 847 | dialogs = dataset.get_all_chats() |
| 848 | try: |
| 849 | if not chat: |
| 850 | results = model.infer_many(prompts, n = n, temperature = temperature) |
| 851 | for p in overlong_prompts: |
| 852 | results[p] = ["Overlong input prompts.", False] |
| 853 | else: |
| 854 | results = model.infer_many_chats(dialogs) |
| 855 | except Exception as e: |
| 856 | logger.error("Error occurred with reason: {}. INFO Dataset: {}\nModel: {}\n".format(str(e), dataset.name, model.name)) |
| 857 | traceback.print_exc() |
| 858 | |
| 859 | res_dir_path = os.path.join(output_path, dataset.name.replace("/", "_")) |
| 860 | res_path = os.path.join(res_dir_path, model.name.replace("/", "_") + ".json") |
| 861 | |
| 862 | if not os.path.exists(res_dir_path): |
| 863 | os.mkdir(res_dir_path) |
| 864 | |
| 865 | with open(res_path, "w", encoding="utf-8") as of: |
| 866 | of.write(json.dumps(results, sort_keys=True, indent=4, separators=(',', ': '))) |
| 867 | |
| 868 | |
| 869 | def batch_infer_local_chat_model(model, mode, rd, input_file, output_path): |
no test coverage detected