rabitrabi commited on
Commit
653b5a7
·
verified ·
1 Parent(s): 48fc8cd

Publish trained Pyramids policy and 32-episode evaluation

Browse files
Pyramids.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba413627b4227b53be5539aee25d049d50a9c58d022c350f3a2b399309c24e5d
3
+ size 162254
Pyramids.yaml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ behaviors:
2
+ Pyramids:
3
+ trainer_type: ppo
4
+ hyperparameters:
5
+ batch_size: 128
6
+ buffer_size: 2048
7
+ learning_rate: 0.0003
8
+ beta: 0.01
9
+ epsilon: 0.2
10
+ lambd: 0.95
11
+ num_epoch: 3
12
+ learning_rate_schedule: linear
13
+ network_settings:
14
+ normalize: false
15
+ hidden_units: 128
16
+ num_layers: 2
17
+ vis_encode_type: simple
18
+ reward_signals:
19
+ extrinsic:
20
+ gamma: 0.99
21
+ strength: 1.0
22
+ rnd:
23
+ gamma: 0.99
24
+ strength: 0.01
25
+ network_settings:
26
+ hidden_units: 64
27
+ num_layers: 3
28
+ learning_rate: 0.0001
29
+ keep_checkpoints: 5
30
+ max_steps: 65536
31
+ time_horizon: 128
32
+ summary_freq: 4096
Pyramids/Pyramids-65841.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba413627b4227b53be5539aee25d049d50a9c58d022c350f3a2b399309c24e5d
3
+ size 162254
Pyramids/Pyramids-65841.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a802e8dba7e6791fb16a118c1263977b9230033923ffc9fff448455e8976e25d
3
+ size 1120862
Pyramids/checkpoint.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd883b592da0ab635415bc46b03c340ba6ede5201c97db69ebb199493fc71e9c
3
+ size 1120546
Pyramids/events.out.tfevents.1796028590.rabia-LOQ-15IAX9E.3405341.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b4326e6acff15baf687f1a177e79f374aed845b4df5f7aad53cb1977cb96821
3
+ size 30668
README.md ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: ml-agents
3
+ tags:
4
+ - reinforcement-learning
5
+ - deep-reinforcement-learning
6
+ - deep-rl-course
7
+ - ml-agents
8
+ - Pyramids
9
+ - ML-Agents-Pyramids
10
+ - onnx
11
+ model-index:
12
+ - name: PPO Pyramids
13
+ results:
14
+ - task:
15
+ type: reinforcement-learning
16
+ name: Reinforcement Learning
17
+ dataset:
18
+ type: Pyramids
19
+ name: Pyramids
20
+ metrics:
21
+ - type: mean_reward
22
+ name: Mean reward
23
+ value: -1.000000 +/- 0.000000
24
+ ---
25
+
26
+ # PPO on Pyramids
27
+
28
+ This Unity ML-Agents 1.1.0 policy was trained from scratch on CPU for the Hugging Face Deep Reinforcement Learning Course with a 65,536-step budget and training seed 42.
29
+
30
+ ## Evaluation
31
+
32
+ The exported ONNX policy sampled actions in a fresh Unity session with seed 2026. Across the first 32 completed episodes, the mean return was **-1.000** and the population standard deviation was **0.000**. Training used the random network distillation curiosity bonus. Evaluation measures the original environment rewards. Individual returns are in `evaluation.json`.
33
+
34
+ ## Reproduce
35
+
36
+ Use Python 3.10.12, Unity ML-Agents 1.1.0, CPU PyTorch 2.2.2, ONNX 1.15.0 and ONNX Runtime 1.18.1. Download the Linux simulator linked in [course unit 5](https://huggingface.co/learn/deep-rl-course/en/unit5/hands-on).
37
+
38
+ ```bash
39
+ mlagents-learn Pyramids.yaml --env=/path/to/Pyramids --run-id=Pyramids --no-graphics --seed=42 --time-scale=64 --torch-device=cpu
40
+ python evaluate.py Pyramids /path/to/Pyramids 6360 --seed=2026 --episodes=32
41
+ ```
config.json ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "default_settings": null,
3
+ "behaviors": {
4
+ "Pyramids": {
5
+ "trainer_type": "ppo",
6
+ "hyperparameters": {
7
+ "batch_size": 128,
8
+ "buffer_size": 2048,
9
+ "learning_rate": 0.0003,
10
+ "beta": 0.01,
11
+ "epsilon": 0.2,
12
+ "lambd": 0.95,
13
+ "num_epoch": 3,
14
+ "shared_critic": false,
15
+ "learning_rate_schedule": "linear",
16
+ "beta_schedule": "linear",
17
+ "epsilon_schedule": "linear"
18
+ },
19
+ "checkpoint_interval": 500000,
20
+ "network_settings": {
21
+ "normalize": false,
22
+ "hidden_units": 128,
23
+ "num_layers": 2,
24
+ "vis_encode_type": "simple",
25
+ "memory": null,
26
+ "goal_conditioning_type": "hyper",
27
+ "deterministic": false
28
+ },
29
+ "reward_signals": {
30
+ "extrinsic": {
31
+ "gamma": 0.99,
32
+ "strength": 1.0,
33
+ "network_settings": {
34
+ "normalize": false,
35
+ "hidden_units": 128,
36
+ "num_layers": 2,
37
+ "vis_encode_type": "simple",
38
+ "memory": null,
39
+ "goal_conditioning_type": "hyper",
40
+ "deterministic": false
41
+ }
42
+ },
43
+ "rnd": {
44
+ "gamma": 0.99,
45
+ "strength": 0.01,
46
+ "network_settings": {
47
+ "normalize": false,
48
+ "hidden_units": 64,
49
+ "num_layers": 3,
50
+ "vis_encode_type": "simple",
51
+ "memory": null,
52
+ "goal_conditioning_type": "hyper",
53
+ "deterministic": false
54
+ },
55
+ "learning_rate": 0.0001,
56
+ "encoding_size": null
57
+ }
58
+ },
59
+ "init_path": null,
60
+ "keep_checkpoints": 5,
61
+ "even_checkpoints": false,
62
+ "max_steps": 65536,
63
+ "time_horizon": 128,
64
+ "summary_freq": 4096,
65
+ "threaded": false,
66
+ "self_play": null,
67
+ "behavioral_cloning": null
68
+ }
69
+ },
70
+ "env_settings": {
71
+ "env_path": "envs/Pyramids/Pyramids",
72
+ "env_args": [
73
+ "-job-worker-count",
74
+ "1"
75
+ ],
76
+ "base_port": 6330,
77
+ "num_envs": 1,
78
+ "num_areas": 1,
79
+ "timeout_wait": 60,
80
+ "seed": 42,
81
+ "max_lifetime_restarts": 10,
82
+ "restarts_rate_limit_n": 1,
83
+ "restarts_rate_limit_period_s": 60
84
+ },
85
+ "engine_settings": {
86
+ "width": 84,
87
+ "height": 84,
88
+ "quality_level": 5,
89
+ "time_scale": 64.0,
90
+ "target_frame_rate": -1,
91
+ "capture_frame_rate": 60,
92
+ "no_graphics": true,
93
+ "no_graphics_monitor": false
94
+ },
95
+ "environment_parameters": null,
96
+ "checkpoint_settings": {
97
+ "run_id": "Pyramids",
98
+ "initialize_from": null,
99
+ "load_model": false,
100
+ "resume": false,
101
+ "force": false,
102
+ "train_model": false,
103
+ "inference": false,
104
+ "results_dir": "results"
105
+ },
106
+ "torch_settings": {
107
+ "device": "cpu"
108
+ },
109
+ "debug": false
110
+ }
configuration.yaml ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ default_settings: null
2
+ behaviors:
3
+ Pyramids:
4
+ trainer_type: ppo
5
+ hyperparameters:
6
+ batch_size: 128
7
+ buffer_size: 2048
8
+ learning_rate: 0.0003
9
+ beta: 0.01
10
+ epsilon: 0.2
11
+ lambd: 0.95
12
+ num_epoch: 3
13
+ shared_critic: false
14
+ learning_rate_schedule: linear
15
+ beta_schedule: linear
16
+ epsilon_schedule: linear
17
+ checkpoint_interval: 500000
18
+ network_settings:
19
+ normalize: false
20
+ hidden_units: 128
21
+ num_layers: 2
22
+ vis_encode_type: simple
23
+ memory: null
24
+ goal_conditioning_type: hyper
25
+ deterministic: false
26
+ reward_signals:
27
+ extrinsic:
28
+ gamma: 0.99
29
+ strength: 1.0
30
+ network_settings:
31
+ normalize: false
32
+ hidden_units: 128
33
+ num_layers: 2
34
+ vis_encode_type: simple
35
+ memory: null
36
+ goal_conditioning_type: hyper
37
+ deterministic: false
38
+ rnd:
39
+ gamma: 0.99
40
+ strength: 0.01
41
+ network_settings:
42
+ normalize: false
43
+ hidden_units: 64
44
+ num_layers: 3
45
+ vis_encode_type: simple
46
+ memory: null
47
+ goal_conditioning_type: hyper
48
+ deterministic: false
49
+ learning_rate: 0.0001
50
+ encoding_size: null
51
+ init_path: null
52
+ keep_checkpoints: 5
53
+ even_checkpoints: false
54
+ max_steps: 65536
55
+ time_horizon: 128
56
+ summary_freq: 4096
57
+ threaded: false
58
+ self_play: null
59
+ behavioral_cloning: null
60
+ env_settings:
61
+ env_path: envs/Pyramids/Pyramids
62
+ env_args:
63
+ - -job-worker-count
64
+ - '1'
65
+ base_port: 6330
66
+ num_envs: 1
67
+ num_areas: 1
68
+ timeout_wait: 60
69
+ seed: 42
70
+ max_lifetime_restarts: 10
71
+ restarts_rate_limit_n: 1
72
+ restarts_rate_limit_period_s: 60
73
+ engine_settings:
74
+ width: 84
75
+ height: 84
76
+ quality_level: 5
77
+ time_scale: 64.0
78
+ target_frame_rate: -1
79
+ capture_frame_rate: 60
80
+ no_graphics: true
81
+ no_graphics_monitor: false
82
+ environment_parameters: null
83
+ checkpoint_settings:
84
+ run_id: Pyramids
85
+ initialize_from: null
86
+ load_model: false
87
+ resume: false
88
+ force: false
89
+ train_model: false
90
+ inference: false
91
+ results_dir: results
92
+ torch_settings:
93
+ device: cpu
94
+ debug: false
evaluate.py ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Evaluate the exported ML-Agents policy in the original headless Unity build."""
2
+ import argparse
3
+ from collections import defaultdict
4
+ import json
5
+ from pathlib import Path
6
+
7
+ import numpy as np
8
+ import onnxruntime as ort
9
+ from mlagents_envs.base_env import ActionTuple
10
+ from mlagents_envs.environment import UnityEnvironment
11
+ from mlagents_envs.side_channel.engine_configuration_channel import EngineConfigurationChannel
12
+
13
+
14
+ def policy_actions(session, decisions, spec):
15
+ batch = len(decisions)
16
+ inputs = {}
17
+ for inp in session.get_inputs():
18
+ if inp.name.startswith("obs_"):
19
+ inputs[inp.name] = decisions.obs[int(inp.name[4:])]
20
+ elif inp.name == "action_masks":
21
+ if decisions.action_mask is None:
22
+ mask = np.ones((batch, sum(spec.discrete_branches)), np.float32)
23
+ else:
24
+ mask = 1 - np.concatenate(decisions.action_mask, axis=1).astype(np.float32)
25
+ inputs[inp.name] = mask
26
+ else:
27
+ raise ValueError(inp.name)
28
+ actions = ActionTuple()
29
+ for name, setter in (
30
+ ("continuous_actions", actions.add_continuous),
31
+ ("discrete_actions", actions.add_discrete),
32
+ ):
33
+ if name in {out.name for out in session.get_outputs()}:
34
+ setter(session.run([name], inputs)[0])
35
+ return actions
36
+
37
+
38
+ def evaluate(args):
39
+ engine = EngineConfigurationChannel()
40
+ engine.set_configuration_parameters(time_scale=64.0)
41
+ ort.set_seed(args.seed)
42
+ np.random.seed(args.seed)
43
+ opts = ort.SessionOptions()
44
+ opts.intra_op_num_threads = 1
45
+ opts.inter_op_num_threads = 1
46
+ model_path = Path("results") / args.name / (args.name + ".onnx")
47
+ if not model_path.exists():
48
+ model_path = Path(__file__).resolve().parent / (args.name + ".onnx")
49
+ session = ort.InferenceSession(str(model_path), opts, providers=["CPUExecutionProvider"])
50
+ totals = defaultdict(float)
51
+ returns = []
52
+ soccer = args.name == "SoccerTwos"
53
+ env = UnityEnvironment(file_name=args.env, seed=args.seed, base_port=args.port,
54
+ no_graphics=True, side_channels=[engine],
55
+ additional_args=["-job-worker-count", "1"])
56
+ try:
57
+ env.reset()
58
+ for _ in range(100000):
59
+ for behavior, spec in env.behavior_specs.items():
60
+ decisions, terminals = env.get_steps(behavior)
61
+ if soccer and behavior.endswith("team=1"):
62
+ if len(decisions):
63
+ env.set_actions(behavior, spec.action_spec.random_action(len(decisions)))
64
+ continue
65
+ for steps, ended in ((terminals, True), (decisions, False)):
66
+ ids = steps.group_id if soccer else steps.agent_id
67
+ seen = set()
68
+ for row, uid in enumerate(ids):
69
+ if uid in seen:
70
+ continue
71
+ seen.add(uid)
72
+ reward = steps.group_reward[row] if soccer else steps.reward[row]
73
+ totals[uid] += float(reward)
74
+ if ended:
75
+ returns.append(totals.pop(uid))
76
+ if len(decisions):
77
+ env.set_actions(behavior, policy_actions(session, decisions, spec.action_spec))
78
+ if len(returns) >= args.episodes:
79
+ break
80
+ env.step()
81
+ else:
82
+ raise RuntimeError("Evaluation exhausted the simulation-step limit")
83
+ finally:
84
+ env.close()
85
+ returns = returns[:args.episodes]
86
+ report = dict(environment=args.name, seed=args.seed, episodes=len(returns),
87
+ stochastic_policy=True, mean=float(np.mean(returns)),
88
+ std=float(np.std(returns)), returns=returns)
89
+ if soccer:
90
+ report.update(opponent="uniform random actions", evaluated_team=0,
91
+ metric="per-match shared team return")
92
+ print(json.dumps(report))
93
+ (model_path.parent / "evaluation.json").write_text(json.dumps(report, indent=2) + "\n")
94
+
95
+
96
+ if __name__ == "__main__":
97
+ parser = argparse.ArgumentParser()
98
+ parser.add_argument("name")
99
+ parser.add_argument("env")
100
+ parser.add_argument("port", type=int)
101
+ parser.add_argument("--episodes", type=int, default=32)
102
+ parser.add_argument("--seed", type=int, default=2026)
103
+ evaluate(parser.parse_args())
evaluation.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "environment": "Pyramids",
3
+ "seed": 2026,
4
+ "episodes": 32,
5
+ "stochastic_policy": true,
6
+ "mean": -0.9999999310821295,
7
+ "std": 0.0,
8
+ "returns": [
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
+ ]
42
+ }
run_logs/training_status.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "Pyramids": {
3
+ "checkpoints": [
4
+ {
5
+ "steps": 65841,
6
+ "file_path": "results/Pyramids/Pyramids/Pyramids-65841.onnx",
7
+ "reward": null,
8
+ "creation_time": 1796028760.570879,
9
+ "auxillary_file_paths": [
10
+ "results/Pyramids/Pyramids/Pyramids-65841.pt"
11
+ ]
12
+ }
13
+ ],
14
+ "final_checkpoint": {
15
+ "steps": 65841,
16
+ "file_path": "results/Pyramids/Pyramids.onnx",
17
+ "reward": null,
18
+ "creation_time": 1796028760.570879,
19
+ "auxillary_file_paths": [
20
+ "results/Pyramids/Pyramids/Pyramids-65841.pt"
21
+ ]
22
+ }
23
+ },
24
+ "metadata": {
25
+ "stats_format_version": "0.3.0",
26
+ "mlagents_version": "1.1.0",
27
+ "torch_version": "2.2.2+cpu"
28
+ }
29
+ }