waylong/sb3-dqn-LunarLander-v2-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

sb3/dqn-LunarLander-v2 on Ascend NPU

Model: sb3/dqn-LunarLander-v2 (https://huggingface.co/sb3/dqn-LunarLander-v2)
Revision: 3f631509a3a70816ba982661e79a1f25f2e617bb
Route: discrete-rl (DQN extends offline-rl) — state (8-dim) → Q-values (4) → discrete action
Task: LunarLander-v2 discrete control (4 actions: noop, left engine, main engine, right engine)
Backend: stable_baselines3 2.9.0 + torch 2.9.0+cpu + torch_npu on Ascend910_9362 (npu:0)
DType: float32 (FP32)

Model Description

DQN agent trained with stable-baselines3 RL Zoo on LunarLander-v2. Architecture: MlpPolicy with net_arch=[256,256] → Linear(8→256) → ReLU → Linear(256→256) → ReLU → Linear(256→4). Input is LunarLander observation Box(8,) : [x, y, vx, vy, angle, ang_vel, leg_contact1, leg_contact2]. Output is Q-values for 4 discrete actions; greedy action = argmax(Q). This adaptation maps to offline-rl family (Decision Transformer contractor: state/action/RTG) but with discrete Q-learning; validated as continuous Q-value tensor rather than environment reward.

Observation & Action Contract

  • Observation: Box(-inf, inf, (8,), float32) lunar lander state, normalized none, dtype float32.
  • Action: Discrete(4) predicted via Q-network; validated object is Q-value tensor [1,4] and derived greedy action. horizon=1, action_dim=4, coordinate_frame=discrete.
  • Sampling: deterministic argmax, no stochastic sampler; seed fixed for observation generation.
  • Weights: not submitted; inference.py loads from https://huggingface.co/sb3/dqn-LunarLander-v2 via huggingface_hub snapshot_download + DQN.load(..., map_location='cpu') then policy.to(npu:0).

Reproducible Commands

pip install -r requirements.txt
python inference.py

Default run prints model/revision/route/backend/device/dtype, input summary, Q-values, action, synchronized latency, CPU-NPU consistency and PASS/FAIL. All floating tensors and outputs are explicitly on npu:0.

Real Results (Ascend910_9362, npu:0, single card)

Fixed observation obs=[0.0, 1.0, 0.0, -0.5, 0.1, 0.2, 0.0, 0.0] (float32, shape [1,8], device npu:0):

  • CPU Q-values: [85.373619, 84.597313, 86.116455, 86.668724] device cpu
  • NPU Q-values: [85.373611, 84.597328, 86.116440, 86.668724] device npu:0
  • Action: 3 (fire right engine) both CPU and NPU — horizon 1, action_dim 4
  • Consistency: max_abs=1.526e-05 MAE=9.537e-06 tolerance=8.677e-02 (atol=1e-4 rtol=1e-3) PASS, shape [1,4], finite True
  • Additional tests (5 diverse obs): all PASS max_abs ≤3.05e-05, actions [3,3,3,1,3] match CPU/NPU via validate_policy_outputs.py

Performance (synchronized torch.npu.synchronize() before/after, warmup 3 + 10 measured):

  • First compiled inference after warmup: ~123 ms (includes graph compile), steady-state ~0.15-0.17 ms
  • Stable avg 0.158 ms, min 0.152 ms, max 0.187 ms, p50 0.155 ms, p90 0.158 ms, p95 0.187 ms
  • Throughput: ~6347 decisions/s (batch=1, horizon=1, action_dim=4, float32)
  • benchmark_policy.py --items-per-call 1 --unit decisions confirms decisions_per_s above.

Device proof (see assets/npu_device_call.png):

  • torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362
  • policy first param device npu:0, q_net target param npu:0, input tensor npu:0, output tensor npu:0, sampler none.

Environment Limitations

  • Requires Ascend 910B with CANN 8.5.1, torch_npu, stable_baselines3>=2.9.0, gym==0.26.2, shimmy>=0.2.1 (for Gym→Gymnasium shim).
  • FP32 only; FP16 not tested (Q-values small error margin would need loosened atol).
  • Single-card npu:0 only; multi-card not evaluated. Memory <100 MB peak.

Evidence

  • agent workflow
  • npu device call
  • model result

All PNGs are rendered from real terminal logs via render_xterm_evidence.mjs --style raw with SHA256 verification.

Files

  • inference.py — default python inference.py loads from HF cache, runs NPU inference, validates CPU/NPU, benchmarks.
  • requirements.txt — pinned dependencies.
  • assets/ — three xterm evidence images.

Model weights URL: https://huggingface.co/sb3/dqn-LunarLander-v2