원클릭으로
support-new-model
Add support for a new model (already in lmdeploy's CUDA backend) on domestic AI hardware (Ascend / CAMB / MACA) via dlinfer.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Add support for a new model (already in lmdeploy's CUDA backend) on domestic AI hardware (Ascend / CAMB / MACA) via dlinfer.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Pull and analyze inference timelines on Ascend with lmdeploy+dlinfer. Covers profiling script templates, delay selection, raw timeline handling, fixed-real-batch decode/KV-context audit, and analysis reporting.
Start, monitor, and stop lmdeploy REST API services for any supported device/backend. Use when Codex needs to run `lmdeploy serve api_server` for a model path, choose model names from the model being served, set backend/device/max-batch/cache and user-provided parallel strategy flags, run outside the sandbox when devices are unavailable inside it, preserve server logs, check readiness, handle port conflicts, and cleanly stop the service before another run.
Run RESTful pressure benchmarks with lmdeploy's profile_restful_api.py after starting an lmdeploy API service. Use when Codex needs to choose ShareGPT native-length or random-length workloads, set tokenizer/model/client parameters without hard-coding qwen, compare models or max-batch settings, preserve logs, inspect running batch and KV cache behavior, and report throughput and cache/OOM handling.
The operator call chain in lmdeploy+dlinfer — the five layers every op crosses from model.forward() down to torch_npu/aclnn kernels, and how to trace or add a new op. Uses fused MoE (Qwen3.5 MoE) on Ascend as the worked example.
Understand the complete graph mode flow in lmdeploy+dlinfer, covering the runner architecture, buffer management, vendor differences, and common pitfalls.
Debug precision regressions in lmdeploy+dlinfer on domestic AI hardware (Ascend / CAMB / MACA) by comparing against a reference implementation.
| name | support-new-model |
| description | Add support for a new model (already in lmdeploy's CUDA backend) on domestic AI hardware (Ascend / CAMB / MACA) via dlinfer. |
You are helping the user adapt a new LLM or VLM for dlinfer's supported hardware backends (Ascend NPU, CAMB MLU, MACA GPU). The model already runs on CUDA via lmdeploy — your job is to identify what is missing for the target vendor and implement it.
Ask the user:
lmdeploy/pytorch/models/, e.g. qwen3, deepseek_v2)Do not proceed until both questions are answered.
Read all of the following files yourself using Read/Bash tools — do not ask the user:
lmdeploy/lmdeploy/pytorch/models/<model>.py
lmdeploy/lmdeploy/pytorch/backends/dlinfer/op_backend.py
lmdeploy/lmdeploy/pytorch/backends/dlinfer/<vendor>/op_backend.py ← per vendor
The full call chain is: models/<model>.py → lmdeploy/pytorch/nn/
→ backends/dlinfer/ → kernels/dlinfer/ → dlinfer/ops/ → vendor/.
If the connection between a model layer and its backend op is unclear, trace
through lmdeploy/pytorch/nn/ to find the intermediate abstraction.
lmdeploy/pytorch/kernels/default/ contains the CUDA reference
implementations and is useful as a specification when writing new vendor ops.
models/<model>.py, identifyStepContext or attn_metadata
beyond the standard set: input_ids, position_ids, block_offsets,
q_seqlens, kv_seqlens, kv_start_indices.
Known extra fields already handled: state_ids (SSM),
mrope_position_ids (MROPE),
cu_seqlens / has_initial_state (Gated Delta Networks).op_backend.py, checkget_layer_impl_builder(): which OpTypes already have a dlinfer Impl.
Cross-reference with the op list above to identify gaps → Path A.<vendor>/op_backend.py, check each of the following carefullyupdate_step_context(): this method builds attn_metadata and (for
Ascend) moe_metadata for every inference step. Verify that it correctly
handles all fields the new model requires. If the model introduces new
context fields or a new attention mode (e.g. a new is_gated_delta-style
flag), this method must be extended → Path B.get_k_block_shape() / get_v_block_shape(): confirm the KV cache
layout matches what the model's attention implementation expects. Different
vendors and even different SoC generations (Ascend A2 vs A3, 310P) may use
different layouts → Path B if wrong.AscendKVQuantMeta (Ascend only): if the model uses KV cache
quantization with a scale/offset format different from the current
implementation → Path B.Summarise your findings to the user before writing any code:
op_backend.py gaps (→ Path B)Follow this path for every op that is absent from get_layer_impl_builder().
Implement each layer in top-to-bottom order:
lmdeploy/lmdeploy/pytorch/backends/dlinfer/Add a new XxxImpl (inherits lmdeploy base Impl) and XxxBuilder
(with build()).
Register the builder in op_backend.py's get_layer_impl_builder()
dispatcher.
Reference: activation.py (simplest), norm.py, attention.py (most
complex).
lmdeploy/lmdeploy/pytorch/kernels/dlinfer/Add a thin wrapper function calling dlinfer.ops.<op_name>(...).
Export it from __init__.py.
dlinfer/dlinfer/ops/llm.pyRegister with @register_custom_op("dlinfer::<op_name>", [...]).
Forward to vendor_ops_registry["<op_name>"].
The key string must exactly match the function name in Layer 4.
dlinfer/dlinfer/vendor/<vendor>/Add @register_ops(vendor_ops_registry) implementation calling the vendor's
native op:
torch.ops.npu.* — see vendor/ascend/torch_npu_ops.pytmo.* (torch_mlu_ops) — see vendor/camb/camb_ops.pymcoplib.* — see vendor/maca/maca_ops.pyAscend: before writing any new op in torch_npu_ops.py, ask the user to
provide the official NPU operator documentation for that op. Implement
strictly according to the docs: parameter names, tensor shapes, and dtype
constraints are not always inferrable from existing code and a mismatch causes
hard-to-debug runtime errors.
For complex ops (e.g. Ascend attention with graph-mode bookkeeping), split
logic into a helper module (e.g. vendor/ascend/attention.py) and import
from torch_npu_ops.py.
op_backend.py changesFile: lmdeploy/lmdeploy/pytorch/backends/dlinfer/<vendor>/op_backend.py
Handle each sub-case independently:
update_step_context(): new context fields or attention modesWhen the new model requires fields in attn_metadata that the current
implementation does not populate, extend update_step_context():
attn_metadata at the end of the
method.moe_metadata if the model introduces a new MoE
communication pattern or parallelism topology.Reference: the is_gated_delta block (adds cu_seqlens and
has_initial_state),
the kv_quant_policy == 8 block (populates AscendKVQuantMeta).
get_k_block_shape() / get_v_block_shape(): KV cache layoutThis rarely needs changing once the hardware target is fixed. Skip unless the new model introduces a fundamentally different attention architecture that requires a new block memory layout not covered by any existing vendor backend.
AscendKVQuantMeta: KV quantization (Ascend only)Legacy feature; its correctness is not actively verified. Skip for standard model support — only revisit if KV cache quantization is explicitly required and confirmed to be working.
dlinfer/dlinfer/framework/lmdeploy_ext/)Each sub-area is independent — assess and handle separately.
When needed: only when the model introduces a new StepContext field
whose shape varies with batch size or sequence length at runtime.
Fixed-shape tensors do not need special buffer management. Example:
x_active_mask (shape [batch_size]) was added to handle Expert Parallelism
— its size changes per step, so it requires a pre-allocated maximum-size
buffer.
framework/lmdeploy_ext/cudagraph/ascend_cudagraph.py
make_buffers_cudagraph: allocate the new field at maximum size
(max_batches / max_tokens). Using runtime size here causes shape
errors on replay.fill_buffers_cudagraph: copy runtime values into the pre-allocated
buffer.update_context_cudagraph: wire the buffer back into the step context.is_ssm (state_ids) and use_mrope (mrope_position_ids)
paths.camb_cudagraph.py /
maca_cudagraph.py.Skip if the model uses only the standard fields already handled.
When needed: when the model requires a vendor-specific override of lmdeploy behaviour (e.g. a different MoE communication strategy on Ascend, an unsupported sampling op on CAMB, hardware-specific cache formats such as Ascend 310P NZ layout).
framework/lmdeploy_ext/device/ascend.pyframework/lmdeploy_ext/device/camb.pyPatch the relevant lmdeploy class method directly. Ensure the file is
imported in framework/lmdeploy_ext/device/__init__.py.
When needed: only when the model uses AWQ and the weight packing or scale layout differs from the current Ascend implementation.
File: framework/lmdeploy_ext/quants/ascend_awq.py
This file patches WeightOnlyQLinear, MergedAwqLinear, AwqLinear, and
QKVAwqLinear. Only modify if the new model's quantized checkpoint uses a
layout the current patches cannot handle.
Path A (new op):
get_layer_impl_builder() dispatcher updated in generic op_backend.pyvendor_ops_registry key in ops/llm.py exactly matches the decorated
function name in the vendor filekernels/dlinfer/__init__.pyPath B (vendor op_backend.py):
update_step_context() populates all fields the new model's
attn_metadata requiresPath C1 (graph buffers):
make_buffers_cudagraphfill_buffers_cudagraphupdate_context_cudagraphPath C2 (device patch):
device/__init__.pyPath C3 (quant patch):
ascend_awq.pyGeneral: