本项目将文本 Embedding 模型 WhereIsAI/UAE-Large-V1(BERT 编码器,1024 维句子向量)适配迁移到 昇腾 NPU(Ascend910 / torch-npu)环境,提供 CLI + FastAPI 双模式推理。
BertModel),24 层,hidden_size=1024./model_weights/WhereIsAI/UAE-Large-V1(config.json + model.safetensors + tokenizer 等)inference.py 不含任何 .cuda() / torch.cuda.* / device="cuda" 调用。try: import torch_npu; torch.npu.set_device(0),失败则抛出明确 RuntimeError,禁止 CUDA 路径。model = model.to("npu:0"),input_ids/attention_mask 均 .to("npu:0")。sentence_transformers,用 transformers.AutoModel 输出 last_hidden_state,按 attention mask 归一化求均值,得到 1024 维句子向量。pip install -r requirements.txtpython inference.py --img test_input.txt --device npu:0输出 JSON 摘要(shape / 前若干维 / norm / inference_ms)。
uvicorn inference:app --host 127.0.0.1 --port 8000 &
curl -F "file=@test_input.txt" http://127.0.0.1:8000/predict返回完整 1024 维 embedding JSON。
assets/agent_workflow.png — NPU 依赖安装与启动日志assets/npu_device_call.png — CLI 推理成功画面assets/model_result.png — FastAPI 调用返回 JSON 结果画面