bestdive commited on
Commit
162021c
Β·
verified Β·
1 Parent(s): 168bdf9

Add introductory trained PPO policy and honest evaluation

Browse files
Files changed (6) hide show
  1. Pyramids.onnx +3 -0
  2. README.md +40 -0
  3. evaluate_unity.py +28 -0
  4. evaluation.json +123 -0
  5. training-config.yaml +23 -0
  6. training.log +83 -0
Pyramids.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:87afd23387a34f3788d48c3b2a55cceec3a79c6b2eb3be98549722f5b68bb1bb
3
+ size 167102
README.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: ml-agents
4
+ tags:
5
+ - ml-agents
6
+ - reinforcement-learning
7
+ - ML-Agents-Pyramids
8
+ model-index:
9
+ - name: ppo-Pyramids
10
+ results:
11
+ - task:
12
+ type: reinforcement-learning
13
+ name: reinforcement-learning
14
+ dataset:
15
+ name: ML-Agents-Pyramids
16
+ type: ML-Agents-Pyramids
17
+ metrics:
18
+ - type: mean_reward
19
+ value: -0.9999999310821295 +/- 0.0
20
+ name: mean_reward
21
+ ---
22
+ # PPO Pyramids
23
+
24
+ Trained from random initialization by Kay Zheng (bestdive), with AI coding and execution assistance, for the Hugging Face Deep RL course. No pretrained policy or fabricated evaluation metrics were used. Training used free Colab CPU, seed 42, ML-Agents 1.1.0, and 100096 environment steps.
25
+
26
+ This introductory policy has not solved the sparse-reward task; all evaluation returns are approximately -1. The course Unit 5 criterion requires submission of a genuinely trained model, without a minimum reward.
27
+
28
+ ## Independent evaluation
29
+
30
+ 112 completed episodes, new environment seed 100002, deterministic ONNX actions. Mean reward -0.9999999310821295, population standard deviation 0.0. See evaluation.json for every episode return and evaluate_unity.py for the evaluation procedure. All agents terminating in the final vector batch were retained.
31
+
32
+ ## Reproduction
33
+
34
+ Python 3.10.12, mlagents==1.1.0, torch==2.2.2, onnx==1.15.0, setuptools<81, onnxruntime. Download the environment from the official course Unit 5 hands-on. Train with:
35
+
36
+ ```sh
37
+ mlagents-learn training-config.yaml --env=PATH_TO_ENV --run-id=Kay-Pyramids --results-dir=results --no-graphics --seed=42 --torch-device=cpu
38
+ ```
39
+
40
+ The configuration, training log, ONNX checkpoint, and independent evaluation are included. Model performance is limited to this simulated task.
evaluate_unity.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pathlib,json,numpy as np,onnxruntime as ort
2
+ from mlagents_envs.environment import UnityEnvironment
3
+ from mlagents_envs.base_env import ActionTuple
4
+ from mlagents_envs.side_channel.engine_configuration_channel import EngineConfigurationChannel
5
+ root=pathlib.Path('/content/hf-rl')
6
+ for number,name in enumerate(['SnowballTarget','Pyramids']):
7
+ binary=next(p for p in (root/name).rglob('*') if p.is_file() and p.name in [name,name+'.x86_64'] and p.read_bytes()[:4]==bytes([127,69,76,70]))
8
+ channel=EngineConfigurationChannel();channel.set_configuration_parameters(time_scale=20)
9
+ env=UnityEnvironment(file_name=str(binary),seed=100001+number,worker_id=10+number,no_graphics=True,side_channels=[channel])
10
+ env.reset();behavior=next(iter(env.behavior_specs));spec=env.behavior_specs[behavior]
11
+ session=ort.InferenceSession(str(root/'results'/('Kay-'+name)/(name+'.onnx')))
12
+ totals={};rewards=[]
13
+ for step in range(100000):
14
+ decisions,terminals=env.get_steps(behavior)
15
+ for i,aid in enumerate(terminals.agent_id):
16
+ rewards.append(float(totals.pop(int(aid),0)+terminals.reward[i]))
17
+ if len(rewards)>=100:break
18
+ if len(decisions):
19
+ for i,aid in enumerate(decisions.agent_id):totals[int(aid)]=totals.get(int(aid),0)+float(decisions.reward[i])
20
+ feed={f'obs_{i}':x.astype(np.float32) for i,x in enumerate(decisions.obs)}
21
+ feed['action_masks']=np.ones((len(decisions),sum(spec.action_spec.discrete_branches)),dtype=np.float32) if decisions.action_mask is None else 1-np.concatenate(decisions.action_mask,axis=1).astype(np.float32)
22
+ actions=session.run(['deterministic_discrete_actions'],feed)[0].astype(np.int32)
23
+ env.set_actions(behavior,ActionTuple(discrete=actions))
24
+ env.step()
25
+ env.close()
26
+ report={'environment':'ML-Agents-'+name,'evaluation_seed':100001+number,'episodes':len(rewards),'mean_reward':float(np.mean(rewards)),'std_reward':float(np.std(rewards)),'episode_returns':rewards,'policy':'deterministic ONNX actions','training_seed':42}
27
+ (root/'results'/('Kay-'+name)/'evaluation.json').write_text(json.dumps(report,indent=2))
28
+ print({k:v for k,v in report.items() if k!='episode_returns'},flush=True)
evaluation.json ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "environment": "ML-Agents-Pyramids",
3
+ "evaluation_seed": 100002,
4
+ "episodes": 112,
5
+ "mean_reward": -0.9999999310821295,
6
+ "std_reward": 0.0,
7
+ "episode_returns": [
8
+ -0.9999999310821295,
9
+ -0.9999999310821295,
10
+ -0.9999999310821295,
11
+ -0.9999999310821295,
12
+ -0.9999999310821295,
13
+ -0.9999999310821295,
14
+ -0.9999999310821295,
15
+ -0.9999999310821295,
16
+ -0.9999999310821295,
17
+ -0.9999999310821295,
18
+ -0.9999999310821295,
19
+ -0.9999999310821295,
20
+ -0.9999999310821295,
21
+ -0.9999999310821295,
22
+ -0.9999999310821295,
23
+ -0.9999999310821295,
24
+ -0.9999999310821295,
25
+ -0.9999999310821295,
26
+ -0.9999999310821295,
27
+ -0.9999999310821295,
28
+ -0.9999999310821295,
29
+ -0.9999999310821295,
30
+ -0.9999999310821295,
31
+ -0.9999999310821295,
32
+ -0.9999999310821295,
33
+ -0.9999999310821295,
34
+ -0.9999999310821295,
35
+ -0.9999999310821295,
36
+ -0.9999999310821295,
37
+ -0.9999999310821295,
38
+ -0.9999999310821295,
39
+ -0.9999999310821295,
40
+ -0.9999999310821295,
41
+ -0.9999999310821295,
42
+ -0.9999999310821295,
43
+ -0.9999999310821295,
44
+ -0.9999999310821295,
45
+ -0.9999999310821295,
46
+ -0.9999999310821295,
47
+ -0.9999999310821295,
48
+ -0.9999999310821295,
49
+ -0.9999999310821295,
50
+ -0.9999999310821295,
51
+ -0.9999999310821295,
52
+ -0.9999999310821295,
53
+ -0.9999999310821295,
54
+ -0.9999999310821295,
55
+ -0.9999999310821295,
56
+ -0.9999999310821295,
57
+ -0.9999999310821295,
58
+ -0.9999999310821295,
59
+ -0.9999999310821295,
60
+ -0.9999999310821295,
61
+ -0.9999999310821295,
62
+ -0.9999999310821295,
63
+ -0.9999999310821295,
64
+ -0.9999999310821295,
65
+ -0.9999999310821295,
66
+ -0.9999999310821295,
67
+ -0.9999999310821295,
68
+ -0.9999999310821295,
69
+ -0.9999999310821295,
70
+ -0.9999999310821295,
71
+ -0.9999999310821295,
72
+ -0.9999999310821295,
73
+ -0.9999999310821295,
74
+ -0.9999999310821295,
75
+ -0.9999999310821295,
76
+ -0.9999999310821295,
77
+ -0.9999999310821295,
78
+ -0.9999999310821295,
79
+ -0.9999999310821295,
80
+ -0.9999999310821295,
81
+ -0.9999999310821295,
82
+ -0.9999999310821295,
83
+ -0.9999999310821295,
84
+ -0.9999999310821295,
85
+ -0.9999999310821295,
86
+ -0.9999999310821295,
87
+ -0.9999999310821295,
88
+ -0.9999999310821295,
89
+ -0.9999999310821295,
90
+ -0.9999999310821295,
91
+ -0.9999999310821295,
92
+ -0.9999999310821295,
93
+ -0.9999999310821295,
94
+ -0.9999999310821295,
95
+ -0.9999999310821295,
96
+ -0.9999999310821295,
97
+ -0.9999999310821295,
98
+ -0.9999999310821295,
99
+ -0.9999999310821295,
100
+ -0.9999999310821295,
101
+ -0.9999999310821295,
102
+ -0.9999999310821295,
103
+ -0.9999999310821295,
104
+ -0.9999999310821295,
105
+ -0.9999999310821295,
106
+ -0.9999999310821295,
107
+ -0.9999999310821295,
108
+ -0.9999999310821295,
109
+ -0.9999999310821295,
110
+ -0.9999999310821295,
111
+ -0.9999999310821295,
112
+ -0.9999999310821295,
113
+ -0.9999999310821295,
114
+ -0.9999999310821295,
115
+ -0.9999999310821295,
116
+ -0.9999999310821295,
117
+ -0.9999999310821295,
118
+ -0.9999999310821295,
119
+ -0.9999999310821295
120
+ ],
121
+ "policy": "deterministic ONNX actions",
122
+ "training_seed": 42
123
+ }
training-config.yaml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ default_settings:
2
+ trainer_type: ppo
3
+ hyperparameters:
4
+ batch_size: 512
5
+ buffer_size: 5120
6
+ learning_rate: 0.0003
7
+ beta: 0.005
8
+ epsilon: 0.2
9
+ lambd: 0.95
10
+ num_epoch: 3
11
+ learning_rate_schedule: linear
12
+ network_settings:
13
+ normalize: true
14
+ hidden_units: 128
15
+ num_layers: 2
16
+ reward_signals:
17
+ extrinsic:
18
+ gamma: 0.99
19
+ strength: 1.0
20
+ max_steps: 100000
21
+ time_horizon: 64
22
+ summary_freq: 10000
23
+ checkpoint_interval: 50000
training.log ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /content/rl-venv/lib/python3.10/site-packages/mlagents/torch_utils/torch.py:4: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
2
+ import pkg_resources
3
+
4
+ ┐ β•–
5
+ ╓╖╬│║ ││╬╖╖
6
+ β•“β•–β•¬β”‚β”‚β”‚β”‚β”‚β”˜ ╬│││││╬╖
7
+ β•–β•¬β”‚β”‚β”‚β”‚β”‚β•¬β•œ ╙╬│││││╖╖ β•—β•—β•—
8
+ ╬╬╬╬╖││╦╖ ╖╬││╗╣╣╣╬ β•Ÿβ•£β•£β•¬ β•Ÿβ•£β•£β•£ β•œβ•œβ•œ β•Ÿβ•£β•£
9
+ ╬╬╬╬╬╬╬╬╖│╬╖╖╓╬β•ͺ│╓╣╣╣╣╣╣╣╬ β•Ÿβ•£β•£β•¬ β•Ÿβ•£β•£β•£ β•’β•£β•£β•–β•—β•£β•£β•£β•— β•£β•£β•£ β•£β•£β•£β•£β•£β•£ β•Ÿβ•£β•£β•– β•£β•£β•£
10
+ ╬╬╬╬┐ β•™β•¬β•¬β•¬β•¬β”‚β•“β•£β•£β•£β•β•œ ╫╣╣╣╬ β•Ÿβ•£β•£β•¬ β•Ÿβ•£β•£β•£ β•Ÿβ•£β•£β•£β•™ β•™β•£β•£β•£ β•£β•£β•£ β•™β•Ÿβ•£β•£β•œβ•™ β•«β•£β•£ β•Ÿβ•£β•£
11
+ ╬╬╬╬┐ ╙╬╬╣╣ ╫╣╣╣╬ β•Ÿβ•£β•£β•¬ β•Ÿβ•£β•£β•£ β•Ÿβ•£β•£β•¬ β•£β•£β•£ β•£β•£β•£ β•Ÿβ•£β•£ β•£β•£β•£β”Œβ•£β•£β•œ
12
+ β•¬β•¬β•¬β•œ ╬╬╣╣ ╙╝╣╣╬ β•™β•£β•£β•£β•—β•–β•“β•—β•£β•£β•£β•œ β•Ÿβ•£β•£β•¬ β•£β•£β•£ β•£β•£β•£ β•Ÿβ•£β•£β•¦β•“ β•£β•£β•£β•£β•£
13
+ β•™ ╓╦╖ ╬╬╣╣ β•“β•—β•—β•– β•™β•β•£β•£β•£β•£β•β•œ β•˜β•β•β•œ ╝╝╝ ╝╝╝ β•™β•£β•£β•£ β•Ÿβ•£β•£β•£
14
+ ╩╬╬╬╬╬╬╦╦╬╬╣╣╗╣╣╣╣╣╣╣╝ β•«β•£β•£β•£β•£
15
+ β•™β•¬β•¬β•¬β•¬β•¬β•¬β•¬β•£β•£β•£β•£β•£β•£β•β•œ
16
+ β•™β•¬β•¬β•¬β•£β•£β•£β•œ
17
+ β•™
18
+
19
+ Version information:
20
+ ml-agents: 1.1.0,
21
+ ml-agents-envs: 1.1.0,
22
+ Communicator API: 1.5.0,
23
+ PyTorch: 2.2.2+cpu
24
+ [INFO] Connected to Unity environment with package version 2.2.1-exp.1 and communication version 1.5.0
25
+ [INFO] Connected new brain: Pyramids?team=0
26
+ [INFO] Hyperparameters for behavior name Pyramids:
27
+ trainer_type: ppo
28
+ hyperparameters:
29
+ batch_size: 512
30
+ buffer_size: 5120
31
+ learning_rate: 0.0003
32
+ beta: 0.005
33
+ epsilon: 0.2
34
+ lambd: 0.95
35
+ num_epoch: 3
36
+ shared_critic: False
37
+ learning_rate_schedule: linear
38
+ beta_schedule: linear
39
+ epsilon_schedule: linear
40
+ checkpoint_interval: 50000
41
+ network_settings:
42
+ normalize: True
43
+ hidden_units: 128
44
+ num_layers: 2
45
+ vis_encode_type: simple
46
+ memory: None
47
+ goal_conditioning_type: hyper
48
+ deterministic: False
49
+ reward_signals:
50
+ extrinsic:
51
+ gamma: 0.99
52
+ strength: 1.0
53
+ network_settings:
54
+ normalize: False
55
+ hidden_units: 128
56
+ num_layers: 2
57
+ vis_encode_type: simple
58
+ memory: None
59
+ goal_conditioning_type: hyper
60
+ deterministic: False
61
+ init_path: None
62
+ keep_checkpoints: 5
63
+ even_checkpoints: False
64
+ max_steps: 100000
65
+ time_horizon: 64
66
+ summary_freq: 10000
67
+ threaded: False
68
+ self_play: None
69
+ behavioral_cloning: None
70
+ [INFO] Pyramids. Step: 10000. Time Elapsed: 23.520 s. No episode was completed since last summary. Training.
71
+ [INFO] Pyramids. Step: 20000. Time Elapsed: 45.633 s. Mean Reward: -1.000. Std of Reward: 0.000. Training.
72
+ [INFO] Pyramids. Step: 30000. Time Elapsed: 63.708 s. No episode was completed since last summary. Training.
73
+ [INFO] Pyramids. Step: 40000. Time Elapsed: 86.239 s. Mean Reward: -1.000. Std of Reward: 0.000. Training.
74
+ [INFO] Pyramids. Step: 50000. Time Elapsed: 109.785 s. Mean Reward: -1.000. Std of Reward: 0.000. Training.
75
+ [INFO] Exported /content/hf-rl/results/Kay-Pyramids/Pyramids/Pyramids-49984.onnx
76
+ [INFO] Pyramids. Step: 60000. Time Elapsed: 127.559 s. No episode was completed since last summary. Training.
77
+ [INFO] Pyramids. Step: 70000. Time Elapsed: 150.552 s. Mean Reward: -1.000. Std of Reward: 0.000. Training.
78
+ [INFO] Pyramids. Step: 80000. Time Elapsed: 169.868 s. Mean Reward: -1.000. Std of Reward: 0.000. Training.
79
+ [INFO] Pyramids. Step: 90000. Time Elapsed: 190.934 s. Mean Reward: -1.000. Std of Reward: 0.000. Training.
80
+ [INFO] Pyramids. Step: 100000. Time Elapsed: 211.785 s. Mean Reward: -1.000. Std of Reward: 0.000. Training.
81
+ [INFO] Exported /content/hf-rl/results/Kay-Pyramids/Pyramids/Pyramids-99968.onnx
82
+ [INFO] Exported /content/hf-rl/results/Kay-Pyramids/Pyramids/Pyramids-100096.onnx
83
+ [INFO] Copied /content/hf-rl/results/Kay-Pyramids/Pyramids/Pyramids-100096.onnx to /content/hf-rl/results/Kay-Pyramids/Pyramids.onnx.