Skip to content

Commit 0cf20a2

Browse files
authored
[fix] cli_evaluate to properly handle Namespace arguments (#733)
* Fix cli_evaluate to properly handle Namespace arguments This fixes an issue where cli_evaluate would fail when called programmatically with an argparse.Namespace object and empty sys.argv. The function now: 1. Always parses default arguments first 2. Only checks sys.argv when no args are provided (args is None) 3. Merges provided Namespace attributes with defaults This enables the function to be called from other Python modules while maintaining backward compatibility with command-line usage. Fixes the issue where passing args as Namespace fails due to sys.argv check. * lint
1 parent c0c0a97 commit 0cf20a2

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lmms_eval/__main__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,23 @@ def parse_eval_args() -> argparse.Namespace:
271271

272272

273273
def cli_evaluate(args: Union[argparse.Namespace, None] = None) -> None:
274-
if not args:
275-
args = parse_eval_args()
274+
default_args = parse_eval_args()
276275

277-
# Check if no arguments were passed after parsing
278-
if len(sys.argv) == 1:
276+
if args is None and len(sys.argv) == 1:
279277
print("┌───────────────────────────────────────────────────────────────────────────────┐")
280278
print("│ Please provide arguments to evaluate the model. e.g. │")
281279
print("│ `lmms-eval --model llava --model_path liuhaotian/llava-v1.6-7b --tasks okvqa` │")
282280
print("│ Use `lmms-eval --help` for more information. │")
283281
print("└───────────────────────────────────────────────────────────────────────────────┘")
284282
sys.exit(1)
285283

284+
# If args were provided, override the defaults
285+
if args:
286+
for key, value in vars(args).items():
287+
setattr(default_args, key, value)
288+
289+
args = default_args
290+
286291
if args.wandb_args:
287292
if "name" not in args.wandb_args:
288293
name = f"{args.model}_{args.model_args}_{utils.get_datetime_str(timezone=args.timezone)}"

lmms_eval/tasks/camerabench_vqa/utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
SUFFIX_FOR_VQA = {"yes_no": "Please answer Yes or No.", "multiple_choice": "Please output the letter corresponding to the correct option."}
77

88

9-
109
def get_scores(scores):
1110
"""
1211
Calculate various scores based on the given results.
@@ -148,11 +147,8 @@ def find_word_position(string, word):
148147

149148
def cambench_doc_to_visual(doc):
150149
try:
151-
default_path = os.path.join(os.getenv('HOME'), '.cache/huggingface')
152-
load_path = os.path.expanduser(os.path.join(
153-
os.getenv("HF_HOME", default_path),
154-
'camerabench_vqa/datasets--chancharikm--camerabench_vqa_lmms_eval/snapshots'
155-
))
150+
default_path = os.path.join(os.getenv("HOME"), ".cache/huggingface")
151+
load_path = os.path.expanduser(os.path.join(os.getenv("HF_HOME", default_path), "camerabench_vqa/datasets--chancharikm--camerabench_vqa_lmms_eval/snapshots"))
156152

157153
if not os.path.exists(load_path):
158154
raise FileNotFoundError(f"Dataset path not found: {load_path}")

0 commit comments

Comments
 (0)