Skip to content

Studio: simplify the inference orchestrator and worker - #6439

Merged
oobabooga merged 2 commits into
unslothai:mainfrom
oobabooga:studio-inference-cleanup
Jun 18, 2026
Merged

oobabooga merged 2 commits into
unslothai:mainfrom
oobabooga:studio-inference-cleanup

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Refactor only, no behavior change. Removes about 190 lines of duplicated code and dead state from the two inference backend files, orchestrator.py (parent process) and worker.py (model subprocess).

Rebased on #6391, so its Nemotron trust check and the malware/consent security gates work exactly as before.

Details

orchestrator.py:

  • The token-reading loop was copy-pasted three times (normal, compare-mode, and audio generation). It is now one helper, _consume_token_stream, that takes a read_one callback so each path can keep reading its own queue (shared resp_queue under _gen_lock, or the per-request mailbox on the dispatcher path).
  • The generate command dict was built in two places. It is now built once in _build_generate_cmd, and _generate_locked folds back into its caller.
  • Removed unused instance state (_lock, loaded_local_models, _current_transformers_major) and the unused structlog import.

worker.py:

  • Deleted the in-file download stall monitor (_get_hf_download_state and _start_heartbeat, about 130 lines) and called start_watchdog from utils.hf_xet_fallback instead, which already does the same thing.
  • The ts timestamp was stamped on every outgoing message by hand. _send_response now stamps it once via setdefault.
  • Pulled a few inline blocks in the load path out into named helpers (_clean_token, _needs_nemotron_trust, _resolve_lora_4bit, _ensure_backend_on_path).

@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 refactors the inference orchestrator and worker to reduce code duplication and improve maintainability. Key changes include consolidating generation command building and token stream consumption into shared helper methods (_build_generate_cmd and _consume_token_stream), simplifying response handling by automatically stamping timestamps in _send_response, and leveraging a shared watchdog utility for heartbeats. Additionally, unused imports, fields, and redundant inline imports were cleaned up. One review comment suggests checking the cancellation event at the beginning of the token stream consumption loop to ensure immediate responsiveness during timeouts or status updates.

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.

@oobabooga
oobabooga merged commit b4fa48e into unslothai:main Jun 18, 2026
24 of 27 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.

1 participant