# 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":
  "labels":
    "accelerator": "v100-x4"
    "benchmarkId": "tf-r2.4.0-ncf-func-v100-x4"
    "frameworkVersion": "tf-r2.4.0"
    "mode": "func"
    "model": "ncf"
  "name": "tf-r2.4.0-ncf-func-v100-x4"
  "namespace": "automated"
"spec":
  "concurrencyPolicy": "Forbid"
  "jobTemplate":
    "metadata":
      "annotations":
        "ml-testing-accelerators/gcs-subdir": "tf-r2.4.0/ncf/func/v100-x4"
        "ml-testing-accelerators/metric-config": |
          {
            "sources": [
              {
                "literals": {
                  "assertions": {
                    "duration": {
                      "inclusive_bounds": false,
                      "std_devs_from_mean": {
                        "comparison": "LESS",
                        "std_devs": 5
                      },
                      "wait_for_n_data_points": 10
                    }
                  }
                }
              },
              {
                "tensorboard": {
                  "aggregate_assertions": [
                    {
                      "assertion": {
                        "inclusive_bounds": true,
                        "std_devs_from_mean": {
                          "comparison": "GREATER",
                          "std_devs": 2
                        },
                        "wait_for_n_data_points": 0
                      },
                      "strategy": "AVERAGE",
                      "tag": "examples_per_second"
                    }
                  ],
                  "exclude_tags": [
          
                  ],
                  "include_tags": [
                    {
                      "strategies": [
                        "FINAL"
                      ],
                      "tag_pattern": "*"
                    }
                  ],
                  "merge_runs": false
                }
              }
            ]
          }
      "labels":
        "accelerator": "v100-x4"
        "benchmarkId": "tf-r2.4.0-ncf-func-v100-x4"
        "frameworkVersion": "tf-r2.4.0"
        "mode": "func"
        "model": "ncf"
    "spec":
      "activeDeadlineSeconds": 3600
      "backoffLimit": 1
      "template":
        "spec":
          "containers":
          - "args":
            - "python3"
            - "official/recommendation/ncf_keras_main.py"
            - "--train_dataset_path=$(NCF_DIR)/tpu_data_dir/training_cycle_*/*"
            - "--eval_dataset_path=$(NCF_DIR)/tpu_data_dir/eval_data/*"
            - "--input_meta_data_path=$(NCF_DIR)/tpu_data_dir/metadata"
            - "--data_dir=$(NCF_DIR)/movielens_data"
            - "--batch_size=99000"
            - "--learning_rate=3e-5"
            - "--dataset=ml-20m"
            - "--eval_batch_size=160000"
            - "--learning_rate=0.00382059"
            - "--beta1=0.783529"
            - "--beta2=0.909003"
            - "--epsilon=1.45439e-07"
            - "--num_factors=64"
            - "--hr_threshold=0.635"
            - "--layers=256,256,128,64"
            - "--use_synthetic_data=false"
            - "--model_dir=$(MODEL_DIR)"
            - "--train_epochs=1"
            - "--ml_perf=true"
            - "--keras_use_ctl=false"
            "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)/tf-r2.4.0/ncf/func/v100-x4/$(JOB_NAME)"
            "envFrom":
            - "configMapRef":
                "name": "gcs-buckets"
            "image": "gcr.io/xl-ml-test/tensorflow:r2.4.0"
            "imagePullPolicy": "Always"
            "name": "train"
            "resources":
              "limits":
                "nvidia.com/gpu": 4
              "requests":
                "cpu": 2
                "memory": "20G"
            "volumeMounts":
            - "mountPath": "/dev/shm"
              "name": "dshm"
              "readOnly": false
          "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)/tf-r2.4.0/ncf/func/v100-x4/$(JOB_NAME)"
            - "name": "METRIC_CONFIG"
              "value": |
                {
                 "metric_collection_config": {
                  "default_aggregation_strategies": [
                   "final"
                  ],
                  "metric_to_aggregation_strategies": {
                   "examples_per_second": [
                    "average"
                   ]
                  },
                  "use_run_name_prefix": true,
                  "write_to_bigquery": true
                 },
                 "regression_test_config": {
                  "metric_success_conditions": {
                   "examples_per_second_average": {
                    "comparison": "greater_or_equal",
                    "success_threshold": {
                     "stddevs_from_mean": 2
                    }
                   },
                   "total_wall_time": {
                    "comparison": "less",
                    "success_threshold": {
                     "stddevs_from_mean": 5
                    },
                    "wait_for_n_points_of_history": 10
                   }
                  }
                 },
                 "test_name": "tf-r2.4.0-ncf-func-v100-x4"
                }
            "envFrom":
            - "configMapRef":
                "name": "gcs-buckets"
            "image": "gcr.io/xl-ml-test/publisher:stable"
            "imagePullPolicy": "Always"
            "name": "publisher"
          "nodeSelector":
            "cloud.google.com/gke-accelerator": "nvidia-tesla-v100"
          "priorityClassName": "gpu-v100"
          "restartPolicy": "Never"
          "volumes":
          - "emptyDir":
              "medium": "Memory"
            "name": "dshm"
  "schedule": "0 6 * * *"
  "successfulJobsHistoryLimit": 1