tf_wide_deep.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package workloads
  14. import (
  15. "fmt"
  16. "strings"
  17. "time"
  18. v1 "k8s.io/api/core/v1"
  19. "k8s.io/apimachinery/pkg/api/resource"
  20. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  21. kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
  22. "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager"
  23. )
  24. // tfWideDeepWorkload defines a workload to run
  25. // https://github.com/tensorflow/models/tree/master/official/r1/wide_deep.
  26. type tfWideDeepWorkload struct{}
  27. // Ensure tfWideDeepWorkload implements NodePerfWorkload interface.
  28. var _ NodePerfWorkload = &tfWideDeepWorkload{}
  29. func (w tfWideDeepWorkload) Name() string {
  30. return "tensorflow-wide-deep"
  31. }
  32. func (w tfWideDeepWorkload) PodSpec() v1.PodSpec {
  33. var containers []v1.Container
  34. ctn := v1.Container{
  35. Name: fmt.Sprintf("%s-ctn", w.Name()),
  36. Image: "gcr.io/kubernetes-e2e-test-images/node-perf/tf-wide-deep-amd64:1.0",
  37. Resources: v1.ResourceRequirements{
  38. Requests: v1.ResourceList{
  39. v1.ResourceName(v1.ResourceCPU): resource.MustParse("15000m"),
  40. v1.ResourceName(v1.ResourceMemory): resource.MustParse("16Gi"),
  41. },
  42. Limits: v1.ResourceList{
  43. v1.ResourceName(v1.ResourceCPU): resource.MustParse("15000m"),
  44. v1.ResourceName(v1.ResourceMemory): resource.MustParse("16Gi"),
  45. },
  46. },
  47. Command: []string{"/bin/sh"},
  48. Args: []string{"-c", "python ./data_download.py && time -p python ./wide_deep.py --model_type=wide_deep --train_epochs=300 --epochs_between_evals=300 --batch_size=32561"},
  49. }
  50. containers = append(containers, ctn)
  51. return v1.PodSpec{
  52. RestartPolicy: v1.RestartPolicyNever,
  53. Containers: containers,
  54. }
  55. }
  56. func (w tfWideDeepWorkload) Timeout() time.Duration {
  57. return 15 * time.Minute
  58. }
  59. func (w tfWideDeepWorkload) KubeletConfig(oldCfg *kubeletconfig.KubeletConfiguration) (newCfg *kubeletconfig.KubeletConfiguration, err error) {
  60. // Enable CPU Manager in Kubelet with static policy.
  61. newCfg = oldCfg.DeepCopy()
  62. // Set the CPU Manager policy to static.
  63. newCfg.CPUManagerPolicy = string(cpumanager.PolicyStatic)
  64. // Set the CPU Manager reconcile period to 10 second.
  65. newCfg.CPUManagerReconcilePeriod = metav1.Duration{Duration: 10 * time.Second}
  66. // The Kubelet panics if either kube-reserved or system-reserved is not set
  67. // when static CPU Manager is enabled. Set cpu in kube-reserved > 0 so that
  68. // kubelet doesn't panic.
  69. if newCfg.KubeReserved == nil {
  70. newCfg.KubeReserved = map[string]string{}
  71. }
  72. if _, ok := newCfg.KubeReserved["cpu"]; !ok {
  73. newCfg.KubeReserved["cpu"] = "200m"
  74. }
  75. return newCfg, nil
  76. }
  77. func (w tfWideDeepWorkload) PreTestExec() error {
  78. cmd := "/bin/sh"
  79. args := []string{"-c", "rm -f /var/lib/kubelet/cpu_manager_state"}
  80. err := runCmd(cmd, args)
  81. return err
  82. }
  83. func (w tfWideDeepWorkload) PostTestExec() error {
  84. cmd := "/bin/sh"
  85. args := []string{"-c", "rm -f /var/lib/kubelet/cpu_manager_state"}
  86. err := runCmd(cmd, args)
  87. return err
  88. }
  89. func (w tfWideDeepWorkload) ExtractPerformanceFromLogs(logs string) (perf time.Duration, err error) {
  90. perfLine, err := getMatchingLineFromLog(logs, "real")
  91. if err != nil {
  92. return perf, err
  93. }
  94. perfString := fmt.Sprintf("%ss", strings.TrimSpace(strings.TrimPrefix(perfLine, "real")))
  95. perf, err = time.ParseDuration(perfString)
  96. return perf, err
  97. }