BAAI/bge-base-en-v1.5 文本向量化(Embedding)模型的昇腾 Ascend NPU 适配推理仓库(Model-Agent 大赛交付)。
Transformer(BERT) -> Pooling(CLS token) -> Normalize(L2),即取 [CLS] token 向量并做 L2 归一化。pip install -r requirements.txt单条文本向量化:
python3 inference.py --query "The weather is lovely today." --output ./results多条文本(逗号分隔)或文件(每行一条):
python3 inference.py --texts "A man is playing guitar.,How is the weather today?" --output ./results
python3 inference.py --texts @queries.txt --weights-dir ./ --device npu:0| 参数 | 说明 | 默认 |
|---|---|---|
--texts | 逗号分隔文本列表,或 @file.txt(每行一条) | 示例文本 |
--query | 单条查询文本(简写) | 无 |
--output | 结果输出目录 | results |
--weights-dir | 本地权重目录(仓库根目录) | . |
--device | auto / npu:0 / cuda:0 / cpu | auto |
--max-length | 输入最大长度 | 512 |
权重从本地 --weights-dir 加载;缺失时自动从 HuggingFace 镜像(hf-mirror.com)下载,不可达时回退 ModelScope。
运行后 results/ 目录生成:
npu_result.json — 推理结果(嵌入向量、相似度、检查项、耗时)inference_evidence.txt — 验证证据摘要model_sha256.txt — 权重文件 sha256npu_smi.txt — NPU 状态快照输出为每条文本的 768 维归一化向量(unit_norm 检查通过),并附第一条文本与其他文本的余弦相似度。
npu:0(Ascend910)(4, 768) 向量finite 通过、向量 unit_norm(L2 范数≈1)通过| 文件 | 说明 |
|---|---|
inference.py | NPU 推理脚本(必选) |
readme.md | 本文档(必选) |
requirements.txt | 环境依赖清单 |
config.json / model.safetensors | 模型权重(Git LFS,417.6 MiB) |
tokenizer*.json / vocab.txt | BERT tokenizer |
assets/ | 比赛三张截图(agent_workflow / npu_device_call / model_result) |