This project adapts the HuggingFace model dkarthikeyan1/tcrt5_pre_tcrdb to run on a Huawei Ascend NPU via torch_npu.
T5ForConditionalGeneration (T5, seq2seq), model_type=t5tcrt5_pre_tcrdb (same family / custom TCRT5Tokenizer as dkarthikeyan1/tcrt5_ft_tcrdb)model.safetensors (167 MB) + tokenizer files (spiece.model, etc. — custom TCRT5Tokenizer)npu:0 (Ascend910), weights cached at ./model_weights/dkarthikeyan1/tcrt5_pre_tcrdb# 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| Method | Path | Description |
|---|---|---|
| GET | / | HTML page with a text box for the input sequence |
| POST | /predict | Accepts {"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:0 through get_device() which includes a
try-except fallback to CPU if the NPU is unavailable..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.TCRT5Tokenizer (SentencePiece). Loading it with the
Fast tokenizer produces the same decoding result.hf-mirror.com and cached locally; loading always
prefers the local cache to avoid re-downloading.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.assets/agent_workflow.png — NPU env setup / dependency install / task start logassets/npu_device_call.png — successful CLI inference run on npu:0assets/model_result.png — FastAPI POST /predict JSON result