Skip to content

fix: added usages guide with examples to options reference #388#432

Open
aashvgit wants to merge 2 commits intokubeflow:mainfrom
aashvgit:docs/optionsdocs-388
Open

fix: added usages guide with examples to options reference #388#432
aashvgit wants to merge 2 commits intokubeflow:mainfrom
aashvgit:docs/optionsdocs-388

Conversation

@aashvgit
Copy link
Copy Markdown

What this PR does / why we need it:
Adds a comprehensive usage guide to the Options Reference page, and added an example how to pass options to TrainerClient.train().
Which issue(s) this PR fixes
#388

Fixes #
Added introduction explaining the 'options' parameter
--Added per-option usage examples ('Name', 'Labels', 'Annotations',
'TrainerCommand', 'TrainerArgs', 'RuntimePatch')
--Added a "Combining Multiple Options" example

  • Added a .. note:: about backend compatibility

Checklist:
.

Copilot AI review requested due to automatic review settings March 27, 2026 18:08
@google-oss-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign electronic-waste for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@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! 🙏

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a usage guide to the Trainer “Options Reference” documentation to help users understand how to pass options into TrainerClient.train() and apply common options.

Changes:

  • Added an introductory explanation and a basic options=[...] example for TrainerClient.train().
  • Added per-option sections (e.g., Name/Labels/Annotations) plus a “Combining Multiple Options” example.
  • Added a backend-compatibility note and kept the existing API reference (autoclass) list.

from kubeflow.trainer.options import Name

