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

sb3/dqn-LunarLander-v2 — Ascend NPU Adaptation (DQN LunarLander-v2)

Model Task & Contracts

Source: sb3/dqn-LunarLander-v2 from HuggingFace, revision 3f631509a3a70816ba982661e79a1f25f2e617bb
Original Paper/Framework: Stable-Baselines3 DQN with MlpPolicy(net_arch=[256,256]) trained on LunarLander-v2.
Task: Discrete reinforcement-learning policy — LunarLander control.
Observation contract: Box(-inf, inf, (8,), float32) — 8-dim continuous state [x, y, vx, vy, angle, angular_vel, leg_contact_1, leg_contact_2].
Action contract: Discrete(4) — 0:do nothing, 1:fire left engine, 2:fire main engine, 3:fire right engine. Single decision horizon = 1.
Output contract for validation: Q-values tensor shape (1,4) dtype float32 on device npu:0 or cpu, and argmax discrete action 0-3 (deterministic, deterministic=True). Raw logits are compared, not environment reward.
Loading backend: torch with manual QNet reconstruction (SB3 MlpPolicy MLP) + torch_npu for NPU, weights from dqn-LunarLander-v2/policy.pth (545 KB, 276496 bytes param). No trust_remote_code, no custom remote code.
Route mapped to skill: offline-rl (DQN variant mapped to decision-style single-action policy; single-step action plan analogous to DT's last-position action).

Model Provenance

  • Base model: sb3/dqn-LunarLander-v2 (stable-baselines3 1.5.1, PyTorch 1.11, Gym 0.21 training). Downloaded via snapshot_download(repo_id="sb3/dqn-LunarLander-v2") respecting HF_ENDPOINT=https://hf-mirror.com (no manual proxy override).
  • Weight filtering: Only q_net.q_net.{0,2,4}.* (Q-network) used for inference; target network weights (q_net_target) preserved in checkpoint but not needed for forward policy.
  • No weight modification: No quantization, pruning, or architecture change; full 256×256 MLP kept intact (resource fits single Ascend910 64GB HBM).
  • No substitution: Single model verified; no dummy policy; CPU fallback is failure.

True Results (npu:0)

Executed on Ascend910_9362, torch_npu 2.9.0.post1, torch 2.9.0+cpu, npu:0 available (device_count=2).

Fixed observation: [0.0, 0.1, -0.2, 0.5, -0.05, 0.0, 1.0, 0.0] float32 (deterministic, no env sampling randomness).

BackendQ-values (shape 1×4)Device proofAction
CPU[33.704620361328125, 34.56105041503906, 25.531845092773438, 32.34321212768555]cpu1
NPU[33.704612731933594, 34.5610466003418, 25.531841278076172, 32.34320831298828]npu:01

Synchronized timing (torch.npu.synchronize before/after):

  • First (compilation+warmup) latency: ~125 ms
  • Steady-state 10-sample avg 0.91 ms, min 0.88 ms, max 0.92 ms, p50 ~0.916 ms

CPU-NPU Consistency

  • validate_policy_outputs.py --atol 1e-4 --rtol 1e-3 → PASS
    count=4, finite=true, max_abs=7.63e-06, tolerance=0.03466, passed=true
  • action_match: true (both argmax=1)
  • Dtype float32, horizon 1, action_dim 4, shape (1,4) validated finite and within bounds.
  • No CPU fallback: model param, input tensor, output tensor all on npu:0 for NPU path.

Performance (benchmark_policy.py)

10 synchronized samples after 3 warmups, batch=1, horizon=1, dtype=float32:

avg_ms: 0.9149, min_ms: 0.906, max_ms: 0.921, p50: 0.915, p90: 0.919, p95: 0.921, samples: 10
decisions_per_s: ~1093 (actions_per_s identical, horizon=1)

Includes only model forward; excludes pre-processing (trivial numpy→tensor). First compile latency reported separately.

Environment Limitations

  • Requires CANN 8.5.1, torch_npu 2.9.0.post1, Ascend910 single card (fits, no sharding).
  • Inference uses fixed policy.pth weights; not retrained on NPU.
  • Gym compatibility shim needed for legacy SB3 checkpoint (gym → gymnasium spaces via sys.modules alias) but Q-Network execution is pure PyTorch, not gym-dependent at inference.
  • npu-smi shows 2 devices, run on npu:0; 3110/65536 MB HBM used at test time.

Reproduction

pip install -r requirements.txt
python inference.py
# expected: PASS with NPU device proofs

Evidence

  • Workflow (discovery → resource → loading → consistency → benchmark): agent workflow
  • NPU device call (npu-smi, torch_npu availability, model/input/output device): npu device
  • Model result (default inference.py): model result

Hardware tag: NPU / Ascend910_9362 verified true NPU.