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.
Bug
In
src/llamafactory/chat/hf_engine.py, four static methods useinput_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
Noneand assign{}inside the function body.