rabitrabi commited on
Commit
04929e0
·
verified ·
1 Parent(s): e0d37cf

Publish trained SnowballTarget policy and 32-episode evaluation

Browse files
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
+ - SnowballTarget
9
+ - ML-Agents-SnowballTarget
10
+ - onnx
11
+ model-index:
12
+ - name: PPO SnowballTarget
13
+ results:
14
+ - task:
15
+ type: reinforcement-learning
16
+ name: Reinforcement Learning
17
+ dataset:
18
+ type: SnowballTarget
19
+ name: SnowballTarget
20
+ metrics:
21
+ - type: mean_reward
22
+ name: Mean reward
23
+ value: 12.093750 +/- 2.376439
24
+ ---
25
+
26
+ # PPO on SnowballTarget
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 **12.094** and the population standard deviation was **2.376**. Each return sums the individual environment rewards for one complete episode. 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 SnowballTarget.yaml --env=/path/to/SnowballTarget --run-id=SnowballTarget --no-graphics --seed=42 --time-scale=64 --torch-device=cpu
40
+ python evaluate.py SnowballTarget /path/to/SnowballTarget 6360 --seed=2026 --episodes=32
41
+ ```
SnowballTarget.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:915d72a86a85df74b859cc0ef882c3f40f325516946613590494f87c7d3483b5
3
+ size 264598
SnowballTarget.yaml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ behaviors:
2
+ SnowballTarget:
3
+ trainer_type: ppo
4
+ max_steps: 65536
5
+ summary_freq: 4096
6
+ time_horizon: 64
7
+ hyperparameters:
8
+ batch_size: 128
9
+ buffer_size: 2048
10
+ learning_rate: 0.0003
11
+ beta: 0.005
12
+ epsilon: 0.2
13
+ lambd: 0.95
14
+ num_epoch: 3
15
+ network_settings:
16
+ hidden_units: 128
17
+ num_layers: 2
18
+ reward_signals:
19
+ extrinsic:
20
+ gamma: 0.99
21
+ strength: 1.0
SnowballTarget/SnowballTarget-65912.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:915d72a86a85df74b859cc0ef882c3f40f325516946613590494f87c7d3483b5
3
+ size 264598
SnowballTarget/SnowballTarget-65912.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:108fff796c4de7b2880b3952784ea0089eacb4fcedc2fa0278f6538c5856e976
3
+ size 1543440
SnowballTarget/checkpoint.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bff122d4ae58c67c5b73dc59b240cc8ba95e1732039c2103f9900c16f459a16b
3
+ size 1542626
SnowballTarget/events.out.tfevents.1796028590.rabia-LOQ-15IAX9E.3405402.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:928f72f825399a088ee3dc1258e3923370140b8303e1eea89211d5ce6d857bda
3
+ size 30443
config.json ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "default_settings": null,
3
+ "behaviors": {
4
+ "SnowballTarget": {
5
+ "trainer_type": "ppo",
6
+ "hyperparameters": {
7
+ "batch_size": 128,
8
+ "buffer_size": 2048,
9
+ "learning_rate": 0.0003,
10
+ "beta": 0.005,
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
+ },
44
+ "init_path": null,
45
+ "keep_checkpoints": 5,
46
+ "even_checkpoints": false,
47
+ "max_steps": 65536,
48
+ "time_horizon": 64,
49
+ "summary_freq": 4096,
50
+ "threaded": false,
51
+ "self_play": null,
52
+ "behavioral_cloning": null
53
+ }
54
+ },
55
+ "env_settings": {
56
+ "env_path": "envs/SnowballTarget/SnowballTarget.x86_64",
57
+ "env_args": [
58
+ "-job-worker-count",
59
+ "1"
60
+ ],
61
+ "base_port": 6310,
62
+ "num_envs": 1,
63
+ "num_areas": 1,
64
+ "timeout_wait": 60,
65
+ "seed": 42,
66
+ "max_lifetime_restarts": 10,
67
+ "restarts_rate_limit_n": 1,
68
+ "restarts_rate_limit_period_s": 60
69
+ },
70
+ "engine_settings": {
71
+ "width": 84,
72
+ "height": 84,
73
+ "quality_level": 5,
74
+ "time_scale": 64.0,
75
+ "target_frame_rate": -1,
76
+ "capture_frame_rate": 60,
77
+ "no_graphics": true,
78
+ "no_graphics_monitor": false
79
+ },
80
+ "environment_parameters": null,
81
+ "checkpoint_settings": {
82
+ "run_id": "SnowballTarget",
83
+ "initialize_from": null,
84
+ "load_model": false,
85
+ "resume": false,
86
+ "force": false,
87
+ "train_model": false,
88
+ "inference": false,
89
+ "results_dir": "results"
90
+ },
91
+ "torch_settings": {
92
+ "device": "cpu"
93
+ },
94
+ "debug": false
95
+ }
configuration.yaml ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ default_settings: null
2
+ behaviors:
3
+ SnowballTarget:
4
+ trainer_type: ppo
5
+ hyperparameters:
6
+ batch_size: 128
7
+ buffer_size: 2048
8
+ learning_rate: 0.0003
9
+ beta: 0.005
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
+ init_path: null
39
+ keep_checkpoints: 5
40
+ even_checkpoints: false
41
+ max_steps: 65536
42
+ time_horizon: 64
43
+ summary_freq: 4096
44
+ threaded: false
45
+ self_play: null
46
+ behavioral_cloning: null
47
+ env_settings:
48
+ env_path: envs/SnowballTarget/SnowballTarget.x86_64
49
+ env_args:
50
+ - -job-worker-count
51
+ - '1'
52
+ base_port: 6310
53
+ num_envs: 1
54
+ num_areas: 1
55
+ timeout_wait: 60
56
+ seed: 42
57
+ max_lifetime_restarts: 10
58
+ restarts_rate_limit_n: 1
59
+ restarts_rate_limit_period_s: 60
60
+ engine_settings:
61
+ width: 84
62
+ height: 84
63
+ quality_level: 5
64
+ time_scale: 64.0
65
+ target_frame_rate: -1
66
+ capture_frame_rate: 60
67
+ no_graphics: true
68
+ no_graphics_monitor: false
69
+ environment_parameters: null
70
+ checkpoint_settings:
71
+ run_id: SnowballTarget
72
+ initialize_from: null
73
+ load_model: false
74
+ resume: false
75
+ force: false
76
+ train_model: false
77
+ inference: false
78
+ results_dir: results
79
+ torch_settings:
80
+ device: cpu
81
+ 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": "SnowballTarget",
3
+ "seed": 2026,
4
+ "episodes": 32,
5
+ "stochastic_policy": true,
6
+ "mean": 12.09375,
7
+ "std": 2.3764387089718935,
8
+ "returns": [
9
+ 13.0,
10
+ 12.0,
11
+ 10.0,
12
+ 14.0,
13
+ 12.0,
14
+ 7.0,
15
+ 15.0,
16
+ 15.0,
17
+ 14.0,
18
+ 7.0,
19
+ 11.0,
20
+ 16.0,
21
+ 14.0,
22
+ 13.0,
23
+ 11.0,
24
+ 14.0,
25
+ 11.0,
26
+ 16.0,
27
+ 9.0,
28
+ 13.0,
29
+ 9.0,
30
+ 12.0,
31
+ 15.0,
32
+ 10.0,
33
+ 12.0,
34
+ 13.0,
35
+ 11.0,
36
+ 12.0,
37
+ 13.0,
38
+ 8.0,
39
+ 11.0,
40
+ 14.0
41
+ ]
42
+ }
run_logs/training_status.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "SnowballTarget": {
3
+ "checkpoints": [
4
+ {
5
+ "steps": 65912,
6
+ "file_path": "results/SnowballTarget/SnowballTarget/SnowballTarget-65912.onnx",
7
+ "reward": 12.272727272727273,
8
+ "creation_time": 1796028776.0526834,
9
+ "auxillary_file_paths": [
10
+ "results/SnowballTarget/SnowballTarget/SnowballTarget-65912.pt"
11
+ ]
12
+ }
13
+ ],
14
+ "final_checkpoint": {
15
+ "steps": 65912,
16
+ "file_path": "results/SnowballTarget/SnowballTarget.onnx",
17
+ "reward": 12.272727272727273,
18
+ "creation_time": 1796028776.0526834,
19
+ "auxillary_file_paths": [
20
+ "results/SnowballTarget/SnowballTarget/SnowballTarget-65912.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
+ }