Skip to content

Add numerical tests for Ascend ViT varlen attention - #139

Open
zhachar14h-cell wants to merge 1 commit into
deepseek-ai:mainfrom
zhachar14h-cell:test/ascend-vit-varlen-attention
Open

zhachar14h-cell wants to merge 1 commit into
deepseek-ai:mainfrom
zhachar14h-cell:test/ascend-vit-varlen-attention

Conversation

@zhachar14h-cell

Copy link
Copy Markdown

The Ascend ViT attention shim has no standalone numerical pytest coverage. Changes to cumulative sequence ends, attention scaling, or packed QKV strides could corrupt image embeddings without a small, model-free check.

Add 34 ci_npu cases for the original vit_attn._flash_attn_fwd implementation:

  • Compare FP16/BF16 output with independent per-segment CPU FP64 attention computed from dtype-rounded inputs.
  • Cover contiguous inputs and packed QKV views, single-token and uneven segments, and two head configurations.
  • Use distinct constant values in separate segments to check that attention does not mix segments.
  • Check output shape, dtype, device, and the None LSE return value.

The fixture loads the standalone shim by file path to avoid installing the package's process-wide import redirects. It skips when PyTorch, torch_npu, or an NPU is unavailable. No model weights or custom kernel dependencies are needed.

Validation:

  • Single Ascend910B3 (A2), CANN 9.0.0, Python 3.11.4, torch 2.7.1+cpu, torch_npu 2.7.1.post4, pytest 8.3.2: OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 python -m pytest -q -m ci_npu tests/npu_ops/test_vit_attn.py — 34 passed in 11.37s.
  • Local Python 3.13.12 / pytest 8.4.2 without PyTorch: 34 collected and 34 skipped; --collect-only -m ci_npu selects all 34.
  • Repository-wide ruff check --no-cache and ruff format --check --no-cache passed; git diff --cached --check passed.

This is a tests-only change. The A2 run exercises the standalone shim, not package initialization (the project requires Python 3.12), complete model inference, or other custom kernels. A3/Ascend950 and the declared production dependency stack were not tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant