w
gcw_uQ09W7jl/Tunamelon-ppo-LunarLander-v2-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Tunamelon/ppo-LunarLander-v2 on Ascend NPU #NPU

Model Introduction

Model Name: Tunamelon/ppo-LunarLander-v2
Revision: f0b8ee438f823e7bbadf44d71821cd5c7257a4c1 (ppo-LunarLander-v2.zip 105KB, policy.pth 92KB)
Model Weight URL: https://huggingface.co/Tunamelon/ppo-LunarLander-v2
Model Type: Reinforcement Learning (PPO, ActorCriticPolicy)
Task Type: reinforcement-learning / offline-rl (vector observation → discrete action)
Architecture Family: MLP Policy (Tanh 64×2 + discrete action head)
Pipeline Tag: reinforcement-learning
Weights: ppo-LunarLander-v2.zip (105 KB zip: data, policy.pth 92KB, pytorch_variables, policy.optimizer) + ppo-LunarLander-v2/policy.pth (92KB) – upstream repo contains PPO_70/75/84/89/90 variants
License: Unknown (check upstream README)

PPO agent trained on Gymnasium LunarLander-v2 (Box(8) obs, Discrete(4) action) with Stable-Baselines3 2.0.0a5, 5M timesteps, Tanh MLP 64×2, gamma 0.999, gae_lambda 0.98, lr 3e-4. Input is 8-dim lunar state (x, y, vx, vy, angle, angular_vel, leg1_contact, leg2_contact) but checkpoint's pi_features_extractor expects 9 dims (legacy SB3 architecture with separate pi/vf extractors, weight shape [64,9]). This adaptation auto-detects has_pi and handles both 9-dim legacy and 8-dim modern checkpoints. Output is discrete logits [B,4] → softmax probs → argmax action 0: do nothing, 1: fire left engine, 2: fire main engine, 3: fire right engine.

Data Contract

FieldValue
Input Formatobs [batch, obs_dim] float32, vector observation
Axis Order[B, OBS_DIM] – MLP input
Observation Dim9 (legacy checkpoint, [64,9] weight) detected; also supports 8 for PPO_70 variant
Observation Boundsx ∈ [-1.5,1.5], y ∈ [0,1.5], vx/vy ∈ [-1,1], angle ∈ [-π,π], angular_vel ∈ [-2,2], contacts ∈ {0,1} – synthetic uses N(0,0.5)+0.1*b clipped
Action Dim4 discrete (logits [B,4], probs softmax, action argmax)
Horizon / Chunk1 (single-step policy; no action chunk, no diffusion)
Hidden LayersLegacy: pi_features 9→64→64 Tanh, then policy_net 64→64→64 Tanh; modern: policy_net 8→64→64 Tanh
Action HeadLinear(64→4) logits, no log_std (discrete)
Dtypefloat32 (weights fp32, compute fp32)
Batch (demo)4 (tested also 1 and 16)
PreprocessingNone (raw obs directly to Linear, Tanh); synthetic deterministic N(0,0.5)+0.1*b seed 42, contacts binarized
Data SourceSynthetic deterministic (no Gym env required for forward), reproducible seed 42; also validated against _last_obs shape (8,8) from training
Outputlogits [B,4] float32 + action [B] int64 discrete 0-3 – both finite, shape verified

No Gym environment needed for forward; policy quality _last_obs shown but not used for reward.

Environment

  • Python 3.11.14
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04
  • huggingface_hub 0.36.2, numpy 1.26.4, gymnasium 0.28.1, stable-baselines3 2.x, cloudpickle
  • Ascend CANN 8.5.1, torch.npu.is_available()==True, device Ascend910_9362, device_count 2, target npu:0
  • Validated with npu-smi info and scripts/check_npu.py

Installation

pip install -r requirements.txt

Model weights: auto-loaded from /opt/atomgit/adapt-npu-agent/working/models/Tunamelon-ppo-LunarLander-v2 if present, else from https://huggingface.co/Tunamelon/ppo-LunarLander-v2 via hf_hub_download (requires HF_ENDPOINT mirror if needed). Needs ppo-LunarLander-v2.zip (105KB) or ppo-LunarLander-v2/policy.pth (92KB).

NPU Inference

Default command (runs synthetic demo with NPU):

python inference.py

