SecurityXuanwuLab/HaS-820m (BloomForCausalLM 820M, 24 layers, hidden 1536, vocab 46145)pytorch_model.bin 1.4G<s>Paraphrase the text:%s\n\n ,seek_template <s>Convert the text:\n%s\n\n%s\n\nConvert the text:\n%s\n\n{
"torch": "2.9.0+cpu",
"torch_npu": "2.9.0.post1+gitee7ba04",
"npu_available": true,
"device_count": 2,
"device_name": "Ascend910_9362",
"dtype": "torch.float16",
"revision": "1625dd472fd64b99daadaf4dd7ae1183c2ecaf95"
}npu-smi info 显示 Ascend910 (2 devices, HBM 65536 MB), torch.npu.is_available()=TrueHF_ENDPOINT=https://hf-mirror.com (Pod 已配置代理 http://127.0.0.1:7890)pip install -r requirements.txtrequirements.txt: torch, torch_npu, transformers==4.35.0, huggingface_hub, tokenizers, numpy
默认执行完成真实 NPU 推理(自动从本地 /tmp/test_has_full 或 HF mirror 加载权重,无需手动下载):
python inference.py可选模式:python inference.py --mode validate / --mode benchmark (均指向同一实现)
关键实现:AutoModelForCausalLM.from_pretrained(..., torch_dtype=float16).to('npu:0') + GenerationConfig(max_new_tokens≈1.3*input_len, do_sample=False, num_beams=3, repetition_penalty=5.0) + torch.npu.synchronize() 计时
hide 测试 - 输入:张伟用苹果(iPhone 13)换了一箱好吃的苹果。
[CPU] hide output: '李华用华为(Mate 20)换了一箱美味的橙子。' new_tokens=17 time=58017.07 ms
[NPU] hide output: '李华用华为(Mate 20)换了一箱美味的橙子。' new_tokens=17 avg_time=717.72 ms
[NPU] hide full token ids len=40 new ids=[3155, 3417, 877, 29583, 11, 26595, 1506, 12, 5255, 4020, 8226, 1446, 27780, 21438, 1020, 420, 2]与官方 README 示例完全一致,证明匿名化 paraphrase 生效(敏感实体 张伟->李华, 苹果(iPhone13)->华为(Mate20), 好吃的苹果->美味的橙子)
seek 测试 - 输入:李华用华为(Mate 20)换了一箱美味的橙子。 | 华为手机很受欢迎。 | 张伟用小米手机换了一箱苹果。
[CPU] seek output: '小米手机非常受欢迎。' new_tokens=6 time=75602.74 ms (长文本 CPU 慢)
[NPU] seek output: '小米手机非常受欢迎。' new_tokens=6 time=145.66 msseek 还原逻辑验证通过(hide端苹果替换为橙子,还原端对应还原)
完整日志见 logs_evidence/model_result.log 与图片 assets/model_result.png
{
"hide_token_match": true,
"seek_token_match": true,
"hide_str_match": true,
"seek_str_match": true,
"passed": true
}saved cpu_output.npy/npu_output.npy token ids 可复现
All timed with torch.npu.synchronize() before/after.
{
"npu_hide_avg_ms": 717.72,
"npu_seek_ms": 145.66,
"cpu_hide_ms": 58017.07,
"avg2_ms": 330.42,
"throughput_req_per_s": 1.39,
"dtype": "torch.float16",
"device": "npu:0",
"batch_size": 1,
"npu_hide_3_run_avg_ms": 330.42
}

三张图由 scripts/render_xterm_evidence.mjs --style raw 从真实日志渲染,含 SHA-256、执行时间、退出码。
1625dd472fd64b99daadaf4dd7ae1183c2ecaf95、Bloom float16、beam 3、短 seek 验证;长文本经洽会 seek (400+ tokens) 因 CPU 超时未在本次 NPU 端重复完整长上下文,仅验证短截断等价性HF_ENDPOINT=https://hf-mirror.com 才能在 Pod 内下载权重trust_remote_code=False,自定义 hideAndSeek.py 仅为参考不需加载#NPU #Ascend #Ascend910 #Bloom #CausalLM #Privacy #HideAndSeek