dijob-sidecar.yaml 7.6 KB
Newer Older
1
apiVersion: diengine.opendilab.org/v2alpha1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
kind: DIJob
metadata:
  name: dijob-cartpole-dqn
spec:
  group: xxx
  priorityClassName: ""
  cleanPodPolicy: "Running"
  volumes:
  - name: cache-volume
    emptyDir:
      medium: Memory
      sizeLimit: 128Mi
  - name: work-dir
    hostPath:
      path: /data/nfs/ding/cartpole
  coordinator:
    template:
      spec:
        shareProcessNamespace: true
        containers:
        - name: shell
          image: busybox
          imagePullPolicy: IfNotPresent
          securityContext:
            capabilities:
              add:
              - SYS_PTRACE
          stdin: true
          tty: true
        - name: di-container
L
liqingping 已提交
32
          image: opendilab/ding:2021-09-26
33 34 35 36 37 38 39 40 41 42 43
          imagePullPolicy: Always
          env:
          - name: PYTHONUNBUFFERED
            value: "1"
          command: ["/bin/bash", "-c",]
          args:
          - |
            cat <<EOF > cartpole_dqn_config_k8s.py
            from easydict import EasyDict

            cartpole_dqn_config = dict(
L
liqingping 已提交
44
                exp_name='cartpole_dqn',
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
                env=dict(
                    collector_env_num=8,
                    collector_episode_num=2,
                    evaluator_env_num=5,
                    evaluator_episode_num=1,
                    stop_value=195,
                ),
                policy=dict(
                    cuda=False,
                    model=dict(
                        obs_shape=4,
                        action_shape=2,
                        encoder_hidden_size_list=[128, 128, 64],
                        dueling=True,
                    ),
                    nstep=3,
                    discount_factor=0.97,
                    learn=dict(
                        batch_size=32,
                        learning_rate=0.001,
                        learner=dict(
                            learner_num=1,
                            send_policy_freq=1,
                        ),
                    ),
                    collect=dict(
                        n_sample=16,
                        collector=dict(
                            collector_num=2,
                            update_policy_second=3,
                        ),
                    ),
                    eval=dict(evaluator=dict(eval_freq=50, )),
                    other=dict(
                        eps=dict(
                            type='exp',
                            start=0.95,
                            end=0.1,
                            decay=100000,
                        ),
                        replay_buffer=dict(
                            replay_buffer_size=100000,
                            enable_track_used_data=False,
                        ),
                        commander=dict(
L
liqingping 已提交
90
                            collector_task_space=2,
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
                            learner_task_space=1,
                            eval_interval=5,
                        ),
                    ),
                ),
            )
            cartpole_dqn_config = EasyDict(cartpole_dqn_config)
            main_config = cartpole_dqn_config

            cartpole_dqn_create_config = dict(
                env=dict(
                    type='cartpole',
                    import_names=['dizoo.classic_control.cartpole.envs.cartpole_env'],
                ),
                env_manager=dict(type='base'),
                policy=dict(type='dqn_command'),
                learner=dict(type='base', import_names=['ding.worker.learner.base_learner']),
                collector=dict(
                    type='zergling',
L
liqingping 已提交
110
                    import_names=['ding.worker.collector.zergling_parallel_collector'],
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
                ),
                commander=dict(
                    type='solo',
                    import_names=['ding.worker.coordinator.solo_parallel_commander'],
                ),
                comm_learner=dict(
                    type='flask_fs',
                    import_names=['ding.worker.learner.comm.flask_fs_learner'],
                ),
                comm_collector=dict(
                    type='flask_fs',
                    import_names=['ding.worker.collector.comm.flask_fs_collector'],
                ),
            )
            cartpole_dqn_create_config = EasyDict(cartpole_dqn_create_config)
            create_config = cartpole_dqn_create_config

            cartpole_dqn_system_config = dict(
                coordinator=dict(
                    operator_server=dict(
                        system_addr='di-server.di-system:8080',
132
                        api_version='/v2alpha1',
133 134 135 136 137
                        init_replicas_request=dict(
                            collectors={
                                "replicas": 2,
                            },
                            learners={
L
liqingping 已提交
138
                                "gpus": "0",
139 140 141 142 143 144 145
                                "replicas": 1,
                            },
                        ),
                        collector_target_num=2,
                        learner_target_num=1,
                    ),
                ),
L
liqingping 已提交
146 147
                path_data='./{}/data'.format(main_config.exp_name),
                path_policy='./{}/policy'.format(main_config.exp_name),
148 149 150 151 152
                communication_mode='auto',
                learner_gpu_num=1,
            )
            cartpole_dqn_system_config = EasyDict(cartpole_dqn_system_config)
            system_config = cartpole_dqn_system_config
L
liqingping 已提交
153 154 155 156

            if __name__ == '__main__':
                from ding.entry.parallel_entry import parallel_pipeline
                parallel_pipeline([main_config, create_config, system_config], seed=9)
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
            EOF

            ding -m dist --module config -P k8s -c ./cartpole_dqn_config_k8s.py -s 0;
            ding -m dist --module coordinator -c ./cartpole_dqn_config_k8s.py.pkl -s 0 -cdp $COORDINATOR_PORT
          ports:
          - name: di-port
            containerPort: 22270
          volumeMounts:
          - name: work-dir
            mountPath: /ding
  collector:
    template:
      spec:
        shareProcessNamespace: true
        containers:
        - name: shell
          image: busybox
          imagePullPolicy: IfNotPresent
          securityContext:
            capabilities:
              add:
              - SYS_PTRACE
          stdin: true
          tty: true
        - name: di-container
L
liqingping 已提交
182
          image: opendilab/ding:2021-09-26
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
          imagePullPolicy: Always
          env:
          - name: PYTHONUNBUFFERED
            value: "1"
          command: ["/bin/bash", "-c",]
          args:
          - |
            ding -m dist --module collector -c ./cartpole_dqn_config_k8s.py.pkl -s 0 -clp $COLLECTOR_PORT
          ports:
          - name: di-port
            containerPort: 22270
          volumeMounts:
          - name: work-dir
            mountPath: /ding
  learner:
    template:
      spec:
        shareProcessNamespace: true
        containers:
        - name: shell
          image: busybox
          imagePullPolicy: IfNotPresent
          securityContext:
            capabilities:
              add:
              - SYS_PTRACE
          stdin: true
          tty: true
        - name: di-container
L
liqingping 已提交
212
          image: opendilab/ding:2021-09-26
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
          imagePullPolicy: Always
          env:
          - name: PYTHONUNBUFFERED
            value: "1"
          command: ["/bin/bash", "-c",]
          args:
          - |
            ding -m dist --module spawn_learner -c ./cartpole_dqn_config_k8s.py.pkl -s 0 -lp $LEARNER_PORT
          ports:
          - name: di-port
            containerPort: 22270
          volumeMounts:
          - name: cache-volume
            mountPath: /dev/shm
          - name: work-dir
            mountPath: /ding