From 701ecbb2921cd1abf488cecc246f73c436f23c68 Mon Sep 17 00:00:00 2001 From: binary-husky <96192199+binary-husky@users.noreply.github.com> Date: Fri, 26 Apr 2024 21:58:45 +0800 Subject: [PATCH] [Fix] python path bug (#1063) * fix relative path bug * format --------- Co-authored-by: hmp <505030475@qq.com> Co-authored-by: Leymore --- opencompass/tasks/openicl_eval.py | 6 ++++-- opencompass/tasks/openicl_infer.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/opencompass/tasks/openicl_eval.py b/opencompass/tasks/openicl_eval.py index 8351d81c..a11bb4cd 100644 --- a/opencompass/tasks/openicl_eval.py +++ b/opencompass/tasks/openicl_eval.py @@ -2,13 +2,14 @@ import argparse import copy import fnmatch import math +import os import os.path as osp import re import statistics +import sys import time from collections import Counter from inspect import signature -from shutil import which from typing import List, Optional import mmengine @@ -76,8 +77,9 @@ class OpenICLEvalTask(BaseTask): 'task', {}).get('dump_details', False) def get_command(self, cfg_path, template): + sys.path.append(os.getcwd()) script_path = __file__ - python = 'python3' if which('python3') else 'python' + python = sys.executable command = f'{python} {script_path} {cfg_path}' return template.format(task_cmd=command) diff --git a/opencompass/tasks/openicl_infer.py b/opencompass/tasks/openicl_infer.py index 6d384b35..fa47df33 100644 --- a/opencompass/tasks/openicl_infer.py +++ b/opencompass/tasks/openicl_infer.py @@ -1,8 +1,9 @@ import argparse +import os import os.path as osp import random +import sys import time -from shutil import which from typing import Any from mmengine.config import Config, ConfigDict @@ -42,6 +43,7 @@ class OpenICLInferTask(BaseTask): template (str): The template which have '{task_cmd}' to format the command. """ + sys.path.append(os.getcwd()) script_path = __file__ backend_keys = ['VLLM', 'Lmdeploy'] use_backend = any( @@ -54,7 +56,7 @@ class OpenICLInferTask(BaseTask): f'--nproc_per_node {self.num_procs} ' f'{script_path} {cfg_path}') else: - python = 'python3' if which('python3') else 'python' + python = sys.executable command = f'{python} {script_path} {cfg_path}' return template.format(task_cmd=command)