模型适配 · TCR 序列条件生成模型 (T5-based Seq2Seq) · 昇腾 NPU
Beta 版本头信息
{hardware NPU}[PMHC]、[SEP]、[EOS]、[SOS] 等,输入为格式化的 pMHC 伪序列{hardware NPU} Ascend 910B(torch_npu 2.9.0.post1)| 组件 | 版本 |
|---|---|
| torch | 2.9.0 |
| torch-npu | 2.9.0.post1 |
| python | 3.11.14 |
| transformers | 4.57.6 |
| CANN | 8.5.1 |
| NPU | Ascend 910B (Ascend910_9362) × 2 |
| 依赖 | numpy / transformers / torch-npu / sentencepiece |
同一权重(
dkarthikeyan1/tcrt5_ft_tcrdb),demo 输入为官方示例 pMHC 序列,CPU 与 NPU 均为 fp32 +eval()。
| 指标 | 数值 |
|---|---|
| logits 余弦相似度 | 1.000000 |
| logits 最大绝对误差 | < 1e-5 |
| 生成序列一致性 | 完全一致 ✅ |
| 参数量 | 77.7M |
Demo 输入:[PMHC]KLGGALQAK[SEP]YFAMYQENVAQTDVDTLYIIYRDYTWAELAYTWY[EOS]
生成输出:CASSLGTGGTDTQYF
| 指标 | 数值 |
|---|---|
| 单条输入生成耗时 | ~80-120 ms (beam=3, max_new_tokens=25) |
# 安装依赖
pip install torch torch-npu transformers sentencepiece -i https://mirrors.aliyun.com/pypi/simple/# NPU 推理(默认使用 demo 输入)
python3 inference.py --device npu:0
# 自定义条件输入
python3 inference.py --device npu:0 --text "[PMHC]KLGGALQAK[SEP]YFAMYQENVAQTDVDTLYIIYRDYTWAELAYTWY[EOS]"
# 无条件生成(随机 TCR 序列)
python3 inference.py --device npu:0 --seq "" --num_beams 10
# CPU vs NPU 精度对比
python3 inference.py --device npu:0 --compare
# 启动 HTTP 服务化推理
python3 inference.py --device npu:0 --serve --port 8000# 健康检查
curl http://localhost:8000/health
# 条件生成
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"text": "[PMHC]KLGGALQAK[SEP]YFAMYQENVAQTDVDTLYIIYRDYTWAELAYTWY[EOS]", "num_beams": 3}'条件生成输入需遵循以下格式:
[PMHC]<peptide_sequence>[SEP]<pseudosequence>[EOS]<peptide_sequence>: 目标肽段氨基酸序列(如 KLGGALQAK)<pseudosequence>: MHC 等位基因的伪序列(来自 NetMHCpan 定义)@Article{Karthikeyan2025_tcrtranslate,
author={Karthikeyan, Dhuvarakesh
and Bennett, Sarah N.
and Reynolds, Amy G.
and Vincent, Benjamin G.
and Rubinsteyn, Alex},
title={Conditional generation of real antigen-specific T cell receptor sequences},
journal={Nature Machine Intelligence},
year={2025},
month={Sep},
day={08},
abstract={Despite recent advances in T cell receptor (TCR) engineering, designing functional TCRs against arbitrary targets remains challenging due to complex rules governing cross-reactivity and limited paired data. Here we present TCR-TRANSLATE, a sequence-to-sequence framework that adapts low-resource machine translation techniques to generate antigen-specific TCR sequences against unseen epitopes. By evaluating 12 model variants of the BART and T5 model architectures, we identified key factors affecting performance and utility, revealing discordances between these objectives. Our flagship model, TCRT5, outperforms existing approaches on computational benchmarks, prioritizing functionally relevant sequences at higher ranks. Most significantly, we experimentally validated a computationally designed TCR against Wilms' tumour antigen, a therapeutically relevant target in leukaemia, excluded from our training and validation sets. Although the identified TCR shows cross-reactivity with pathogen-derived peptides, highlighting limitations in specificity, our work represents the successful computational design of a functional TCR construct against a non-viral epitope from the target sequence alone. Our findings establish a foundation for computational TCR design and reveal current limitations in data availability and methodology, providing a framework for accelerating personalized immunotherapy by reducing the search space for novel targets.},
issn={2522-5839},
doi={10.1038/s42256-025-01096-6},
url={https://doi.org/10.1038/s42256-025-01096-6}
}