Skip to content

feat(webui): add seed controls for reproducibility#10629

Merged
hiyouga merged 1 commit into
hiyouga:mainfrom
kmishra1204:codex/substantive-llamafactory
Jul 7, 2026
Merged

feat(webui): add seed controls for reproducibility#10629
hiyouga merged 1 commit into
hiyouga:mainfrom
kmishra1204:codex/substantive-llamafactory

Conversation

@kmishra1204

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #10581.

Adds explicit seed controls in the WebUI so users can reproduce generation, training, and evaluation/prediction runs without discovering the JSON extra_args escape hatch.

Changes:

  • Adds a chat generation seed field, with -1 preserving the current random behavior.
  • Passes generation seeds through the WebUI chatter path into HF, vLLM, and SGLang inference engines.
  • Adds explicit training and evaluation seed fields in the WebUI and includes them in generated CLI args.
  • Adds locale labels for the new controls.

Validation:

  • uvx ruff check src\llamafactory\webui\components\chatbot.py src\llamafactory\webui\components\train.py src\llamafactory\webui\components\eval.py src\llamafactory\webui\chatter.py src\llamafactory\webui\runner.py src\llamafactory\chat\hf_engine.py src\llamafactory\chat\vllm_engine.py src\llamafactory\chat\sglang_engine.py src\llamafactory\webui\locales.py
  • git diff --check
  • py -m py_compile src\llamafactory\webui\components\chatbot.py src\llamafactory\webui\components\train.py src\llamafactory\webui\components\eval.py src\llamafactory\webui\chatter.py src\llamafactory\webui\runner.py src\llamafactory\chat\hf_engine.py src\llamafactory\chat\vllm_engine.py src\llamafactory\chat\sglang_engine.py src\llamafactory\webui\locales.py

Full runtime generation/training tests were not run locally because this environment does not have the heavyweight ML runtime dependencies installed, and I avoided pulling them for this focused WebUI/argument-wiring change.

Before submitting

  • Did you read the contributor guideline?
  • Did you write any new necessary tests? Not applicable for this WebUI/argument-wiring change; targeted lint, whitespace, and syntax checks are included above.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for configuring random seeds across the training, evaluation, and chat interfaces in the WebUI, as well as in the Hugging Face, SGLang, and vLLM chat engines. The review feedback points out potential crash risks in the WebUI runner when parsing the 'train_seed' and 'eval_seed' textboxes, as calling int() directly on empty or non-numeric inputs will raise a ValueError. It is recommended to safely parse these inputs with a fallback default value.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/llamafactory/webui/runner.py Outdated
learning_rate=float(get("train.learning_rate")),
num_train_epochs=float(get("train.num_train_epochs")),
max_samples=int(get("train.max_samples")),
seed=int(get("train.train_seed")),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If the user clears the train_seed textbox or inputs an invalid/non-numeric value, calling int() directly on it will raise a ValueError and crash the WebUI runner thread.

To prevent this, we should safely parse the seed and fall back to the default seed of 42 if the input is empty or invalid.

Suggested change
seed=int(get("train.train_seed")),
seed=int(get("train.train_seed").strip()) if get("train.train_seed") and get("train.train_seed").strip().isdigit() else 42,

Comment thread src/llamafactory/webui/runner.py Outdated
max_new_tokens=get("eval.max_new_tokens"),
top_p=get("eval.top_p"),
temperature=get("eval.temperature"),
seed=int(get("eval.eval_seed")),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similarly to train_seed, if the user clears the eval_seed textbox or inputs an invalid/non-numeric value, calling int() directly on it will raise a ValueError and crash the WebUI runner thread.

We should safely parse the seed and fall back to the default seed of 42 if the input is empty or invalid.

Suggested change
seed=int(get("eval.eval_seed")),
seed=int(get("eval.eval_seed").strip()) if get("eval.eval_seed") and get("eval.eval_seed").strip().isdigit() else 42,

@kmishra1204 kmishra1204 force-pushed the codex/substantive-llamafactory branch from cd249f9 to 10ce5ff Compare July 7, 2026 05:24
@kmishra1204

Copy link
Copy Markdown
Contributor Author

Addressed the seed parsing review in the latest push.

Change made:

  • Added a small _parse_seed(...) helper in webui/runner.py so blank or non-numeric training/eval seed textbox values fall back to the default 42 instead of raising ValueError.
  • Kept chat generation seed handling unchanged because that path uses a numeric Gradio control and already normalizes negative values to the current random behavior.

Validation rerun:

  • uvx ruff check src\llamafactory\webui\components\chatbot.py src\llamafactory\webui\components\train.py src\llamafactory\webui\components\eval.py src\llamafactory\webui\chatter.py src\llamafactory\webui\runner.py src\llamafactory\chat\hf_engine.py src\llamafactory\chat\vllm_engine.py src\llamafactory\chat\sglang_engine.py src\llamafactory\webui\locales.py
  • py -m py_compile src\llamafactory\webui\components\chatbot.py src\llamafactory\webui\components\train.py src\llamafactory\webui\components\eval.py src\llamafactory\webui\chatter.py src\llamafactory\webui\runner.py src\llamafactory\chat\hf_engine.py src\llamafactory\chat\vllm_engine.py src\llamafactory\chat\sglang_engine.py src\llamafactory\webui\locales.py
  • git diff --check

@hiyouga hiyouga merged commit 5987a8d into hiyouga:main Jul 7, 2026
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to set a random seed in the weibuUI interface to control randomness

2 participants