Expected output includes:

  • model_name, revision, PPO LunarLander-v2, route offline-rl, arch MLP Tanh 64x2
  • config: num_timesteps 5013504 n_steps 2048 gamma 0.999
  • obs shape [4,9], sample values, stats
  • CPU baseline logits shape [4,4], sample, finite, probs
  • first_param device: npu:0, input device: npu:0, NPU logits shape: [4,4] device: npu:0
  • first run (compile) time with torch.npu.synchronize() and second run time
  • Benchmark avg/min/max/p50/p90/p95 and throughput
  • Consistency max_abs, allclose, discrete action match
  • Final state: SUCCESS

Supports different batch sizes (1, 16 validated).

Real Results (Verified NPU)

Run: python inference.py (batch=4, obs_dim=9, act_dim=4 discrete, float32, npu:0)

Input:

  • obs [4,9], sample [0.9634,0.7436,0.4503,-1.0527] contacts [0.0,0.0], mean 0.1472 std 0.5170

Output:

  • CPU logits [4,4], sample [-0.00389,-0.00692,0.00400,0.00610] probs [0.2490,0.2483,0.2510,0.2515] actions [3,0,2,2]
  • NPU logits [4,4], sample [-0.00389,-0.00692,0.00400,0.00610] (max_abs 5.58e-09) actions [3,0,2,2] exact match
  • finite True, probs sum 1.0

Timing (npu:0, synchronized):

  • First run (compile): 139.45 ms
  • Second run: 0.31 ms
  • Stable avg: 0.19 ms (warmup 3, test 10)
  • Throughput: 21037 decisions/s (4 obs), 21037 actions? discrete batch 4
  • Memory: allocated 0.1 MB, reserved 36.0 MB

No CPU fallback; all tensors on npu:0, model buffers on npu:0.

Consistency Verification

Saved CPU/NPU logits to .npy + .json and compared:

python .opencode/skills/npu_adapt_robotics/scripts/validate_policy_outputs.py --cpu /tmp/cpu_tunamelon.json --npu /tmp/npu_tunamelon.json --atol 1e-4 --rtol 1e-3

Result: count 16 passed True finite True max_abs 5.58e-09 mean_abs 1.58e-09 tolerance 0.000109 (fp32 atol=1e-4). Shape [4,4] verified, bounds not exceeded, allclose True, discrete actions identical. Differences due to NPU fused ops but well within tolerance.

Benchmark also via benchmark_policy.py with latencies list: avg 0.19 ms p50 0.19 p90 0.20.

Performance

Warmup 3, test 10, synchronized:

  • compile/first_run 139.45 ms, avg 0.19 ms, min 0.18 ms, max 0.21 ms, p50 0.19 ms, p90 0.20 ms, p95 0.21 ms
  • batch=4, horizon=1, act_dim=4 discrete, dtype float32, device npu:0
  • throughput 21037 decisions/s
  • peak NPU memory 0.1 MB allocated, 36 MB reserved
  • preprocessing (synthetic generation) not included; timed region is LunarActor.forward only

Additional: batch 1 latency 0.53 ms shape [1,4]; batch 16 latency 0.49 ms shape [16,4] correct.

Evidence

Three PNGs generated by xterm.js from real logs (render_xterm_evidence.mjs --style raw):

  • assets/agent_workflow.png – workflow (inspect, download, NPU check, inference, compare, benchmark, validation)
  • assets/npu_device_call.png – npu-smi + torch.npu availability + model param device + input/output device
  • assets/model_result.png – full python inference.py output

Images are rendered from actual terminal logs, not screenshots, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$ is display label only.

agent workflow npu device call model result

Limitations

  • Vector obs only; checkpoint legacy expects 9 dims vs env 8 dims – auto-detected and handled via synthetic 9-dim generation (extra dim padded with realistic contact logic). PPO_70 variant with 8 dims also supported if present.
  • Discrete action only (4 logits); deterministic argmax reported, stochastic sampling not exercised.
  • No Gym closed-loop rollout; forward only. Reward/success metrics not applicable per skill rule 6.
  • FP32 only; FP16/BF16 not tested.
  • Weights not included in repo (download from HuggingFace); single zip ppo-LunarLander-v2.zip demonstrated, other variants (PPO_70 etc) share similar arch and expected similar NPU behavior but not all tested.
  • Tanh activation used per SB3 default; ReLU not applicable.