question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Go Templates are hard to work with programmatically

See original GitHub issue

/kind feature

Describe the solution you’d like Katib currently uses go templates to define the training jobs. In the random example https://github.com/kubeflow/katib/blob/4e96b94600a598e1786ea7c88778a84747268a4d/examples/v1alpha2/random-example.yaml#L20

The training job template is set to

          apiVersion: batch/v1
          kind: Job
          metadata:
            name: {{.Trial}}
            namespace: {{.NameSpace}}
          spec:
            template:
              spec:
                containers:
                - name: {{.Trial}}
                  image: katib/mxnet-mnist-example
                  command:
                  - "python"
                  - "/mxnet/example/image-classification/train_mnist.py"
                  - "--batch-size=64"
                  {{- with .HyperParameters}}
                  {{- range .}}
                  - "{{.Name}}={{.Value}}"
                  {{- end}}
                  {{- end}}
                restartPolicy: Never

The problem with using go templates is that the manifest is no longer valid yaml. So you can’t parse the YAML spec in python and then manipulate that object programmatically.

Consider the following example

  1. We are using a notebook (e.g this one) to launch katib jobs
  2. We are using fairing to build the docker images
  3. We would like to programmatically set the docker image in our training jobs for katib to the newly built image with fairing

Typically we would just define the K8s object a python dictionary and then we can easily set the image.

However, because the training job in the case of katib is a go template we can no longer parse it into a dictionary, manipulate it and then serialize it to YAML.

It might be worth looking at Tekton to see how it does parameter substitution since Tekton objects are valid YAML.

/cc @johnugeorge @richardsliu

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hougangliucommented, Oct 9, 2019

yes, AST can be one another hyperparamater-inject-kind, the hyperparamater-inject-kind must keep consistent with user source code.

1reaction
gaocegegecommented, Oct 9, 2019

SGTM. Actually, I have researched if we could inject hyperparameters by rewriting Python AST.

https://github.com/caicloud/katib/blob/056cc36515052156fa2ada681d7ff487441eedc0/py/hypertransformer/README.md

NNI follows this way. I think it is better to be extensible. We could support multiples approaches.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Templates in Go - Level Up Coding
Again, first step we need to do is to parse the template(s). We do this with template.ParseFiles() which takes the relative paths to...
Read more >
Is it possible to use gofmt on templates that are designed to be ...
The short answer is 'no' and the reason is a bit subtle: (1) as you point out it's unnecessary because one can easily...
Read more >
Templates in GoLang - GeeksforGeeks
Template in Golang is a robust feature to create dynamic content or show customized output to the user. Golang has two packages with ......
Read more >
Dynamic Templates in Go - Crimson Macaw
We will have a string, which is where our template is saved, and a map[string]interface{} i.e. our data map as inputs to this...
Read more >
Advanced Hugo Template Tips and Tricks - Stackbit
Hugo uses Go's text and HTML templates that underly a lot of the core features you'll use in every template, but it adds...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found