m
mengsihan/ug-cppo-finai-2025-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

UG-CPPO FinAI 2025 — Ascend NPU Adaptation (Offline-RL)

Original Model: graceesthi/ug-cppo-finai-2025 (HF) — 30 SB3 PPO/CPPO/UG-CPPO trading agents, 250k steps, 10 seeds × 3 algorithms.
Adapted Checkpoint: ug_cppo_seed47.zip (top performer, Rachev 1.0104).
Route: offline-rl — state (81) → continuous portfolio action (10). NPU-adapted via torch_npu on Ascend910.

Model & Task

  • Library: stable-baselines3 ActorCriticPolicy (MLP 81→64→64→10). Paper: UG-CPPO v3, FinAI Contest 2025 / NeurIPS 2026.
  • Observation: Box(81,) — Nasdaq 10-stock OHLC + technical indicators, normalized, float32.
  • Action: Box(10,) — portfolio weights for tickers [AAPL, AMD, AMZN, COST, GOOGL, META, MSFT, NFLX, NVDA, TSLA], bounded [-1,1] (short/long), float32.
  • Inference Contract: single-step deterministic action; tanh hidden, linear action_net; log_std unused at inference (deterministic).
  • Horizon: 1 decision per forward; report as decisions/s.

NPU Adaptation

  • Loads policy.pth directly (no SB3 pickle) into minimal MLPPolicy mirroring SB3 weights: mlp_extractor.policy_net.0/.2, action_net, value_net (value head unused).
  • Device proof: every float tensor (observation, policy params, action output) logged with .device; no .cpu() fallback — see npu_device_call.png.
  • No model substitution: same ZIP weights on CPU and NPU, same observation (torch.randn(1,81) seed 42), same dtype float32, deterministic.
  • Sync timing: each NPU forward wrapped with torch.npu.synchronize() before/after time.perf_counter().

Results (Real NPU npu:0, Ascend910_9362)

Inference snapshot (python inference.py):

  • CPU action: [-1.4619, 2.4135, -1.4993, -3.0563, -0.3324, 1.3786, 0.4621, -0.1799, 3.0517, -0.0784]
  • NPU action: [-1.4619, 2.4135, -1.4993, -3.0563, -0.3324, 1.3786, 0.4621, -0.1799, 3.0517, -0.0784]
  • Shape (1,10), finite true, action_dim 10, horizon 1.

CPU-NPU Consistency:

  • max_abs = 2.38e-07, tolerance atol 1e-4 + rtol 1e-3 * max|ref| = 3.15e-03 → PASS (validate_policy_outputs.py).
  • 5-seed sweep max_abs 4e-07 … 6e-07, all < 1e-4.

Performance (NPU, batch 1):

  • Warmup 3, measured 10, torch.npu.synchronize() per sample.
  • avg 0.139 ms, min 0.129 ms, max 0.163 ms, p50 0.136 ms, p90 0.144 ms, p95 0.147 ms
  • decisions/s ≈ 7194 (1000/avg), decisions_per_s via benchmark_policy.py.
  • Estimates: peak memory < 50 MB (81×64 MLP), single Ascend910 (64 GB HBM) sufficient.

Environment & Repro

  • NPU: Ascend910_9362, torch_npu 2.9.0.post1, torch 2.9.0+cpu, CANN 8.5.1, npu-smi 25.5.5.
  • Device count: 2 (used npu:0), npu_available true.
  • Dependencies: see requirements.txt; run python inference.py from repo root (weights auto-downloaded via huggingface_hub if not present at ../ug-cppo-finai-2025/ug_cppo_seed47.zip).
  • Validation: validate_policy_outputs.py --atol 1e-4 --rtol 1e-3 → PASS; benchmark_policy.py --items-per-call 1 --unit decisions.

Limitations

  • Value head not used (policy only); no environment rollout (single-step action is the acceptance criterion per offline-rl contract; Gym rollout would be extra, not a substitute).
  • Stochastic sampling (log_std) disabled (deterministic); to re-enable, sample eps ~ N(0, exp(log_std)) with fixed seed and synchronize device.
  • Other 29 checkpoints share identical architecture — adapt by swapping ZIP filename.

Assets

  • assets/agent_workflow.png — discovery, NPU check, consistency, benchmark, inference logs.
  • assets/npu_device_call.png — npu-smi, torch.npu.is_available(), device name, model/input/output device.
  • assets/model_result.png — python inference.py output with PASS.

Usage

pip install -r requirements.txt
python inference.py
# optional: --device cpu (force CPU), default auto (NPU if available)