This Skill guides how to create a basic adapter for a new model so that it can run through the W8A8/W4A16 quantization process.
Scope
- Supported: Decoder-only LLM, understanding-type VLM (only processes the text/LLM backbone)
- Not supported: multimodal generation (such as Stable Diffusion/Flux/Wan), Encoder-only, non-Transformers
Core Workflow
1. Preparation
- Download the model: It is recommended to use
modelscope downloadto download non-weight files.- Example:
modelscope download --model <org>/<model> --local_dir ./models/<name> --exclude '*.safetensors'
- Example:
- Analyze the model: Read
config.jsonandmodeling_*.py, and confirm the structure and implementation.
2. Create the adapter
- Use the template:
- LLM:
assets/model_adapter_template.py - VLM:
assets/vlm_model_adapter_template.py
- LLM:
- Implement the interfaces: Implement
handle_dataset,init_model,generate_model_visit,generate_model_forward,enable_kv_cache。 - Key principles:
visitandforwardmust be strictly consistent.- For MoE models, it is recommended to unpack into pure linear layers.
- See:Adapter Implementation Guide
3. Register and install
- In
config/config.iniregister the model and entry point, and executebash install.sh。 - See:Adapter Registration Guide
4. Verify the adapter (required)
- The four-step verification must be performed: generate a test model -> full-fallback quantization -> verify that the full-fallback model is strictly consistent with the floating-point weights and can be fully loaded/saved -> verify that the actual quantization process works properly (including validation of description file rules).
- See:Adapter Verification Guide
Common Scripts
The scripts are located in the scripts/ directory:
scripts/step1_generate_test_model.pyscripts/step2_run_quantization.pyscripts/step3_verify_weights.pyscripts/step4_verify_quant_description.py