w
gcw_uQ09W7jl/WhereIsAI-UAE-Large-V1-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

WhereIsAI/UAE-Large-V1-NPU

Ascend 910B NPU-adapted version of WhereIsAI/UAE-Large-V1 (BertModel, 24 layers, 1024 hidden, 335M params, 1024-dim embedding, CLS pooling).

Validated on single-card Ascend 910B (npu:0) with torch_npu eager inference — no graph compilation required.

Model Info

  • Base: WhereIsAI/UAE-Large-V1 (BertModel, model_type: bert, 24 layers, hidden 1024, 16 heads, vocab 30522)
  • Architecture: BertModel without task head (embedding route)
  • Pooling: CLS token (1_Pooling/pooling_mode_cls_token: true) + L2 normalize (sentence-transformers Transformer→Pooling→Normalize)
  • Max length: 512
  • Weight: model.safetensors 1.34 GB (fp32)
  • Tokenizer: BertTokenizer (vocab.txt 30522)

NPU Adaptation

  • Load: AutoModel.from_pretrained(..., torch_dtype=float32).to("npu:0") — fp32 preserves 0.999+ cosine vs CPU
  • Tokenizer: BertTokenizer from local dir, padding=True, truncation=True, max_length=512
  • Pooling: last_hidden_state[:,0] then F.normalize(p=2) — attention_mask kept for padding correctness
  • All tensors (input_ids, attention_mask, last_hidden_state, embeddings) verified on npu:0; torch.npu.synchronize() around timing
  • Single-card HBM check: weight 1.34 GB + activation < 4 GB, well within 60 GB free per card — no multi-card fallback needed

Validation

  • Inputs: 4 real English sentences (similar pair + unrelated + ML sentence)
  • CPU vs NPU cosine per sample ≥ 0.99999, per-dim max diff ≤ 4e-4 (fp32), similar-pair cosine 0.988 > dissimilar 0.23 holds on both
  • Performance (batch 4, 910B): ~269 sentences/s stable (14.8 ms / batch), first inference ~219 ms (compile)
  • Device proofs logged: next(model.parameters()).device, input_ids.device, last_hidden_state.device, embeddings.device all npu:0

Usage

from transformers import AutoModel, AutoTokenizer
import torch, torch_npu, torch.nn.functional as F

model_dir = "WhereIsAI/UAE-Large-V1"
tok = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=False)
model = AutoModel.from_pretrained(model_dir, trust_remote_code=False).to("npu:0").eval()

sentences = ["The cat sits on the mat.", "A cat is sitting on a mat."]
enc = tok(sentences, padding=True, truncation=True, max_length=512, return_tensors="pt")
enc = {k: v.to("npu:0") for k,v in enc.items()}
with torch.no_grad():
    out = model(**enc)
    emb = F.normalize(out.last_hidden_state[:,0], p=2, dim=1)  # [2, 1024]
    torch.npu.synchronize()
print(emb.device)  # npu:0
print(F.cosine_similarity(emb[0].unsqueeze(0), emb[1].unsqueeze(0)).item())  # ~0.988

Or run python inference.py.

Evidence

agent workflow npu device call model result

Requirements

See requirements.txt. Tested with torch 2.9.0, torch_npu 2.9.0.post1, transformers >=4.30.