# 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": "pt-1.6-dlrm-seq-fwd-func-v3-8"
  "namespace": "automated"
"spec":
  "concurrencyPolicy": "Forbid"
  "jobTemplate":
    "spec":
      "activeDeadlineSeconds": 10800
      "backoffLimit": 1
      "template":
        "metadata":
          "annotations":
            "tf-version.cloud-tpus.google.com": "pytorch-1.6"
        "spec":
          "containers":
          - "env":
            - "name": "POD_NAME"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.name"
            - "name": "POD_NAMESPACE"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.namespace"
            "image": "gcr.io/xl-ml-test/health-monitor:stable"
            "imagePullPolicy": "Always"
            "name": "monitor"
          - "args":
            - "/bin/bash"
            - "-c"
            - |
              set -u
              set -e
              set -x
              
              git clone https://github.com/taylanbil/dlrm.git -b tpu
              pip install onnx
              python dlrm/dlrm_tpu_runner.py \
                --arch-sparse-feature-size=64 \
                --arch-mlp-bot=512-512-64 \
                --arch-mlp-top=1024-1024-1024-1 \
                --arch-interaction-op=dot \
                --lr-num-warmup-steps 10 \
                --lr-decay-start-step 10 \
                --num-batches=1000 \
                --data-generation="random" \
                --numpy-rand-seed=727 \
                --print-freq 100 \
                --num-indices-per-lookup=100 \
                --use-tpu \
                --metrics-debug \
                --num-indices-per-lookup-fixed \
                --mini-batch-size=2048 \
                --arch-embedding-size=1000000-1000000 \
                --tpu-model-parallel-group-len 1 \
                --tpu-cores=8
              
            "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": "MODEL_DIR"
              "value": "$(OUTPUT_BUCKET)/pt-1.6/dlrm-seq-fwd/func/v3-8/$(JOB_NAME)"
            - "name": "XLA_USE_BF16"
              "value": "0"
            "envFrom":
            - "configMapRef":
                "name": "gcs-buckets"
            "image": "gcr.io/xl-ml-test/pytorch-xla:r1.6"
            "imagePullPolicy": "Always"
            "name": "train"
            "resources":
              "limits":
                "cloud-tpus.google.com/v3": 8
              "requests":
                "cpu": "9.0"
                "memory": "30Gi"
            "volumeMounts":
            - "mountPath": "/dev/shm"
              "name": "dshm"
              "readOnly": false
            - "mountPath": "/datasets"
              "name": "pytorch-datasets-claim"
              "readOnly": true
          "initContainers":
          - "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": "MODEL_DIR"
              "value": "$(OUTPUT_BUCKET)/pt-1.6/dlrm-seq-fwd/func/v3-8/$(JOB_NAME)"
            - "name": "METRIC_CONFIG"
              "value": |
                {
                 "metric_collection_config": {
                  "default_aggregation_strategies": [
                   "final"
                  ],
                  "tags_to_ignore": [
                   "LearningRate"
                  ],
                  "write_to_bigquery": true
                 },
                 "regression_test_config": {
                  "metric_subset_to_alert": [
                   "ExecuteTime__Percentile_99_sec_final",
                   "total_wall_time",
                   "Accuracy/test_final",
                   "aten_ops_sum_final"
                  ],
                  "metric_success_conditions": {
                   "ExecuteTime__Percentile_99_sec_final": {
                    "comparison": "less",
                    "success_threshold": {
                     "stddevs_from_mean": 5
                    },
                    "wait_for_n_points_of_history": 10
                   },
                   "aten_ops_sum_final": {
                    "comparison": "less_or_equal",
                    "success_threshold": {
                     "stddevs_from_mean": 0
                    }
                   },
                   "total_wall_time": {
                    "comparison": "less",
                    "success_threshold": {
                     "stddevs_from_mean": 5
                    },
                    "wait_for_n_points_of_history": 10
                   }
                  }
                 },
                 "test_name": "pt-1.6-dlrm-seq-fwd-func-v3-8"
                }
            "envFrom":
            - "configMapRef":
                "name": "gcs-buckets"
            "image": "gcr.io/xl-ml-test/publisher:stable"
            "imagePullPolicy": "Always"
            "name": "publisher"
          "nodeSelector":
            "tpu-available": "true"
          "restartPolicy": "Never"
          "volumes":
          - "emptyDir":
              "medium": "Memory"
            "name": "dshm"
          - "name": "pytorch-datasets-claim"
            "persistentVolumeClaim":
              "claimName": "pytorch-datasets-claim"
  "schedule": "0 2 * * *"
  "successfulJobsHistoryLimit": 1