# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"apiVersion": "batch/v1beta1"
"kind": "CronJob"
"metadata":
  "name": "tf-nightly-mnist-convergence-v3-8"
  "namespace": "automated"
"spec":
  "concurrencyPolicy": "Forbid"
  "jobTemplate":
    "spec":
      "activeDeadlineSeconds": 36000
      "backoffLimit": 2
      "template":
        "metadata":
          "annotations":
            "tf-version.cloud-tpus.google.com": "nightly"
        "spec":
          "containers":
          - "args":
            - "python3"
            - "official/vision/image_classification/mnist_main.py"
            - "--data_dir=gs://xl-ml-test-us-central1/data/mnist"
            - "--distribution_strategy=tpu"
            - "--batch_size=2048"
            - "--train_epochs=10"
            - "--epochs_between_evals=10"
            - "--model_dir=$(MODEL_DIR)"
            "env":
            - "name": "POD_NAME"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.name"
            - "name": "POD_UID"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.uid"
            - "name": "POD_NAMESPACE"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.namespace"
            - "name": "JOB_NAME"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.labels['job-name']"
            - "name": "METRIC_CONFIG"
              "value": |
                {
                 "metric_collection_config": {
                  "default_aggregation_strategies": [
                   "final"
                  ],
                  "write_to_bigquery": true
                 },
                 "regression_test_config": {
                  "metric_success_conditions": {
                   "total_wall_time": {
                    "comparison": "less",
                    "success_threshold": {
                     "stddevs_from_mean": 5
                    },
                    "wait_for_n_points_of_history": 10
                   }
                  },
                  "write_to_error_reporting": true
                 },
                 "test_name": "tf-nightly-mnist-convergence-v3-8"
                }
            - "name": "MODEL_DIR"
              "value": "gs://xl-ml-test-us-central1/k8s/mnist/convergence/v3-8/$(JOB_NAME)"
            "image": "gcr.io/xl-ml-test/model-garden:nightly"
            "imagePullPolicy": "Always"
            "name": "train"
            "resources":
              "limits":
                "cloud-tpus.google.com/v3": 8
          "restartPolicy": "Never"
  "schedule": "0 6 * * 0,5"