job_id = trainer_client.train(
trainer=CustomTrainer(fuc=train_function),
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This code sample also uses fuc= instead of func= for CustomTrainer, which makes it invalid if copied; update the keyword argument to func.

Copilot uses AI. Check for mistakes.
from kubeflow.trainer.options import Labels

job_id = trainer_client.train(
trainer=CustomTrainer(fuc=train_function),
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This code sample also uses fuc= instead of func= for CustomTrainer, which makes it invalid if copied; update the keyword argument to func.

Copilot uses AI. Check for mistakes.
from kubeflow.trainer.options import Annotations

job_id = trainer_client.train(
trainer=CustomTrainer(fuc=train_function),
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This code sample also uses fuc= instead of func= for CustomTrainer, which makes it invalid if copied; update the keyword argument to func.

Copilot uses AI. Check for mistakes.
Comment on lines +72 to +80
TrainerCommand
----------------

Override the trainer container command "spec.trainer.command". It can only be used with ''CustomTrainerContainer'' not with ''CustomTrainer'' or ''BuildinTrainer''.

.. code-block:: python

from kubeflow.trainer.options import (RuntimePatch, TrainingRuntimeSpecPatch, JobSetTemplatePatch, JobSetSpecPatch, ReplicatedJobPatch, JobTemplatePatch, JobSpecPatch, PodTemplatePatch, PodSpecPatch, ContainerPatch)
patch = RuntimePatch(
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The “TrainerCommand” section text says it overrides .spec.trainer.command and only works with CustomTrainerContainer, but the example below shows a RuntimePatch applied to a CustomTrainer; either update the example to demonstrate TrainerCommand with CustomTrainerContainer or move/rename this section to document RuntimePatch instead.

Copilot uses AI. Check for mistakes.
TrainerCommand
----------------

Override the trainer container command "spec.trainer.command". It can only be used with ''CustomTrainerContainer'' not with ''CustomTrainer'' or ''BuildinTrainer''.
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

Inline code formatting and class name are off here: use Sphinx inline-literal markup (CustomTrainerContainer, CustomTrainer, BuiltinTrainer) and fix the typo “BuildinTrainer” → “BuiltinTrainer”.

Suggested change
Override the trainer container command "spec.trainer.command". It can only be used with ''CustomTrainerContainer'' not with ''CustomTrainer'' or ''BuildinTrainer''.
Override the trainer container command ``spec.trainer.command``. It can only be used with ``CustomTrainerContainer`` not with ``CustomTrainer`` or ``BuiltinTrainer``.

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +11
from kubeflow.trainer import TrainerClient
from kubeflow.trainer.options import Name, Labels, Annotations

Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This example uses CustomTrainer but never imports it, so the snippet won’t run if copied; import CustomTrainer (e.g., from kubeflow.trainer or kubeflow.trainer.types) or adjust the example to only use imported symbols.

Copilot uses AI. Check for mistakes.
)

.. note::
Not all options work with every backend, each option documents which backend it supports. An uusupported option will raise an "ValueError" during the runtime.
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

Typo in the note: “uusupported” should be “unsupported”.

Suggested change
Not all options work with every backend, each option documents which backend it supports. An uusupported option will raise an "ValueError" during the runtime.
Not all options work with every backend, each option documents which backend it supports. An unsupported option will raise a "ValueError" during runtime.

Copilot uses AI. Check for mistakes.
)

.. note::
Not all options work with every backend, each option documents which backend it supports. An uusupported option will raise an "ValueError" during the runtime.
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

Grammar in the note is incorrect (“an ValueError”); change to “a ValueError” (and consider dropping the extra quotes around ValueError).

Suggested change
Not all options work with every backend, each option documents which backend it supports. An uusupported option will raise an "ValueError" during the runtime.
Not all options work with every backend, each option documents which backend it supports. An unsupported option will raise a ValueError at runtime.

Copilot uses AI. Check for mistakes.
from kubeflow.trainer.options import Name, Labels, Annotations

job_id = client.train(
trainer=CustomTrainer(fuc=train_function),
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This example again uses CustomTrainer(fuc=...) (should be func), which will fail if copied; update the keyword argument to func.

Copilot uses AI. Check for mistakes.

trainer_client = TrainerClient()
job_id = trainer_client.train(
trainer=CustomTrainer(fuc=train_function),
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

CustomTrainer takes a func parameter (not fuc), so this code sample would raise TypeError if used as written; update the keyword argument to func.

Copilot uses AI. Check for mistakes.
…w#388

Signed-off-by: aashvgit <167199295+aashvgit@users.noreply.github.com>
@aashvgit aashvgit force-pushed the docs/optionsdocs-388 branch from 43b03bb to 1278c95 Compare March 27, 2026 18:13
Signed-off-by: aashvgit <167199295+aashvgit@users.noreply.github.com>
@aashvgit aashvgit changed the title docfix: added usages guide with examples to options reference #388 fix: added usages guide with examples to options reference #388 Mar 27, 2026
@aashvgit aashvgit requested a review from Copilot March 29, 2026 13:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 7 comments.

Annotations
-----------

Add annotations to the TrainJob resource metadata(``metadata.annotations``). Only supported on the Kubernetes backend.
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The Annotations description is missing a space before the inline literal ("metadata(metadata.annotations)"); add the space so the text renders/readably parses as "metadata (metadata.annotations)".

Suggested change
Add annotations to the TrainJob resource metadata(``metadata.annotations``). Only supported on the Kubernetes backend.
Add annotations to the TrainJob resource metadata (``metadata.annotations``). Only supported on the Kubernetes backend.

Copilot uses AI. Check for mistakes.
--------------

Override the trainer container command (``spec.trainer.command``).
Can Only be used with ''CustomTrainerContainer'' not with ''CustomTrainer''' or ''BuiltinTrainer''.
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The TrainerCommand restrictions line uses incorrect reST markup (''...'' and mismatched quotes) and inconsistent capitalization ("Can Only"); use consistent inline-literal/class markup (e.g., CustomTrainerContainer, CustomTrainer, BuiltinTrainer) and "can only".

Suggested change
Can Only be used with ''CustomTrainerContainer'' not with ''CustomTrainer''' or ''BuiltinTrainer''.
Can only be used with ``CustomTrainerContainer`` and not with ``CustomTrainer`` or ``BuiltinTrainer``.

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +112
Append extra arguments to the trainer container command.

.. code-block:: python

from kubeflow.trainer import TrainerClient, CustomTrainer
from kubeflow.trainer.options import TrainerArgs

trainer_client = TrainerClient()

job_id = trainer_client.train(
trainer=CustomTrainer(func=train_function),
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The TrainerArgs section is inaccurate: the option overrides .spec.trainer.args and is only valid with CustomTrainerContainer on the Kubernetes backend (per the implementation), but the text implies it appends args generically.

Suggested change
Append extra arguments to the trainer container command.
.. code-block:: python
from kubeflow.trainer import TrainerClient, CustomTrainer
from kubeflow.trainer.options import TrainerArgs
trainer_client = TrainerClient()
job_id = trainer_client.train(
trainer=CustomTrainer(func=train_function),
Override the trainer container arguments (``spec.trainer.args``). Only supported on the **Kubernetes backend** with ``CustomTrainerContainer``.
.. code-block:: python
from kubeflow.trainer import TrainerClient, CustomTrainerContainer
from kubeflow.trainer.options import TrainerArgs
trainer_client = TrainerClient()
job_id = trainer_client.train(
trainer=CustomTrainerContainer(image="my-image:latest"),

Copilot uses AI. Check for mistakes.
Comment on lines +106 to +112
from kubeflow.trainer import TrainerClient, CustomTrainer
from kubeflow.trainer.options import TrainerArgs

trainer_client = TrainerClient()

job_id = trainer_client.train(
trainer=CustomTrainer(func=train_function),
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The TrainerArgs example uses CustomTrainer (func-based), but TrainerArgs raises ValueError unless the trainer is a CustomTrainerContainer; update the example to use CustomTrainerContainer (and show args consistent with that).

Suggested change
from kubeflow.trainer import TrainerClient, CustomTrainer
from kubeflow.trainer.options import TrainerArgs
trainer_client = TrainerClient()
job_id = trainer_client.train(
trainer=CustomTrainer(func=train_function),
from kubeflow.trainer import TrainerClient, CustomTrainerContainer
from kubeflow.trainer.options import TrainerArgs
trainer_client = TrainerClient()
job_id = trainer_client.train(
trainer=CustomTrainerContainer(image="my-image:latest"),

Copilot uses AI. Check for mistakes.
RuntimePatch
--------------

Apply structured patches to the TrainJob (``spec.runtimePatches``) Use this for advanced Kubernetes-level customisation such as adding init containers, volumes, or tolerations. Only supported on the ''Kubernetes backend''.
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

The RuntimePatch description runs two sentences together and uses inconsistent quoting (''Kubernetes backend''); add a period after the spec.runtimePatches clause and use consistent markup (e.g., Kubernetes backend or KubernetesBackend).

Suggested change
Apply structured patches to the TrainJob (``spec.runtimePatches``) Use this for advanced Kubernetes-level customisation such as adding init containers, volumes, or tolerations. Only supported on the ''Kubernetes backend''.
Apply structured patches to the TrainJob (``spec.runtimePatches``). Use this for advanced Kubernetes-level customisation such as adding init containers, volumes, or tolerations. Only supported on the **Kubernetes backend**.

Copilot uses AI. Check for mistakes.
=================

Options let to customize how a TrainJob is created and executed. Pass them as a list to the '''options''' parameter of the
:py:meth:`kubeflow.trainer.TrainerClient.train` method.
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

There should be a blank line between the paragraph ending with the :py:meth: role and the .. code-block:: directive; without it Sphinx can emit an "Explicit markup" warning and render incorrectly.

Suggested change
:py:meth:`kubeflow.trainer.TrainerClient.train` method.
:py:meth:`kubeflow.trainer.TrainerClient.train` method.

Copilot uses AI. Check for mistakes.
.. note::
Not all options work with every backend. Each option documents
which backends it supports. An unsupported option will raise a
`ValueError` at runtime.
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

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

ValueError is currently written with single backticks; in this doc it should be marked as code or a Python class reference (e.g., ValueError or :class:ValueError) to avoid mis-rendering.

Suggested change
`ValueError` at runtime.
``ValueError`` at runtime.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants