gcw_6a3w2yXz/UAE-Large-V1-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

WhereIsAI/UAE-Large-V1 - Ascend NPU Adaptation

This is an Ascend NPU adaptation of WhereIsAI/UAE-Large-V1 (https://huggingface.co/WhereIsAI/UAE-Large-V1), an embedding model based on BertModel (1024 hidden, 24 layers, ~335M params) with CLS pooling.

Original model: WhereIsAI/UAE-Large-V1 - AnglE-based universal embedding model, sentence-transformers compatible (Transformer + Pooling(cls_token)).

Model Details

  • Architecture: BertModel (BertModel), word_embedding_dimension 1024, pooling_mode_cls_token True
  • Task: embedding (sentence embedding / retrieval)
  • Max seq length: 512
  • Weight size: 1.3G (model.safetensors)
  • Route verified via scripts/inspect_nlp_model.py -> embedding

NPU Adaptation

  • Backend: torch_npu (Ascend 910B, CANN 8.5.1, torch 2.9.0, torch_npu 2.9.0.post1)
  • Device: npu:0 (Ascend910_9362, 61 GiB HBM, 2 devices available)
  • Loading: AutoModel.from_pretrained(local_dir, trust_remote_code=False).to("npu:0")
  • Pooling: CLS token (first token hidden state) + L2 normalization, as per 1_Pooling/config.json
  • dtype: float32 (original torch_dtype)

Validation

  • Device proof: next(model.parameters()).device == npu:0, input_ids.device == npu:0, last_hidden_state.device == npu:0, embeddings.device == npu:0
  • CPU vs NPU consistency (4 sentences):
    • cosine ≥ 0.999993, max_diff ≤ 0.000409 (fp32 threshold 1e-3)
    • Semantic: similar pair (What is the capital of France? vs What is France's capital city?) cosine 0.9669 > dissimilar (vs The weather...) 0.2826
  • Performance (NPU synchronized):
    • First inference: ~18 sentences/s (incl. compilation)
    • Stable: ~253 sentences/s (4 sentences batch)

Usage

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

model_id = "WhereIsAI/UAE-Large-V1"
device = torch.device("npu:0" if torch.npu.is_available() else "cpu")
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=False)
model = AutoModel.from_pretrained(model_id, trust_remote_code=False).to(device).eval()

sentences = ["What is the capital of France?", "Machine learning is AI."]
inputs = tokenizer(sentences, padding=True, truncation=True, max_length=512, return_tensors="pt")
inputs = {k: v.to(device) for k, v in inputs.items()}
with torch.no_grad():
    hidden = model(**inputs).last_hidden_state
    embeddings = F.normalize(hidden[:, 0], p=2, dim=1)  # CLS pooling
print(embeddings.shape)  # [2, 1024]
# similarity
print(F.cosine_similarity(embeddings[0].unsqueeze(0), embeddings[1].unsqueeze(0)))

See inference.py for full example with torch.npu.synchronize() timing.

Evidence

agent workflow npu device call model result

Requirements

See requirements.txt. Core: torch, torch_npu, transformers, safetensors.