Analyze candidate models before adapter implementation. Determine model implementation source (transformers or model-local), structural features, layer-by-la...
Coding
huawei-cloud-msmodelslim-model-adapt
Try itCreate basic Transformers model adapters for msModelSlim. Implements required interfaces and completes a four-step verification workflow: generate test model...
What it does
Create basic Transformers model adapters for msModelSlim. Implements required interfaces and completes a four-step verification workflow: generate test model -> full fallback quantization -> weight verification -> quantization description validation. Use this skill when the user wants to: (1) create msModelSlim adapters for decoder-only LLM, (2) adapt understanding VLM text backbones for quantization, (3) implement W8A8/W4A16 quantization workflow for new models. Trigger: user mentions "msModelSlim", "adapter", "model adapter","quantization", "W8A8","W4A16", "transformers", "LLM", "VLM", "adapter creation", "适配器","模型适配", "量化", "模型适配器", "LLM量化"
The skill document
Huawei Cloud msModelSlim Model Adapter
Overview
This skill guides how to create basic adapters for new models to run W8A8/W4A16 quantization workflows in msModelSlim.
Architecture: Model Analysis -> Adapter Creation -> Registration -> Verification (4 Steps)
Related Skills:
huawei-cloud-msmodelslim-model-analysis- Model structure analysis before adapter implementationhuawei-cloud-ascend-profiler-db-explorer- Optional: Performance analysis after deployment
Scope
Supported:
- Decoder-only LLM
- Understanding VLM (text/LLM backbone only)
Not supported:
- Multimodal generation (Stable Diffusion/Flux/Wan)
- Encoder-only models
- Non-Transformers architectures
Architecture
┌─────────────────────────────────────────────────────────────┐
│ msModelSlim Model Adapter Skill │
├─────────────────────────────────────────────────────────────┤
│ ┌──────────────────┐ ┌──────────────────────────────┐ │
│ │ Model Analysis │───▶│ Adapter Creation │ │
│ │ - config.json │ │ - LLM Adapter Template │ │
│ │ - modeling_*.py│ │ - VLM Adapter Template │ │
│ └──────────────────┘ │ - Required Interfaces │ │
│ └──────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────┐ │
│ │ Registration │ │
│ │ & Installation │ │
│ └──────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Verification (4 Steps) │ │
│ │ 1. Generate Test Model → 2. Full Fallback Quant │ │
│ │ 3. Weight Verification → 4. Quant Description │ │
│ └──────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Architecture Components
This skill involves the following cloud services and components:
- msModelSlim: Huawei Cloud's model quantization framework for efficient model compression
- Transformers Library: Hugging Face Transformers for model loading and processing
- ModelScope: Model download and management platform
- Ascend NPU: Target hardware for quantized model deployment
Use Cases
Typical Problem Scenarios:
- Need to deploy LLM models with reduced memory footprint on Ascend NPU
- Want to optimize inference speed without significant accuracy loss
- Migrating models that don't have built-in msModelSlim support
- Need W8A8/W4A16 quantization for decoder-only LLM or VLM text backbones
Typical User Phrases:
- "How to quantize my custom LLM model for Ascend?"
- "Create msModelSlim adapter for Qwen model"
- "Implement W4A16 quantization workflow"
- "Adapt my VLM text backbone for quantization"
- "How to add quantization support for new models?"
Core Workflow
1. Preparation
- Download Model: Recommended to use
modelscope downloadfor non-weight files.- Example:
modelscope download --model / --local_dir ./models/ --exclude '*.safetensors'
- Example:
- Analyze Model: Read
config.jsonandmodeling_*.pyto confirm structure and implementation.- See: Model Analysis Guide
2. Create Adapter
- Use Templates:
- LLM:
assets/model_adapter_template.py - VLM:
assets/vlm_model_adapter_template.py
- LLM:
- Implement Interfaces: Implement
handle_dataset,init_model,generate_model_visit,generate_model_forward,enable_kv_cache. - Key Principles:
visitandforwardmust be strictly consistent.- MoE models recommended to unpack to pure linear layers.
- See: Implementation Guide
3. Registration & Installation
- Register model and entry in
config/config.ini, then executebash install.sh. - See: Registration Guide
4. Verify Adapter (Required)
- Must execute four-step verification: Generate test model -> Full fallback quantization -> Verify full fallback model matches float weights exactly and can load/save completely -> Verify actual quantization workflow works (including description file rule validation).
- See: Verification Guide
Common Scripts
Scripts located in scripts/ directory:
scripts/step1_generate_test_model.pyscripts/step2_run_quantization.pyscripts/step3_verify_weights.pyscripts/step4_verify_quant_description.py
Prerequisites
System Requirements
- Python 3.8+
- transformers >= 4.40.0
- msmodelslim >= 1.0.0
Environment Check
Prerequisite check: Python3 + transformers + msmodelslim required
python3 --version # Python3 >= 3.8 python3 -c "import transformers; print('OK')" # Transformers library python3 -c "import msmodelslim; print('OK')" # msModelSlim libraryIf not installed:
pip3 install --user transformers msmodelslim
Reference Documents
| Document | Description |
|---|---|
| Model Analysis Guide | Model structure analysis guide |
| Implementation Guide | Adapter implementation instructions |
| Registration Guide | Registration and installation guide |
| Verification Guide | Four-step verification workflow |
| Interface Checklist | Required interface implementation checklist |
| Core Workflow | Core workflow documentation |
| Acceptance Criteria | Functional acceptance criteria |
| Troubleshooting | Common issues and solutions |
Requirements
- transformers >= 4.40.0 installed
- msmodelslim >= 1.0.0 installed
- Transformers model to be adapted
- Understanding of target quantization scheme (W8A8/W4A16)
Core Commands
# Create model adapter
python3 scripts/create_adapter.py \
--model Qwen2-7B \
--quantization W8A8
# Run four-step verification
python3 scripts/verify_adapter.py --adapter ./adapter.py
Parameter Confirmation
| Parameter | Description | Required |
|---|---|---|
| model | Model name or path | Yes |
| quantization | Quantization scheme (W8A8/W4A16) | Yes |
| output | Adapter output path | No |
Related skills
Migrate vision/detection/segmentation small models to Ascend NPU, covering the full workflow: model structure analysis, migration verification, performance p...
Deploy and test LLM, VL, Embedding, and Rerank models on Huawei Cloud Ascend 910B DevServer with single- or dual-node topologies.
Use when routing Alibaba Cloud Model Studio requests to the right local skill (Qwen text, coder, deep research, image, video, audio, search and multimodal sk...
Route Alibaba Cloud Model Studio requests to the right local skill (Qwen Image, Qwen Image Edit, Wan Video, Wan R2V, Qwen TTS, Qwen ASR and advanced TTS vari...
Query Huawei Cloud MaaS (Model as a Service) tokens usage statistics, including total tokens, prompt tokens, completion tokens, total requests, and total errors. Supports preset service, my service, and custom endpoint with time range queries (last 7/14/30 days or custom). Data source is MaaS ShowStatistics API, consistent with console. Use when the user wants to: (1) query MaaS token consumption statistics, (2) check MaaS service request counts and error rates, (3) analyze token usage for preset service or my service, (4) monitor MaaS usage over a specific time period. Triggers include: "MaaS", "Model as a Service", "tokens usage", "token consumption", "request count", "error count", "MaaS usage", "preset service usage", "completion tokens", "prompt tokens", "MaaS statistics", "模型服务", "令牌用量", "token统计", "token用量", "词元用量", "请求次数", "MaaS监控", "华为云MaaS"
More from huaweicloud-skills-team
Browse all skillsManage Huawei Ascend NPUs with natural language commands that translate to npu-smi, locally or over SSH.
Deploy and test LLM, VL, Embedding, and Rerank models on Huawei Cloud Ascend 910B DevServer with single- or dual-node topologies.
Read-only queries against Huawei Cloud resources for inventory, verification, and parameter discovery.
Query Huawei Cloud IAM resources (users, groups, policies, agencies, AK/SK, MFA, security settings) read-only via local Python SDK.
Deploy the OpenClaw AI Agent platform on Huawei Cloud Flexus L Instance and configure models and channels via COC.
One-click deploy Hermes AI Agent platform on Huawei Cloud Flexus L instances with model and channel configuration.