Skip to content

feat: Run dataset and model initializers in parallel#313

Merged
google-oss-prow[bot] merged 3 commits into
kubeflow:mainfrom
priyank766:feat/parallel-initializers-290
Mar 18, 2026
Merged

feat: Run dataset and model initializers in parallel#313
google-oss-prow[bot] merged 3 commits into
kubeflow:mainfrom
priyank766:feat/parallel-initializers-290

Conversation

@priyank766

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:
Currently, the ContainerBackend (Docker/Podman) runs dataset and model initializers sequentially. For Large Language Model (LLM) fine-tuning or heavy data workloads, downloading both a massive dataset and a base model separately can add significant overhead to the job startup time.

This PR refactors the _run_initializers logic to use concurrent.futures.ThreadPoolExecutor. If both a dataset and a model are configured, they are now initialized in parallel threads. This reduces the total initialization time to the duration of the longest single download, rather than the sum of both.

Key technical changes:

  • Refactored kubeflow/trainer/backends/container/backend.py to use a thread pool for parallel initializer dispatch.
  • Added import concurrent.futures to the backend.
  • Ensured thread safety and proper error propagation (if one initializer fails, the main thread correctly identifies the failure and cleans up).
  • Verified that shared volume mounts work correctly during concurrent writes from separate containers.

Which issue(s) this PR fixes:
Fixes #290

Checklist:

  • Docs included if any changes are user facing (Internal performance improvement, no change to public API surface)
  • Unit tests pass: uv run pytest kubeflow/trainer/backends/container/backend_test.py
  • Code adheres to Ruff formatting/linting standards verified via make verify.

Verification Results:
Ran the specific backend tests to confirm the threading logic works as expected without race conditions:

uv run pytest kubeflow/trainer/backends/container/backend_test.py
# Result: 19 passed

Copilot AI review requested due to automatic review settings February 22, 2026 09:00
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Welcome to the Kubeflow SDK! 🎉

Thanks for opening your first PR! We're happy to have you as part of our community 🚀

Here's what happens next:

  • If you haven't already, please check out our Contributing Guide for repo-specific guidelines and the Kubeflow Contributor Guide for general community standards
  • Our team will review your PR soon! cc @kubeflow/kubeflow-sdk-team

Join the community:

Feel free to ask questions in the comments if you need any help or clarification!
Thanks again for contributing to Kubeflow! 🙏

Copilot AI 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.

Pull request overview

This PR refactors the ContainerBackend to run dataset and model initializers in parallel using Python's ThreadPoolExecutor, reducing total initialization time from sequential (sum of both downloads) to parallel (duration of the longest download). This is particularly beneficial for LLM fine-tuning workloads with large datasets and models.

Changes:

  • Refactored _run_initializers to use concurrent.futures.ThreadPoolExecutor with max_workers=2
  • Updated method documentation to reflect parallel execution
  • Modified logging messages to indicate queueing and parallel completion

