liuhongwei-2026/tcrt5_ft_tcrdb
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

dkarthikeyan1/tcrt5_ft_tcrdb on Ascend NPU

模型适配 · TCR 序列条件生成模型 (T5-based Seq2Seq) · 昇腾 NPU

Beta 版本头信息

{hardware NPU}

1. 简介

  • 模型来源: dkarthikeyan1/tcrt5_ft_tcrdb(AtomGit 镜像: https://ai.gitcode.com/hf_mirrors/dkarthikeyan1/tcrt5_ft_tcrdb)
  • 模型类型: TCRT5 —— 基于 T5 架构的序列到序列模型,用于给定肽段-MHC (pMHC) 条件下生成 T 细胞受体 (TCR) 的 CDR3β 序列。输入为包含 pMHC 信息的特殊标记文本,输出为抗原特异性 TCR 序列。
  • 参数量: 约 77.7M
  • 架构: 标准 T5 编码器-解码器架构,10 层编码器 + 10 层解码器,d_model=256,d_ff=1024,16 头注意力,相对位置编码(32 buckets,最大距离 128),词表大小 128
  • 词表/输入: SentencePiece 词表,特殊标记包括 [PMHC]、[SEP]、[EOS]、[SOS] 等,输入为格式化的 pMHC 伪序列
  • 输出: CDR3β 氨基酸序列(自动回归生成)
  • 适配状态: SUCCESS
  • 适配说明: 本模型为 T5-based Seq2Seq 模型(非传统 LLM),不适用 vLLM-Ascend;本项目采用 torch_npu 在昇腾 NPU 上适配(T5 标准架构,所有算子均为 NPU 原生支持,零算子改造)。使用 transformers 官方 T5 实现,直接加载官方权重,与 CPU 输出完全一致。
  • 适配时间: 2026-08-22
  • 硬件: {hardware NPU} Ascend 910B(torch_npu 2.9.0.post1)

2. 验证环境

组件版本
torch2.9.0
torch-npu2.9.0.post1
python3.11.14
transformers4.57.6
CANN8.5.1
NPUAscend 910B (Ascend910_9362) × 2
依赖numpy / transformers / torch-npu / sentencepiece

3. 精度评测 (CPU vs NPU)

同一权重(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

4. 性能评测 (昇腾 NPU)

指标数值
单条输入生成耗时~80-120 ms (beam=3, max_new_tokens=25)

5. 使用说明

环境准备

# 安装依赖
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

服务化 API

# 健康检查
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 定义)

6. 已知问题与限制

  1. 本模型仅用于学术研究目的,不应用于临床诊断
  2. 模型对低亲和力 pMHC 的预测性能未经充分验证
  3. Beam search 解码倾向于生成高重组概率序列,多样性较低;如需更高多样性,建议使用采样解码(top-p / temperature)

7. 引用

@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}
}