Skip to content

fix: mutable default argument input_kwargs={} in HuggingfaceEngine static methods #10476

Description

@kuishou68

Bug

In src/llamafactory/chat/hf_engine.py, four static methods use input_kwargs: Optional[dict[str, Any]] = {} as a parameter default:

  • _process_args (line 85)
  • _chat (line 227)
  • _stream_chat (line 282)
  • _get_scores (line 321)

Using a mutable dict as a default argument is a classic Python pitfall — the same dict object is shared across all calls that don't pass input_kwargs. Since each method calls .pop() on it, the shared dict gets drained on the first call and subsequent callers using the default get an already-mutated object.

Fix

Change the default to None and assign {} inside the function body.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions