2
gcw_BOxvkDDf/tcrt5-pre-tcrdb
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

TCRT5 · dkarthikeyan1/tcrt5_pre_tcrdb — 昇腾 Ascend NPU 适配

This project adapts the HuggingFace model dkarthikeyan1/tcrt5_pre_tcrdb to run on a Huawei Ascend NPU via torch_npu.

  • Architecture: T5ForConditionalGeneration (T5, seq2seq), model_type=t5
  • Task: conditional generation of TCR CDR3β sequences given a peptide-MHC (pMHC) input
  • Checkpoint: PRETRAINED tcrt5_pre_tcrdb (same family / custom TCRT5Tokenizer as dkarthikeyan1/tcrt5_ft_tcrdb)
  • Weights: single model.safetensors (167 MB) + tokenizer files (spiece.model, etc. — custom TCRT5Tokenizer)
  • Runtime: torch 2.9.0 + torch_npu, python 3.11, transformers 4.57.6
  • NPU: npu:0 (Ascend910), weights cached at ./model_weights/dkarthikeyan1/tcrt5_pre_tcrdb

Quick start

# 1) Prepare environment
source /usr/local/Ascend/ascend-toolkit/set_env.sh
export ASCEND_RT_VISIBLE_DEVICES=0

# 2) CLI single-input inference
python3 inference.py --input "[PMHC]KLGGALQAK[SEP]YFAMYQENVAQTDVDTLYIIYRDYTWAELAYTWY[EOS]" --num_workers 0

# 3) Start FastAPI service
python3 inference.py --serve --port 8000

FastAPI endpoints

MethodPathDescription
GET/HTML page with a text box for the input sequence
POST/predictAccepts {"text": "..."} (JSON) or a form field text; returns JSON {"input": ..., "output": ...}

Example request:

curl -X POST http://0.0.0.0:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "[PMHC]KLGGALQAK[SEP]YFAMYQENVAQTDVDTLYIIYRDYTWAELAYTWY[EOS]"}'

Response:

{
  "model": "dkarthikeyan1/tcrt5_pre_tcrdb",
  "device": "npu:0",
  "input": "[PMHC]KLGGALQAK[SEP]YFAMYQENVAQTDVDTLYIIYRDYTWAELAYTWY[EOS]",
  "output": "LLL",
  "output_raw": "[SOS]<extra_id_0>LLL<extra_id_1>[PAD]..."
}

NPU adaptation notes

  • All device tensors are moved to npu:0 through get_device() which includes a try-except fallback to CPU if the NPU is unavailable.
  • The code contains no CUDA device calls — all .cuda(), torch.device('cuda') and torch.cuda.* were removed/replaced with the torch_npu equivalents.
  • torch_npu must be imported before transformers in this environment so the compatible user-site huggingface-hub is used.
  • The tokenizer is the custom TCRT5Tokenizer (SentencePiece). Loading it with the Fast tokenizer produces the same decoding result.
  • Weights are downloaded once via hf-mirror.com and cached locally; loading always prefers the local cache to avoid re-downloading.
  • Device note: this host exposes NPU logical devices 0/1 (physical Phy-IDs 8/9); use ASCEND_RT_VISIBLE_DEVICES=0. Setting ASCEND_RT_VISIBLE_DEVICES=8 makes the NPU invisible to torch_npu and falls back to CPU.

Screenshots

  • assets/agent_workflow.png — NPU env setup / dependency install / task start log
  • assets/npu_device_call.png — successful CLI inference run on npu:0
  • assets/model_result.png — FastAPI POST /predict JSON result