This repository contains the complete validation, optimization, and benchmarking toolchain for running a BlendMask-Lite instance-segmentation model on Huawei Ascend NPUs (Atlas 800 A2/A3, CANN 8.5.1).
| Phase | Status | Description |
|---|---|---|
| Precision Verification | PASS | CPU/NPU tensor-level comparison with msaccucmp |
| Performance Benchmark | PASS | Batch/input tuning + msprof profiling |
| Preprocessing Optimization | PASS | Fused NPU tensor ops vs PIL baseline |
| ATC OM Conversion | PASS | ONNX exported; ATC conversion succeeded with BN+FP16 fusion |

blendmask-ascend-validation/
├── blendmask_model.py # Lightweight BlendMask-like model (ResNet50-like + FPN + FCOS + Blender)
├── blendmask_validator.py # Precision validation: CPU vs NPU with DumpCollector + msaccucmp
├── dump_collector.py # PyTorch hook-based tensor dumper (replaces ptdbg_ascend)
├── perf_benchmark.py # Performance benchmark: batch tuning, latency, throughput, msprof
├── atc_optimize.sh # ONNX export + ATC conversion script with fusion & AIPP configs
├── generate_final_report.py # Aggregates precision + performance + ATC into FINAL_REPORT.md/json
├── reports/
│ ├── precision_report.json # Detailed precision metrics
│ ├── performance_report.json # Benchmark results across configs
│ ├── sota_performance_report.json # SOTA benchmark results
│ ├── SOTA_SUMMARY.txt # Full-text SOTA validation summary
│ ├── FINAL_REPORT.md # Human-readable consolidated report
│ ├── FINAL_REPORT.json # Machine-readable consolidated report
│ ├── atc_conversion.log # ATC conversion log
│ ├── dumps/
│ │ ├── cpu/ # CPU baseline dump tensors (.npy)
│ │ └── npu/ # NPU inference dump tensors (.npy)
│ └── msprof_bs8_640x640/ # msprof profiling output
├── models/
│ ├── blendmask_lite.onnx # Exported ONNX model
│ ├── blendmask_bn_bs1.onnx # BN static batch ONNX
│ ├── blendmask_bn_dynamic.onnx # BN dynamic batch ONNX
│ ├── blendmask_bn_bs1.om # ATC-converted OM model
│ ├── fusion_switch.cfg # ATC graph fusion configuration
│ └── insert_op.cfg # ATC AIPP preprocess configuration
├── validation_report.json # verify-agent scoring schema report
└── README.md # This fileNote: The following files referenced in the original specification were not present in the source directory and are therefore not included:
blendmask_model_v2.py,blendmask_validator_v2.py,blendmask_validator_v3.py,generate_final_report_v3.py.
python3 blendmask_validator.py --output-dir ./reports --input-size 640 640Validates numerical consistency between CPU baseline and NPU inference using:
DumpCollector (PyTorch forward hooks)msaccucmp.py file_compare for tensor-level comparisonpython3 perf_benchmark.py --output-dir ./reportsBenchmarks multiple (batch_size, input_h, input_w) configurations and runs msprof on the best config.
bash atc_optimize.shExports ONNX from PyTorch and runs ATC with:
ConvBNFusionPass, UBFusion, etc.)buffer_optimize=l2_optimizepython3 generate_final_report.pyAggregates precision_report.json + performance_report.json into FINAL_REPORT.md and FINAL_REPORT.json.
| Metric | Value | Threshold | Status |
|---|---|---|---|
| Tensor Mean Relative Error | 1.7264% | < 10% | ✅ PASS |
| Tensor Max Layer Error | 7.2268% | < 10% | ✅ PASS |
| Box Absolute Error | 0.081620 | < 0.10 | ✅ PASS |
| Score Relative Error | 0.0237% | < 1% | ✅ PASS |
| Class Accuracy | 85.00% | > 70% | ✅ PASS |
| Top-5 Class Overlap | 100% | — | ✅ PASS |
| Config | Throughput (samples/s) | Latency (ms) | Speedup |
|---|---|---|---|
| Baseline GN FP32 | 241.27 | 4.145 | 1.00× |
| GN + FP16 | 318.73 | 3.137 | 1.32× |
| BN + FP32 (CANN fusion) | 252.95 | 3.953 | 1.05× |
| BN + FP16 (old SOTA) | 375.59 | 2.662 | 1.56× |
| BN + FP16 + Streams (SOTA) | 490.55 | 2.039 | 2.03× |
| Batch Size | Sequential (samples/s) | Streams Parallel (samples/s) | Speedup | Best Config |
|---|---|---|---|---|
| 1 | 121.87 | 101.50 | 0.83× | SEQ |
| 2 | 215.47 | 234.45 | 1.09× | PAR |
| 4 | 315.92 | 396.91 | 1.26× | PAR |
| 8 | 375.36 | 490.55 | 1.31× | PAR ← default |
| 16 | 420.79 | 503.59 | 1.20× | PAR |
| Item | Status |
|---|---|
| ONNX Static Export | ✅ OK (blendmask_bn_bs1.onnx) |
| ONNX Dynamic Export | ✅ OK (blendmask_bn_dynamic.onnx) |
| ATC OM Conversion | ✅ SUCCESS (blendmask_bn_bs1.om) |
The performance journey from baseline to SOTA:
| Round | Change | Throughput (samples/s) | Gain |
|---|---|---|---|
| Baseline | GN FP32 | 241.27 | — |
| R1 | GN → BN (CANN Conv+BN fusion) | 252.95 | +4.8% |
| R2 | FP32 → FP16 (amp) | 318.73 | +32.1% |
| R3 | GN+FP16 → BN+FP16 | 375.59 | +55.7% |
| R4 | EnvOpt (tcmalloc, stream queue) | 375.48 | +55.6% (marginal) |
| R5 | FPN Head Stream Parallelism | 490.55 | +103% |
Key breakthrough: Stream-parallel FPN Head The 5 FPN levels (P3-P7) are processed on independent NPU Streams, allowing the AI Cores to compute them in parallel instead of sequentially. This yields +30.7% throughput at BS=8, scaling to +19.7% at BS=16.
Key model changes enabling SOTA:
inplace=False for NPU compatibilitytorch.npu.amp.autocastalign_corners for ONNX export stabilityforward_with_streams() for concurrent FPN head processingptdbg_ascend was unavailable in this environment, dump_collector.py provides a lightweight hook-based replacement fully compatible with msaccucmp.blendmask_bn_bs1.onnx) converts successfully via ATC with graph fusion (ConvBNFusionPass, UBFusion) and buffer_optimize=l2_optimize. The dynamic-batch ONNX variant requires AOE tuning for unsupported interpolation patterns.BlendMaskLite.aclmdlExecute pipeline for production inference.Apache-2.0