Skip to content

Commit f3b925e

Browse files
Address review comments on lm_eval_hf.py
- Annotate trust_remote_code propagation as user-driven (satisfies CodeRabbit Security Anti-Pattern check on hardcoded trust_remote_code=True). - Guard the private cli._subparsers access with a clear RuntimeError so a future lm-eval refactor surfaces a useful error instead of AttributeError. Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
1 parent 4727635 commit f3b925e

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

examples/llm_eval/lm_eval_hf.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def _inject_modelopt_args_into_model_args(args):
248248
model_args = dict(args.model_args) if args.model_args else {}
249249

250250
if getattr(args, "trust_remote_code", False):
251+
# Propagate the user-provided --trust_remote_code flag (not hardcoded).
251252
datasets.config.HF_DATASETS_TRUST_REMOTE_CODE = True
252253
model_args["trust_remote_code"] = True
253254
args.trust_remote_code = None
@@ -264,7 +265,16 @@ def _inject_modelopt_args_into_model_args(args):
264265
setup_logging()
265266
cli = HarnessCLI()
266267
# The `run` subcommand owns the model/task arguments; extend that parser.
267-
_add_modelopt_args(cli._subparsers.choices["run"])
268+
# `_subparsers` is private API; guard so a future lm-eval refactor surfaces a
269+
# clear error instead of an opaque AttributeError.
270+
try:
271+
run_parser = cli._subparsers.choices["run"]
272+
except (AttributeError, KeyError) as e:
273+
raise RuntimeError(
274+
"Cannot locate lm-eval's `run` subparser; the HarnessCLI internals may "
275+
f"have changed. Installed lm-eval version: {version('lm_eval')}."
276+
) from e
277+
_add_modelopt_args(run_parser)
268278
args = cli.parse_args()
269279
_inject_modelopt_args_into_model_args(args)
270280
cli.execute(args)

0 commit comments

Comments
 (0)