Reinforcement Learning
ml-agents
TensorBoard
ONNX
deep-reinforcement-learning
deep-rl-course
Pyramids
ML-Agents-Pyramids
Eval Results (legacy)
Instructions to use rabitrabi/ppo-Pyramids with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ml-agents
How to use rabitrabi/ppo-Pyramids with ml-agents:
mlagents-load-from-hf --repo-id="rabitrabi/ppo-Pyramids" --local-dir="./downloads"
- Notebooks
- Google Colab
- Kaggle
Publish trained Pyramids policy and 32-episode evaluation
Browse filesFiles changed (12)
- Pyramids.onnxAdded+3
- Pyramids.yamlAdded+32
- Pyramids/Pyramids-65841.onnxAdded+3
- Pyramids/Pyramids-65841.ptAdded+3
- Pyramids/checkpoint.ptAdded+3
- Pyramids/events.out.tfevents.1796028590.rabia-LOQ-15IAX9E.3405341.0Added+3
- README.mdAdded+41
- config.jsonAdded+110
- configuration.yamlAdded+94
- evaluate.pyAdded+103
- evaluation.jsonAdded+42
- run_logs/training_status.jsonAdded+29
123version https://git-lfs.github.com/spec/v1oid sha256:ba413627b4227b53be5539aee25d049d50a9c58d022c350f3a2b399309c24e5dsize 1622541234567891011121314151617181920212223242526272829303132behaviors: Pyramids: trainer_type: ppo hyperparameters: batch_size: 128 buffer_size: 2048 learning_rate: 0.0003 beta: 0.01 epsilon: 0.2 lambd: 0.95 num_epoch: 3 learning_rate_schedule: linear network_settings: normalize: false hidden_units: 128 num_layers: 2 vis_encode_type: simple reward_signals: extrinsic: gamma: 0.99 strength: 1.0 rnd: gamma: 0.99 strength: 0.01 network_settings: hidden_units: 64 num_layers: 3 learning_rate: 0.0001 keep_checkpoints: 5 max_steps: 65536 time_horizon: 128 summary_freq: 4096123version https://git-lfs.github.com/spec/v1oid sha256:ba413627b4227b53be5539aee25d049d50a9c58d022c350f3a2b399309c24e5dsize 162254123version https://git-lfs.github.com/spec/v1oid sha256:a802e8dba7e6791fb16a118c1263977b9230033923ffc9fff448455e8976e25dsize 1120862123version https://git-lfs.github.com/spec/v1oid sha256:cd883b592da0ab635415bc46b03c340ba6ede5201c97db69ebb199493fc71e9csize 1120546123version https://git-lfs.github.com/spec/v1oid sha256:1b4326e6acff15baf687f1a177e79f374aed845b4df5f7aad53cb1977cb96821size 306681234567891011121314151617181920212223242526272829303132333435363738394041---library_name: ml-agentstags:- reinforcement-learning- deep-reinforcement-learning- deep-rl-course- ml-agents- Pyramids- ML-Agents-Pyramids- onnxmodel-index:- name: PPO Pyramids results: - task: type: reinforcement-learning name: Reinforcement Learning dataset: type: Pyramids name: Pyramids metrics: - type: mean_reward name: Mean reward value: -1.000000 +/- 0.000000---
# PPO on Pyramids
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.
## Evaluation
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`.
## Reproduce
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).
```bashmlagents-learn Pyramids.yaml --env=/path/to/Pyramids --run-id=Pyramids --no-graphics --seed=42 --time-scale=64 --torch-device=cpupython evaluate.py Pyramids /path/to/Pyramids 6360 --seed=2026 --episodes=32```123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110{ "default_settings": null, "behaviors": { "Pyramids": { "trainer_type": "ppo", "hyperparameters": { "batch_size": 128, "buffer_size": 2048, "learning_rate": 0.0003, "beta": 0.01, "epsilon": 0.2, "lambd": 0.95, "num_epoch": 3, "shared_critic": false, "learning_rate_schedule": "linear", "beta_schedule": "linear", "epsilon_schedule": "linear" }, "checkpoint_interval": 500000, "network_settings": { "normalize": false, "hidden_units": 128, "num_layers": 2, "vis_encode_type": "simple", "memory": null, "goal_conditioning_type": "hyper", "deterministic": false }, "reward_signals": { "extrinsic": { "gamma": 0.99, "strength": 1.0, "network_settings": { "normalize": false, "hidden_units": 128, "num_layers": 2, "vis_encode_type": "simple", "memory": null, "goal_conditioning_type": "hyper", "deterministic": false } }, "rnd": { "gamma": 0.99, "strength": 0.01, "network_settings": { "normalize": false, "hidden_units": 64, "num_layers": 3, "vis_encode_type": "simple", "memory": null, "goal_conditioning_type": "hyper", "deterministic": false }, "learning_rate": 0.0001, "encoding_size": null } }, "init_path": null, "keep_checkpoints": 5, "even_checkpoints": false, "max_steps": 65536, "time_horizon": 128, "summary_freq": 4096, "threaded": false, "self_play": null, "behavioral_cloning": null } }, "env_settings": { "env_path": "envs/Pyramids/Pyramids", "env_args": [ "-job-worker-count", "1" ], "base_port": 6330, "num_envs": 1, "num_areas": 1, "timeout_wait": 60, "seed": 42, "max_lifetime_restarts": 10, "restarts_rate_limit_n": 1, "restarts_rate_limit_period_s": 60 }, "engine_settings": { "width": 84, "height": 84, "quality_level": 5, "time_scale": 64.0, "target_frame_rate": -1, "capture_frame_rate": 60, "no_graphics": true, "no_graphics_monitor": false }, "environment_parameters": null, "checkpoint_settings": { "run_id": "Pyramids", "initialize_from": null, "load_model": false, "resume": false, "force": false, "train_model": false, "inference": false, "results_dir": "results" }, "torch_settings": { "device": "cpu" }, "debug": false}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394default_settings: nullbehaviors: Pyramids: trainer_type: ppo hyperparameters: batch_size: 128 buffer_size: 2048 learning_rate: 0.0003 beta: 0.01 epsilon: 0.2 lambd: 0.95 num_epoch: 3 shared_critic: false learning_rate_schedule: linear beta_schedule: linear epsilon_schedule: linear checkpoint_interval: 500000 network_settings: normalize: false hidden_units: 128 num_layers: 2 vis_encode_type: simple memory: null goal_conditioning_type: hyper deterministic: false reward_signals: extrinsic: gamma: 0.99 strength: 1.0 network_settings: normalize: false hidden_units: 128 num_layers: 2 vis_encode_type: simple memory: null goal_conditioning_type: hyper deterministic: false rnd: gamma: 0.99 strength: 0.01 network_settings: normalize: false hidden_units: 64 num_layers: 3 vis_encode_type: simple memory: null goal_conditioning_type: hyper deterministic: false learning_rate: 0.0001 encoding_size: null init_path: null keep_checkpoints: 5 even_checkpoints: false max_steps: 65536 time_horizon: 128 summary_freq: 4096 threaded: false self_play: null behavioral_cloning: nullenv_settings: env_path: envs/Pyramids/Pyramids env_args: - -job-worker-count - '1' base_port: 6330 num_envs: 1 num_areas: 1 timeout_wait: 60 seed: 42 max_lifetime_restarts: 10 restarts_rate_limit_n: 1 restarts_rate_limit_period_s: 60engine_settings: width: 84 height: 84 quality_level: 5 time_scale: 64.0 target_frame_rate: -1 capture_frame_rate: 60 no_graphics: true no_graphics_monitor: falseenvironment_parameters: nullcheckpoint_settings: run_id: Pyramids initialize_from: null load_model: false resume: false force: false train_model: false inference: false results_dir: resultstorch_settings: device: cpudebug: false123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103"""Evaluate the exported ML-Agents policy in the original headless Unity build."""import argparsefrom collections import defaultdictimport jsonfrom pathlib import Path
import numpy as npimport onnxruntime as ortfrom mlagents_envs.base_env import ActionTuplefrom mlagents_envs.environment import UnityEnvironmentfrom mlagents_envs.side_channel.engine_configuration_channel import EngineConfigurationChannel
def policy_actions(session, decisions, spec): batch = len(decisions) inputs = {} for inp in session.get_inputs(): if inp.name.startswith("obs_"): inputs[inp.name] = decisions.obs[int(inp.name[4:])] elif inp.name == "action_masks": if decisions.action_mask is None: mask = np.ones((batch, sum(spec.discrete_branches)), np.float32) else: mask = 1 - np.concatenate(decisions.action_mask, axis=1).astype(np.float32) inputs[inp.name] = mask else: raise ValueError(inp.name) actions = ActionTuple() for name, setter in ( ("continuous_actions", actions.add_continuous), ("discrete_actions", actions.add_discrete), ): if name in {out.name for out in session.get_outputs()}: setter(session.run([name], inputs)[0]) return actions
def evaluate(args): engine = EngineConfigurationChannel() engine.set_configuration_parameters(time_scale=64.0) ort.set_seed(args.seed) np.random.seed(args.seed) opts = ort.SessionOptions() opts.intra_op_num_threads = 1 opts.inter_op_num_threads = 1 model_path = Path("results") / args.name / (args.name + ".onnx") if not model_path.exists(): model_path = Path(__file__).resolve().parent / (args.name + ".onnx") session = ort.InferenceSession(str(model_path), opts, providers=["CPUExecutionProvider"]) totals = defaultdict(float) returns = [] soccer = args.name == "SoccerTwos" env = UnityEnvironment(file_name=args.env, seed=args.seed, base_port=args.port, no_graphics=True, side_channels=[engine], additional_args=["-job-worker-count", "1"]) try: env.reset() for _ in range(100000): for behavior, spec in env.behavior_specs.items(): decisions, terminals = env.get_steps(behavior) if soccer and behavior.endswith("team=1"): if len(decisions): env.set_actions(behavior, spec.action_spec.random_action(len(decisions))) continue for steps, ended in ((terminals, True), (decisions, False)): ids = steps.group_id if soccer else steps.agent_id seen = set() for row, uid in enumerate(ids): if uid in seen: continue seen.add(uid) reward = steps.group_reward[row] if soccer else steps.reward[row] totals[uid] += float(reward) if ended: returns.append(totals.pop(uid)) if len(decisions): env.set_actions(behavior, policy_actions(session, decisions, spec.action_spec)) if len(returns) >= args.episodes: break env.step() else: raise RuntimeError("Evaluation exhausted the simulation-step limit") finally: env.close() returns = returns[:args.episodes] report = dict(environment=args.name, seed=args.seed, episodes=len(returns), stochastic_policy=True, mean=float(np.mean(returns)), std=float(np.std(returns)), returns=returns) if soccer: report.update(opponent="uniform random actions", evaluated_team=0, metric="per-match shared team return") print(json.dumps(report)) (model_path.parent / "evaluation.json").write_text(json.dumps(report, indent=2) + "\n")
if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("name") parser.add_argument("env") parser.add_argument("port", type=int) parser.add_argument("--episodes", type=int, default=32) parser.add_argument("--seed", type=int, default=2026) evaluate(parser.parse_args())123456789101112131415161718192021222324252627282930313233343536373839404142{ "environment": "Pyramids", "seed": 2026, "episodes": 32, "stochastic_policy": true, "mean": -0.9999999310821295, "std": 0.0, "returns": [ -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295, -0.9999999310821295 ]}1234567891011121314151617181920212223242526272829{ "Pyramids": { "checkpoints": [ { "steps": 65841, "file_path": "results/Pyramids/Pyramids/Pyramids-65841.onnx", "reward": null, "creation_time": 1796028760.570879, "auxillary_file_paths": [ "results/Pyramids/Pyramids/Pyramids-65841.pt" ] } ], "final_checkpoint": { "steps": 65841, "file_path": "results/Pyramids/Pyramids.onnx", "reward": null, "creation_time": 1796028760.570879, "auxillary_file_paths": [ "results/Pyramids/Pyramids/Pyramids-65841.pt" ] } }, "metadata": { "stats_format_version": "0.3.0", "mlagents_version": "1.1.0", "torch_version": "2.2.2+cpu" }}Pyramids.onnxAdded+3
Pyramids.yamlAdded+32
Pyramids/Pyramids-65841.onnxAdded+3
Pyramids/Pyramids-65841.ptAdded+3
Pyramids/checkpoint.ptAdded+3
Pyramids/events.out.tfevents.1796028590.rabia-LOQ-15IAX9E.3405341.0Added+3
README.mdAdded+41
config.jsonAdded+110
configuration.yamlAdded+94
evaluate.pyAdded+103
evaluation.jsonAdded+42
run_logs/training_status.jsonAdded+29