Files
561e9cf083 feat(docs): add dedicated documentation website (#3308)
* feat(docs): add initial documentation structure and configuration for Kubeflow Trainer

- Introduced .readthedocs.yaml for ReadTheDocs configuration.
- Created Makefile for building and serving documentation.
- Added Sphinx configuration in docs/conf.py.
- Established index.rst as the main entry point for documentation.
- Developed user guides for various frameworks including PyTorch, JAX, and DeepSpeed.
- Implemented custom CSS for documentation styling.
- Included a distributed data cache guide and a DeepSpeed integration guide.

This commit sets up the foundational documentation for the Kubeflow Trainer, enhancing accessibility and usability for users.

Signed-off-by: Sridhar1030 <[email protected]>

* feat(docs): update user guides and restructure documentation for Kubeflow Trainer

- Renamed and reorganized user guides to better serve different audiences: AI practitioners, cluster operators, and contributors.
- Added new sections for documentation on the Kubeflow Training Operator v1 and legacy guides.
- Enhanced descriptions to clarify the purpose and content of each guide, improving overall accessibility and usability.

Signed-off-by: Sridhar1030 <[email protected]>

* feat(docs): add comprehensive operator guides for Kubeflow Trainer

Signed-off-by: Sridhar1030 <[email protected]>

* feat(docs): enhance operator guides for Kubeflow Trainer

Signed-off-by: Sridhar1030 <[email protected]>

* fixed user-guides

Signed-off-by: Sridhar1030 <[email protected]>

* feat(docs): add initial API reference and contributor guides for Kubeflow Trainer

- Introduced API reference documentation for Python SDK and Kubernetes CRD types, including TrainJob, TrainingRuntime, and ClusterTrainingRuntime.
- Created contributor guides covering architecture, community, and contributing processes.
- Added legacy v1 documentation structure with sections for installation and user guides for various frameworks.
- Enhanced local execution documentation with updated examples.

This commit establishes a comprehensive documentation framework to support users and contributors of the Kubeflow Trainer.

Signed-off-by: Sridhar1030 <[email protected]>

* feat(docs): update user guides for distributed training frameworks

- Revised user guides for distributed training with Kubeflow Trainer, including JAX, PyTorch, MLX, DeepSpeed, and the data cache feature.
- Enhanced clarity and structure of documentation to improve user experience and accessibility.
- Added detailed instructions for using TrainJob with various frameworks, emphasizing configuration-driven training and runtime packages.
- Removed outdated content and streamlined sections for better readability.

This commit enhances the documentation framework, making it easier for users to implement distributed training solutions.

Signed-off-by: Sridhar1030 <[email protected]>

* refactor(docs): update index.rst and custom.css for improved documentation layout

- Replaced the old container structure with HTML for doc cards in index.rst, enhancing the visual presentation of quick links.
- Updated CSS styles for doc cards to improve interactivity and appearance, including hover effects and text decoration.
- Added an API Reference section to the documentation layout for better accessibility to technical details.

These changes aim to enhance the user experience and accessibility of the Kubeflow Trainer documentation.

Signed-off-by: Sridhar1030 <[email protected]>

* feat(docs): enhance documentation with new sidebar toggle and external link handling

- Added JavaScript functionality for a collapsible sidebar to improve navigation on larger screens.
- Implemented external link handling to open links in a new tab for better user experience.
- Updated CSS to accommodate new sidebar features and reduce whitespace in the content area.
- Included Sphinx documentation build artifacts in .gitignore for cleaner repository management.

These changes aim to improve the usability and accessibility of the Kubeflow Trainer documentation.

Signed-off-by: Sridhar1030 <[email protected]>

* added leagcy training docs

Signed-off-by: Sridhar1030 <[email protected]>

* refactor(docs): remove API reference section and update documentation layout

- Deleted the API reference section and related files to streamline the documentation.
- Updated index.rst to remove references to the API documentation.
- Enhanced CSS styles for doc cards to improve visual consistency and interactivity.

These changes aim to simplify the documentation structure and improve user navigation within the Kubeflow Trainer documentation.

Signed-off-by: Sridhar1030 <[email protected]>

* refactor(docs): remove CRD API reference generation and update Sphinx configuration

- Eliminated the CRD API reference generation from the Makefile and .readthedocs.yaml to simplify the build process.
- Updated Sphinx configuration to disable fail_on_warning, allowing builds to proceed despite warnings.
- Removed AutoAPI configuration from conf.py and related dependencies from requirements.txt to streamline documentation setup.

These changes aim to enhance the documentation build process and reduce complexity in the project structure.

Signed-off-by: Sridhar1030 <[email protected]>

* feat(docs): expand JAX and MPI user guides with detailed instructions

- Updated the JAX user guide to include comprehensive instructions for creating and monitoring JAX training jobs using the JAXJob custom resource.
- Enhanced the MPI user guide with additional metrics and Docker image building instructions, improving clarity and usability.
- Introduced a new section in the multi-cluster guide detailing the `MultiKueue` feature for efficient management of MPI jobs across clusters.

These changes aim to provide users with clearer guidance and enhance the overall documentation for distributed training frameworks in Kubeflow.

Signed-off-by: Sridhar1030 <[email protected]>

* feat(docs): enhance user guides with grid layout and sidebar improvements

- Introduced a grid layout for the BuiltinTrainer and local execution user guides, improving visual organization and accessibility.
- Added new sections for overview and backend options in the local execution guide, detailing how to run TrainJobs with different backends.
- Updated CSS to make the sidebar sticky during scrolling, enhancing navigation on larger screens.

These changes aim to improve the overall user experience and clarity of the documentation for Kubeflow Trainer.

Signed-off-by: Sridhar1030 <[email protected]>

* fix\(docs\):\ update\ dataset\ download\ instructions\ and\ improve\ links\ in\ user\ guides$'\n'$'\n'-\ Clarified\ that\ each\ rank\ in\ a\ multi-node\ TrainJob\ must\ download\ the\ dataset\ independently.$'\n'-\ Updated\ links\ in\ the\ local\ execution\ and\ Podman\ user\ guides\ to\ point\ directly\ to\ the\ relevant\ sections\ in\ the\ overview.$'\n'-\ Corrected\ the\ path\ for\ accessing\ the\ fine-tuned\ model\ in\ the\ BuiltinTrainer\ guide.$'\n'$'\n'These\ changes\ enhance\ the\ clarity\ and\ usability\ of\ the\ documentation\ for\ Kubeflow\ Trainer. (resolved the copliot reviews)

Signed-off-by: Sridhar1030 <[email protected]>

* docs: update extension framework guide and remove pod template documentation

- Added architecture diagrams to the Kubeflow Trainer Extension Framework guide for better visualization.
- Updated terminology in the index to reflect the transition from Pod Templates to Runtime Patches.
- Removed the outdated PodTemplate documentation to streamline the guides and focus on current practices.

These changes aim to enhance clarity and usability in the documentation for the Kubeflow Trainer.

Signed-off-by: Sridhar1030 <[email protected]>

* docs: update overview and add diagrams

Signed-off-by: Sridhar1030 <[email protected]>

* docs: update Sphinx configuration and improve link references

- Enabled fail_on_warning in Sphinx configuration to ensure builds fail on warnings, enhancing documentation quality.
- Updated links in user guides to point to the correct paths, improving navigation and clarity for users.

These changes aim to enhance the reliability and usability of the documentation for Kubeflow Trainer.

Signed-off-by: Sridhar1030 <[email protected]>

* fixed the MNIST link , updated local process backend to match the main documentation website

Signed-off-by: Sridhar1030 <[email protected]>

* fix(docs): add missing newline at end of file for pre-commit compliance

Signed-off-by: Sridhar1030 <[email protected]>

* fix(docs): remove trailing whitespace in podman guide

Signed-off-by: Sridhar1030 <[email protected]>

* fix(docs): format conf.py for black/flake8 compliance

Signed-off-by: Sridhar1030 <[email protected]>
Made-with: Cursor

* docs: update theme configuration and enhance CSS for improved navigation

- Updated the Furo theme options in `conf.py` to refine color variables for light and dark modes, enhancing visual consistency.
- Introduced a top navigation bar in the CSS with links to examples, GitHub, Slack, and the blog, improving accessibility and user experience.
- Expanded the CSS file to include a comprehensive color palette and responsive design adjustments for better usability across devices.

These changes aim to enhance the overall look and feel of the Kubeflow Trainer documentation, making it more user-friendly and visually appealing.

Signed-off-by: Sridhar1030 <[email protected]>

* fix(docs): wrap long lines in conf.py to satisfy E501 lint
Break announcement HTML string into concatenated short lines
to keep all lines under the 100-character limit.
Ref #3308

Signed-off-by: Sridhar1030 <[email protected]>

* docs: enhance theme configuration and update local execution guides

- Updated color variables in `conf.py` for improved light and dark mode support.
- Refined CSS styles to utilize new color variables, enhancing visual consistency across the documentation.
- Added architecture diagrams for Docker and Podman backends in their respective guides, clarifying the orchestration process.
- Improved the structure and clarity of the local execution documentation, including error handling and configuration examples.

These changes aim to enhance the overall user experience and visual appeal of the Kubeflow Trainer documentation.

Signed-off-by: Sridhar1030 <[email protected]>

* added homepage

Signed-off-by: Sridhar1030 <[email protected]>

* fixed routing

Signed-off-by: Sridhar1030 <[email protected]>

* Added remaining pages

Signed-off-by: Sridhar1030 <[email protected]>

* fix(docs): trim trailing whitespace for pre-commit

Signed-off-by: Sridhar1030 <[email protected]>

* fix(docs): add Kubeflow boilerplate header to conf.py

Required by the code-quality verify-boilerplate check added upstream.

Signed-off-by: Sridhar1030 <[email protected]>

* fix(docs): address PR review feedback

- Consolidate landing page: remove home.rst, migrate links to index.rst
- Vendor overview and data-cache images into docs/images/
- Fix apiVersion v2alpha1 → v1alpha1 in runtime-patches and megatron
- Add missing runtimes to supported-runtimes table
- Expand overview ecosystem list, remove phantom SDK bullet and stray emoji
- Replace hard-coded GitHub stats with ADOPTERS.md link
- Delete kueue.md stub, use external toctree link
- Fix torchtune overview link and wildcard import
- Fix xgboost typos and add distributed training example
- Replace vendored contributing/community with link-out stubs
- Add data-cache architecture diagrams
- Move top nav to Sphinx extension (docs/_ext/kubeflow_topnav/)
- Fix brokeGitHub line anchors in legacy fine-tuning reference
- Add missing import os in legacy getting-started

Signed-off-by: Sridhar1030 <[email protected]>

* docs(operator-guides): add torch envInjection section to ml-policy

Add documentation for torch.envInjection.targets in MLPolicy, allowing
PET_* env vars to be injected into init/sidecar containers.

Ref: kubeflow/website#4399, kubeflow/trainer#3417
Signed-off-by: Sridhar1030 <[email protected]>

---------

Signed-off-by: Sridhar1030 <[email protected]>

Co-authored-by: Hanzo Dev <[email protected]>
2026-06-18 14:29:04 +00:00

17 KiB

TensorFlow Training (TFJob)

Using TFJob to train a model with TensorFlow

:::{admonition} Old Version :class: warning This page is about Kubeflow Training Operator V1, for the latest information check the Kubeflow Trainer V2 documentation.

Follow this guide for migrating to Kubeflow Trainer V2. :::

This page describes TFJob for training a machine learning model with TensorFlow.

What is TFJob?

TFJob is a Kubernetes custom resource to run TensorFlow training jobs on Kubernetes. The Kubeflow implementation of TFJob is in the training-operator.

Note: TFJob doesn't work in a user namespace by default because of Istio automatic sidecar injection. In order to get TFJob running, it needs the annotation sidecar.istio.io/inject: "false" to disable it for TFJob pods.

A TFJob is a resource with a YAML representation like the one below (edit to use the container image and command for your own training code):

apiVersion: kubeflow.org/v1
kind: TFJob
metadata:
  generateName: tfjob
  namespace: your-user-namespace
spec:
  tfReplicaSpecs:
    PS:
      replicas: 1
      restartPolicy: OnFailure
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "false"
        spec:
          containers:
            - name: tensorflow
              image: gcr.io/your-project/your-image
              command:
                - python
                - -m
                - trainer.task
                - --batch_size=32
                - --training_steps=1000
    Worker:
      replicas: 3
      restartPolicy: OnFailure
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "false"
        spec:
          containers:
            - name: tensorflow
              image: gcr.io/your-project/your-image
              command:
                - python
                - -m
                - trainer.task
                - --batch_size=32
                - --training_steps=1000

If you want to give your TFJob pods access to credentials secrets, such as the Google Cloud credentials automatically created when you do a GKE-based Kubeflow installation, you can mount and use a secret like this:

apiVersion: kubeflow.org/v1
kind: TFJob
metadata:
  generateName: tfjob
  namespace: your-user-namespace
spec:
  tfReplicaSpecs:
    PS:
      replicas: 1
      restartPolicy: OnFailure
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "false"
        spec:
          containers:
            - name: tensorflow
              image: gcr.io/your-project/your-image
              command:
                - python
                - -m
                - trainer.task
                - --batch_size=32
                - --training_steps=1000
              env:
                - name: GOOGLE_APPLICATION_CREDENTIALS
                  value: "/etc/secrets/user-gcp-sa.json"
              volumeMounts:
                - name: sa
                  mountPath: "/etc/secrets"
                  readOnly: true
          volumes:
            - name: sa
              secret:
                secretName: user-gcp-sa
    Worker:
      replicas: 1
      restartPolicy: OnFailure
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "false"
        spec:
          containers:
            - name: tensorflow
              image: gcr.io/your-project/your-image
              command:
                - python
                - -m
                - trainer.task
                - --batch_size=32
                - --training_steps=1000
              env:
                - name: GOOGLE_APPLICATION_CREDENTIALS
                  value: "/etc/secrets/user-gcp-sa.json"
              volumeMounts:
                - name: sa
                  mountPath: "/etc/secrets"
                  readOnly: true
          volumes:
            - name: sa
              secret:
                secretName: user-gcp-sa

If you are not familiar with Kubernetes resources please refer to the page Understanding Kubernetes Objects.

What makes TFJob different from built in controllers is that the TFJob spec is designed to manage distributed TensorFlow training jobs.

A distributed TensorFlow job typically contains 0 or more of the following processes

  • Evaluator The evaluators can be used to compute evaluation metrics as the model is trained.
  • Worker The workers do the actual work of training the model. In some cases, worker 0 might also act as the chief.
  • Ps The ps are parameter servers; these servers provide a distributed data store for the model parameters.
  • Chief The chief is responsible for orchestrating training and performing tasks like checkpointing the model.

The field tfReplicaSpecs in TFJob spec contains a map from the type of replica (as listed above) to the TFReplicaSpec for that replica. TFReplicaSpec consists of 3 fields

  • replicas The number of replicas of this type to spawn for this TFJob.
  • template A PodTemplateSpec that describes the pod to create for each replica. The pod must include a container named tensorflow.
  • restartPolicy Determines whether pods will be restarted when they exit. The allowed values are as follows:
    • Always means the pod will always be restarted. This policy is good for parameter servers since they never exit and should always be restarted in the event of failure.
    • OnFailure means the pod will be restarted if the pod exits due to failure. This policy is good for chief and workers. An exit code of 0 indicates success and the pod will not be restarted. A non-zero exit code indicates a failure.
    • ExitCode means the restart behavior is dependent on the exit code of the tensorflow container as follows:
      • Exit code 0 indicates the process completed successfully and will not be restarted.
      • The following exit codes indicate a permanent error and the container will not be restarted: 139, 128, 127, 126, 2, 1.
      • The following exit codes indicate a retryable error and the container will be restarted: 143, 137, 130, 138.
    • Never means pods that terminate will never be restarted. This policy should rarely be used because Kubernetes will terminate pods for any number of reasons (e.g. node becomes unhealthy) and this will prevent the job from recovering.

For background information on exit codes, see the GNU guide to termination signals and the Linux Documentation Project.

Running the Mnist example

See the manifests for the distributed MNIST example. You may change the config file based on your requirements.

Deploy the TFJob resource to start training:

kubectl create -f https://raw.githubusercontent.com/kubeflow/training-operator/refs/heads/release-1.9/examples/tensorflow/simple.yaml

Monitor the job (see the detailed guide below):

kubectl -n kubeflow get tfjob tfjob-simple -o yaml

Delete it

kubectl -n kubeflow delete tfjob tfjob-simple

Customizing the TFJob

Typically you can change the following values in the TFJob yaml file:

  • Change the image to point to the docker image containing your code
  • Change the number and types of replicas
  • Change the resources (requests and limits) assigned to each resource
  • Set any environment variables (e.g., configure various environment variables to talk to datastores like GCS or S3)
  • Attach PVs if you want to use PVs for storage.

Using GPUs

To use GPUs your cluster must be configured to use GPUs.

For more information:

To attach GPUs specify the GPU resource on the container in the replicas that should contain the GPUs; for example:

apiVersion: "kubeflow.org/v1"
kind: "TFJob"
metadata:
  name: "tf-smoke-gpu"
spec:
  tfReplicaSpecs:
    PS:
      replicas: 1
      template:
        metadata:
          creationTimestamp: null
        spec:
          containers:
            - args:
                - python
                - tf_cnn_benchmarks.py
                - --batch_size=32
                - --model=resnet50
                - --variable_update=parameter_server
                - --flush_stdout=true
                - --num_gpus=1
                - --local_parameter_device=cpu
                - --device=cpu
                - --data_format=NHWC
              image: gcr.io/kubeflow/tf-benchmarks-cpu:v20171202-bdab599-dirty-284af3
              name: tensorflow
              ports:
                - containerPort: 2222
                  name: tfjob-port
              resources:
                limits:
                  cpu: "1"
              workingDir: /opt/tf-benchmarks/scripts/tf_cnn_benchmarks
          restartPolicy: OnFailure
    Worker:
      replicas: 1
      template:
        metadata:
          creationTimestamp: null
        spec:
          containers:
            - args:
                - python
                - tf_cnn_benchmarks.py
                - --batch_size=32
                - --model=resnet50
                - --variable_update=parameter_server
                - --flush_stdout=true
                - --num_gpus=1
                - --local_parameter_device=cpu
                - --device=gpu
                - --data_format=NHWC
              image: gcr.io/kubeflow/tf-benchmarks-gpu:v20171202-bdab599-dirty-284af3
              name: tensorflow
              ports:
                - containerPort: 2222
                  name: tfjob-port
              resources:
                limits:
                  nvidia.com/gpu: 1
              workingDir: /opt/tf-benchmarks/scripts/tf_cnn_benchmarks
          restartPolicy: OnFailure

Follow TensorFlow's instructions for using GPUs.

Monitoring your job

To get the status of your job

kubectl -n kubeflow get -o yaml tfjobs tfjob-simple

Here is sample output for an example job

apiVersion: kubeflow.org/v1
kind: TFJob
metadata:
  creationTimestamp: "2021-09-06T11:48:09Z"
  generation: 1
  name: tfjob-simple
  namespace: kubeflow
  resourceVersion: "5764004"
  selfLink: /apis/kubeflow.org/v1/namespaces/kubeflow/tfjobs/tfjob-simple
  uid: 3a67a9a9-cb89-4c1f-a189-f49f0b581e29
spec:
  tfReplicaSpecs:
    Worker:
      replicas: 2
      restartPolicy: OnFailure
      template:
        spec:
          containers:
            - command:
                - python
                - /var/tf_mnist/mnist_with_summaries.py
              image: gcr.io/kubeflow-ci/tf-mnist-with-summaries:1.0
              name: tensorflow
status:
  completionTime: "2021-09-06T11:49:30Z"
  conditions:
    - lastTransitionTime: "2021-09-06T11:48:09Z"
      lastUpdateTime: "2021-09-06T11:48:09Z"
      message: TFJob tfjob-simple is created.
      reason: TFJobCreated
      status: "True"
      type: Created
    - lastTransitionTime: "2021-09-06T11:48:12Z"
      lastUpdateTime: "2021-09-06T11:48:12Z"
      message: TFJob kubeflow/tfjob-simple is running.
      reason: TFJobRunning
      status: "False"
      type: Running
    - lastTransitionTime: "2021-09-06T11:49:30Z"
      lastUpdateTime: "2021-09-06T11:49:30Z"
      message: TFJob kubeflow/tfjob-simple successfully completed.
      reason: TFJobSucceeded
      status: "True"
      type: Succeeded
  replicaStatuses:
    Worker:
      succeeded: 2
  startTime: "2021-09-06T11:48:10Z"

Conditions

A TFJob has a TFJobStatus, which has an array of TFJobConditions through which the TFJob has or has not passed. Each element of the TFJobCondition array has six possible fields:

The type field is a string with the following possible values:

  • TFJobFailed means the job has failed.
  • TFJobSucceeded means the job completed successfully.
  • TFJobRestarting means one or more sub-resources (e.g. services/pods) of this TFJob had a problem and is being restarted.
  • TFJobRunning means all sub-resources (e.g. services/pods) of this TFJob have been successfully scheduled and launched and the job is running.
  • TFJobCreated means the TFJob has been accepted by the system, but one or more of the pods/services has not been started.

Success or failure of a job is determined as follows

If the restartPolicy allows for restarts then the process will just be restarted and the TFJob will continue to execute.

  • If the restartPolicy doesn't allow restarts a non-zero exit code is considered a permanent failure and the job is marked failed.
  • For the restartPolicy ExitCode the behavior is exit code dependent.

tfReplicaStatuses

tfReplicaStatuses provides a map indicating the number of pods for each replica in a given state. There are three possible states

  • Failed is the number of pods that completed with an error.
  • Succeeded is the number of pods that completed successfully.
  • Active is the number of currently running pods.

Events

During execution, TFJob will emit events to indicate whats happening such as the creation/deletion of pods and services. Kubernetes doesn't retain events older than 1 hour by default. To see recent events for a job run

kubectl -n kubeflow describe tfjobs tfjob-simple

TensorFlow Logs

Logging follows standard K8s logging practices.

You can use kubectl to get standard output/error for any pods that haven't been deleted.

First find the pod created by the job controller for the replica of interest. Pods will be named

${JOBNAME}-${REPLICA-TYPE}-${INDEX}

Once you've identified your pod you can get the logs using kubectl.

kubectl logs ${PODNAME}

The CleanPodPolicy in the TFJob spec controls deletion of pods when a job terminates. The policy can be one of the following values

  • None means that no pods will be deleted when the job completes.
  • All means all pods even completed pods will be deleted immediately when the job finishes.
  • Running means that only pods still running when a job completes (e.g. parameter servers) will be deleted immediately; completed pods will not be deleted so that the logs will be preserved. This is the default value.

If your cluster takes advantage of Kubernetes cluster logging then your logs may also be shipped to an appropriate data store for further analysis.

Troubleshooting

Here are some steps to follow to troubleshoot your job

  1. Is a status present for your job? Run the command
kubectl -n ${USER_NAMESPACE} get tfjobs -o yaml ${JOB_NAME}

USER_NAMESPACE is the namespace created for your user profile.

If the resulting output doesn't include a status for your job then this typically indicates the job spec is invalid.

If the TFJob spec is invalid there should be a log message in the tf operator logs

kubectl -n ${KUBEFLOW_NAMESPACE} logs `kubectl get pods --selector=name=tf-job-operator -o jsonpath='{.items[0].metadata.name}'`

KUBEFLOW_NAMESPACE is the namespace you deployed the TFJob operator in.

  1. Check the events for your job to see if the pods were created

There are a number of ways to get the events; if your job is less than 1 hour old then you can do

kubectl -n ${USER_NAMESPACE} describe tfjobs ${JOB_NAME}

The bottom of the output should include a list of events emitted by the job.

Kubernetes only preserves events for 1 hour (see kubernetes/kubernetes#52521)

  1. If the pods and services aren't being created then this suggests the TFJob isn't being processed; common causes are
  • The TFJob operator isn't running
  • The TFJob spec is invalid (see above)
  1. Check the events for the pods to ensure they are scheduled.
kubectl -n ${USER_NAMESPACE} describe pods ${POD_NAME}

Some common problems that can prevent a container from starting are

  • The docker image doesn't exist or can't be accessed (e.g due to permission issues)
  • The pod tries to mount a volume (or secret) that doesn't exist or is unavailable
  • Insufficient resources to schedule the pod
  1. If the containers start; check the logs of the containers following the instructions in the previous section.

Next steps

Learn about distributed training in Training Operator.

See how to run a job with gang-scheduling.