Skip to content

Initialize base inference before training model creation - #2003

Open
j316chuck wants to merge 1 commit into
NovaSky-AI:mainfrom
j316chuck:chuck-codex/inference-ready-service
Open

Initialize base inference before training model creation#2003
j316chuck wants to merge 1 commit into
NovaSky-AI:mainfrom
j316chuck:chuck-codex/inference-ready-service

Conversation

@j316chuck

Copy link
Copy Markdown
Contributor
  • Initialize non-colocated base-model inference when the service starts, before any training model exists.
  • Publish a structured readiness event after the inference proxy reaches the shared engine-state database.
  • Reuse the warm inference client when the first training model is created.

Testing

ruff check skyrl/backends/skyrl_train_backend.py skyrl/tinker/engine.py tests/tinker/skyrl_train/test_text_only_batch_no_inference.py

Focused backend tests: 10 passed; two unrelated JAX engine tests require the JAX extra.

@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 introduces the ability to initialize base-model inference before the first training model is created, specifically when not colocated. It also adds a deployment event log when the inference proxy is published and includes a corresponding unit test. The review feedback highlights two main improvements: removing a redundant call to set_inference_engine_client in skyrl_train_backend.py since it is already handled during policy building, and replacing the naive bool() conversion in engine.py with a safer check to prevent string values like "False" from being evaluated as truthy.

Comment on lines +512 to +514
if self._inference_engines_initialized:
self._dispatch.set_inference_engine_client(self._inference_engine_client)
self.init_weight_sync_state()

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.

medium

The call to self._dispatch.set_inference_engine_client(self._inference_engine_client) is redundant here. self._dispatch is instantiated inside self._build_policy (called on the line immediately preceding this block) where self._inference_engine_client is already passed to the WorkerDispatch constructor. Removing this redundant call simplifies the initialization flow.

Suggested change
if self._inference_engines_initialized:
self._dispatch.set_inference_engine_client(self._inference_engine_client)
self.init_weight_sync_state()
if self._inference_engines_initialized:
self.init_weight_sync_state()

Comment thread skyrl/tinker/engine.py
if hasattr(self.backend, "set_inference_state_publisher"):
self.backend.set_inference_state_publisher(self._write_inference_state_to_db)

is_colocated = bool(config.backend_config.get("trainer.placement.colocate_all", True))

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.

medium

Using bool() directly on a configuration value retrieved from config.backend_config can lead to unexpected behavior if the value is parsed as a string (e.g., from command-line overrides or environment variables). In Python, bool("False") or bool("false") evaluates to True because any non-empty string is truthy. It is safer to explicitly check against common falsey string and boolean representations.

        colocate_val = config.backend_config.get("trainer.placement.colocate_all", True)
        is_colocated = colocate_val not in (False, "False", "false", 0, "0")

if not ray.is_initialized():
logger.info("Initializing Ray for base-model inference")
initialize_ray(self._cfg)
self._colocate_pg = self._create_colocate_pg() if self._cfg.trainer.placement.colocate_all else None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems like initialize_base_inference() is only ever called in non-colocated mode. What is the purpose of having this check here?

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.

2 participants