import six


def decoder_template(job_name, model, image, logdir, decoder_type,
                     decoder_gpus):
  """Constructs the base yaml config for the decoder."""
  name = six.ensure_str(job_name) + ".decoder"
  container_name = name.replace(".", "-")
  job = "decoder_" + six.ensure_str(decoder_type)
  return """
apiVersion: v1
kind: Pod
metadata:
  name: {job_name}
spec:
  restartPolicy: Never
  containers:
    - name: {container_name}
      image: {image}
      command: ["/usr/bin/python3"]
      args: ["-m", "lingvo.trainer", "--mode=sync", "--alsologtostderr", "--model={model}", "--logdir={logdir}", "--job={job}", "--decoder_gpus={decoder_gpus}", "--decoder_replicas=1", "--cluster_spec={job}=localhost:0"]
  """.format(
      job_name=name,
      container_name=container_name,
      image=image,
      model=model,
      logdir=logdir,
      job=job,
      decoder_gpus=decoder_gpus)