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

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

This project adapts the HuggingFace model dkarthikeyan1/tcrt5_ft_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
  • 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_ft_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_ft_tcrdb",
  "device": "npu:0",
  "input": "[PMHC]KLGGALQAK[SEP]YFAMYQENVAQTDVDTLYIIYRDYTWAELAYTWY[EOS]",
  "output": "[TCR]CASSPGQGGTEAFF",
  "output_raw": "[SOS][TCR]CASSPGQGGTEAFF[EOS]"
}

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.

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