This project adapts the HuggingFace model dkarthikeyan1/tcrt5_ft_tcrdb to run on a Huawei Ascend NPU via torch_npu.
T5ForConditionalGeneration (T5, seq2seq), model_type=t5model.safetensors (167 MB) + tokenizer files (spiece.model, etc. — custom TCRT5Tokenizer)npu:0 (Ascend910), weights cached at ./model_weights/dkarthikeyan1/tcrt5_ft_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_ft_tcrdb",
"device": "npu:0",
"input": "[PMHC]KLGGALQAK[SEP]YFAMYQENVAQTDVDTLYIIYRDYTWAELAYTWY[EOS]",
"output": "[TCR]CASSPGQGGTEAFF",
"output_raw": "[SOS][TCR]CASSPGQGGTEAFF[EOS]"
}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.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