@priyank766 priyank766 force-pushed the feat/parallel-initializers-290 branch 2 times, most recently from af5276e to be3c0a8 Compare February 22, 2026 09:07
@priyank766 priyank766 changed the title feat(container): Run dataset and model initializers in parallel (#290) feat : Run dataset and model initializers in parallel (#290) Feb 22, 2026
@priyank766

Copy link
Copy Markdown
Contributor Author

I wanted to know this issue is Open right i submitted PR but I had issue for PR Title can anyone can help me as I didn't get the format for PR Title issue
@astefanutti

@astefanutti

Copy link
Copy Markdown
Contributor

/retitle feat: Run dataset and model initializers in parallel

@google-oss-prow google-oss-prow Bot changed the title feat : Run dataset and model initializers in parallel (#290) feat: Run dataset and model initializers in parallel Feb 23, 2026

@astefanutti astefanutti 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.

/ok-to-test

@priyank766 priyank766 force-pushed the feat/parallel-initializers-290 branch from bb80231 to c05ed89 Compare February 23, 2026 16:19
@priyank766

Copy link
Copy Markdown
Contributor Author

@astefanutti E2E Test are solved here

@Fiona-Waters Fiona-Waters 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.

Thanks @priyank766 this looks good. Just a couple of suggestions.

Comment thread kubeflow/trainer/backends/container/backend.py Outdated
Comment thread kubeflow/trainer/backends/container/backend.py Outdated
@priyank766

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! Addressed both points:

  1. Refactored the dataset and model initializer dispatch into a loop over an initializer_configs list, which also makes it straightforward to add new initializer types in the future.
  2. Updated the log message as you said to include the names of the initializers that completed, e.g. Initializers completed in parallel: ['dataset', 'model'].
    @Fiona-Waters

@priyank766 priyank766 requested a review from Fiona-Waters March 4, 2026 14:01

@Fiona-Waters Fiona-Waters 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.

@priyank766 This looks great now. I would like to test it on my machine, will do that as soon as I can and will get back to you. Thanks

@priyank766

Copy link
Copy Markdown
Contributor Author

Sure I would love to hear your feedback and thoughts
@Fiona-Waters

@Fiona-Waters Fiona-Waters 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.

Was able to run this successfully on my local machine using Docker. Thanks @priyank766
/lgtm

@google-oss-prow google-oss-prow Bot added the lgtm label Mar 5, 2026
Comment thread kubeflow/trainer/backends/container/backend.py
@priyank766 priyank766 requested a review from kramaranya March 8, 2026 18:53
@andreyvelich

Copy link
Copy Markdown
Member

/lgtm
/approve
/hold in case @Fiona-Waters or @kramaranya has any additional comments.

@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andreyvelich

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@andreyvelich

Copy link
Copy Markdown
Member

/hold cancel

@google-oss-prow google-oss-prow Bot merged commit 6d1d5a2 into kubeflow:main Mar 18, 2026
18 of 19 checks passed
@google-oss-prow google-oss-prow Bot added this to the v0.4 milestone Mar 18, 2026
@priyank766 priyank766 deleted the feat/parallel-initializers-290 branch March 18, 2026 12:43
1Ayush-Petwal added a commit to 1Ayush-Petwal/sdk that referenced this pull request Mar 21, 2026
Add docs/source/train/initializers.rst documenting the dataset and
model initializer types (HuggingFaceDatasetInitializer, S3DatasetInitializer,
DataCacheInitializer, HuggingFaceModelInitializer, S3ModelInitializer)
that were added to the container backend in PRs kubeflow#188 and kubeflow#313.

The guide covers: concept overview, per-initializer code examples,
combined usage, ContainerBackendConfig options (images, timeout),
log-based debugging, and backend limitations.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1Ayush-Petwal added a commit to 1Ayush-Petwal/sdk that referenced this pull request Mar 21, 2026
Add docs/source/train/initializers.rst covering dataset and model
initializers for the container backend (added in kubeflow#188, parallelised
in kubeflow#313). Includes per-type code examples, combined usage, ContainerBackendConfig
options, and debugging via get_job_logs().
1Ayush-Petwal added a commit to 1Ayush-Petwal/sdk that referenced this pull request Mar 21, 2026
Add docs/source/train/initializers.rst covering dataset and model
initializers for the container backend (added in kubeflow#188, parallelised
in kubeflow#313). Includes per-type code examples, combined usage, ContainerBackendConfig
options, and debugging via get_job_logs().
1Ayush-Petwal added a commit to 1Ayush-Petwal/sdk that referenced this pull request Mar 21, 2026
Add docs/source/train/initializers.rst covering dataset and model
initializers for the container backend (added in kubeflow#188, parallelised
in kubeflow#313). Includes per-type code examples, combined usage, ContainerBackendConfig
options, and debugging via get_job_logs().

Signed-off-by: Ayush Petwal <[email protected]>
1Ayush-Petwal added a commit to 1Ayush-Petwal/sdk that referenced this pull request Mar 28, 2026
Add docs/source/train/initializers.rst covering dataset and model
initializers for the container backend (added in kubeflow#188, parallelised
in kubeflow#313). Includes per-type code examples, combined usage, ContainerBackendConfig
options, and debugging via get_job_logs().

Signed-off-by: Ayush Petwal <[email protected]>
1Ayush-Petwal added a commit to 1Ayush-Petwal/sdk that referenced this pull request Apr 10, 2026
Add docs/source/train/initializers.rst covering dataset and model
initializers for the container backend (added in kubeflow#188, parallelised
in kubeflow#313). Includes per-type code examples, combined usage, ContainerBackendConfig
options, and debugging via get_job_logs().

Signed-off-by: Ayush Petwal <[email protected]>
google-oss-prow Bot pushed a commit that referenced this pull request Apr 10, 2026
* chore(trainer): add data and model initializers guide

Add docs/source/train/initializers.rst covering dataset and model
initializers for the container backend (added in #188, parallelised
in #313). Includes per-type code examples, combined usage, ContainerBackendConfig
options, and debugging via get_job_logs().

Signed-off-by: Ayush Petwal <[email protected]>

* docs(trainer): address PR review comments on initializers guide

- Fix model output path from /workspace/model-weights to /workspace/model
  to match the MODEL_PATH constant in constants.py
- Clarify DataCacheInitializer is Kubernetes-only in the backend note
  and annotate the Available Initializers table row accordingly
- Add DataCacheInitializer usage example with required fields
  (storage_uri, metadata_loc, num_data_nodes) and backend constraint note

Signed-off-by: 1Ayush-Petwal <[email protected]>

* docs(trainer): use latest tag for initializer images in guide

Signed-off-by: 1Ayush-Petwal <[email protected]>

---------

Signed-off-by: Ayush Petwal <[email protected]>
Signed-off-by: 1Ayush-Petwal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(container): Run dataset and model initializers in parallel

6 participants