Huawei Cloud msModelSlim Model Analysis
Overview
This skill analyzes candidate models before adapter implementation for msModelSlim.
Architecture: Implementation Source Detection → Model Type Classification →
Structural Feature Analysis → Risk Assessment
Related Skills:
huawei-cloud-msmodelslim-model-adapt - Adapter creation based on analysis
results
Architecture Components
This skill involves the following cloud services and components:
- msModelSlim: Huawei Cloud's model quantization framework
- Transformers Library: Hugging Face Transformers for model loading
- ModelScope: Model download and management platform
- config.json: Model configuration file for analysis
Architecture Diagram:
┌─────────────────────────────────────────────────────────────┐
│ msModelSlim Model Analysis Skill │
├─────────────────────────────────────────────────────────────┤
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Model │───▶│ Source │───▶│ Structure │ │
│ │ Input │ │ Detection │ │ Analysis │ │
│ │ (config) │ │ │ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Type │ │ MoE │ │ Risk │ │
│ │ Classification│ │ Assessment │ │ Assessment │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘
Use Cases
Typical Problem Scenarios:
- Assessing model adaptation feasibility before creating msModelSlim adapters
- Analyzing model structure and type classification
- Evaluating MoE compatibility for quantization
- Determining if a model can be quantized with msModelSlim
- Identifying potential risks before adapter development
Typical User Phrases:
- "Analyze my model for msModelSlim compatibility"
- "Check if this model can be quantized"
- "Evaluate MoE fused weights risk"
- "Assess model adaptation feasibility"
- "Analyze model structure for quantization"
- "AnalysisModelmsModelSlim"
- "ModelQuantization"
- "CheckMoE"
Scope
Supported:
- Decoder-only LLM
- VLM text backbone analysis (LLM/text path only)
Not supported:
- Non-transformers implementations
- Multimodal generation models (image/video/audio generation)
Required Input
Model path or model repository identifier
config.json
Optional: modeling_*.py, model.safetensors.index.json in the model
directory
If files are missing locally:
- Download non-weight files using:
modelscope download --model <org>/<model> --local_dir ./models/<name> --exclude '*.safetensors'
- Read
config.json and modeling_*.py from the download directory as input
for analysis.
Hard Requirement: Parse Implementation Source First
Must complete before any structural analysis. Agent should manually parse
following these steps:
Read config.json:
- Get
model_type
- Get
auto_map (if present)
Try parsing from transformers:
- Check if
transformers library supports the model_type.
- Check if path exists:
transformers/models/<model_type>/modeling_<model_type>.py.
- If exists, record as
transformers implementation.
If not parsed, try model-local implementation:
- Check if files pointed by
auto_map exist in the model directory.
- Check if
modeling_*.py files exist in the model directory.
- If exists, record as
model-local implementation.
If neither path available:
- Stop analysis.
- Request user to provide readable model implementation code.
Minimum Workflow
Parse implementation source (complete hard requirement above).
Determine model type, structural differences, and connections:
- Type: Pure LLM / Multimodal understanding / Multimodal generation
- Compare with common Qwen2-like LLMs, record special structural designs
(e.g., MoE, non-standard attention, SSM/hybrid blocks, additional heads
or parallel branches)
- Check special structure connections (location, dependencies,
serial/parallel/residual connections, impact on backbone traversal)
Identify structural features:
- Decoder layer class, attention/MLP module naming, forward signature
Determine features affecting adaptation:
- Layer traversal path and order
- Whether layer-by-layer loading is needed
- MoE fused expert weight risk
- Quantized model dequantization script risk
- MTP structure implementation availability and weight handling risk
Output structured analysis results (refer to template below).
Provide next steps:
- Proceed to adapter creation workflow
- Or block and explain what user needs to provide
Model Type, Structural Differences, and Connection Determination
(relative to common Qwen2)
- Pure LLM: Text token input only, backbone is decoder-only language model.
- Multimodal understanding: Contains vision/audio encoders, but generation
path centers on text backbone; only text portion can be analyzed and adapted.
- Multimodal generation: Core goal is image/video/audio generation; current
workflow does not support, should block and explain reason directly.
- Structural differences only need to record "existence + impact direction",
no deep implementation details required.
- Connection relationships should record at minimum: which stage special
structure is located in backbone, which modules it connects to, connection
type (serial/parallel/residual), and impact on traversal/forward alignment.
MoE Layout Determination
- Non-fused MoE: Experts expanded by module/list (commonly each expert has
its own
gate/up/down linear layers).
- Fused MoE: Multiple expert weights packaged as tensor parameters, no
longer independent linear layers.
- If any of
gate/up/down stored in [..., num_experts, ...] or
[num_experts, ...] form, treat as "fused".
- Three-dimensional expert weights (e.g., gate/up/down each fused into 3D
parameters) uniformly classified as
MoE fused, with "may need unpack"
marked in report.
Required Output: Analysis Report
Agent should directly generate analysis report (Markdown format), must include
following elements. Refer to template below:
# Analysis Report
## Model Identification
- Model Path/Repository: {model_path}
- `model_type`: {model_type}
- `architectures`: {architectures}
## Implementation Source Analysis
- Result: `transformers` | `model-local` | `unsupported`
- Basis:
- Resolved file path: {path}
- Related configuration fields (`model_type`, `auto_map`): {details}
## Model Features and Specifications
- Hidden size: {hidden_size}
- Number of layers: {num_layers}
- Attention heads / KV heads: {num_heads} / {num_kv_heads}
- Analyze only VLM text portion: Yes/No
## Model Type, Structural Differences and Connections
- Model type: Pure LLM | Multimodal understanding | Multimodal generation
- Special structures vs common Qwen2: {special_structures}
- Special structure connections: {special_structure_connections}
- Impact on adaptation workflow: {structure_impact}
## Layer-by-Layer Loading Assessment
- Need layer-by-layer loading: Yes/No
- Reason: {reason}
- Constraints (memory/runtime environment): {constraints}
## MoE Assessment
- Contains MoE: Yes/No
- Layout type: No MoE | Non-fused MoE | Fused MoE
- Suspected fused keys/modules: {keys}
- Expert weight form: Independent linear layers | Packaged tensors
- Needs unpack: Yes/No
## Adaptation Impact Points
- Decoder traversal path: {traversal_path}
- Attention module naming: {attn_module}
- MLP module naming: {mlp_module}
- `visit/forward` strict alignment points: {alignment_points}
## Quantization and MTP Risk Assessment
- Model already quantized: Yes/No
- Quantization determination basis: {quant_evidence}
- Dequantization script provided: Yes/No
- Dequantization script status: {dequant_status}
- MTP structure exists: Yes/No
- MTP implementation code accessibility: Accessible/Not accessible
- MTP risk description: {mtp_risk}
## Risks and Next Steps
- Risk level: Low | Medium | High
- Blockers: {blockers}
- Recommended next steps:
- Proceed to adapter creation workflow
- Or request user to provide implementation code
Risk Identification and User Communication Requirements (Mandatory)
If identified as "model already quantized", must mark "missing dequantization
script" as blocker, explicitly requiring user to actively provide
dequantization script before continuing adaptation.
If MTP structure identified but implementation code inaccessible, must
explicitly inform:
- Agent may not be able to fully implement MTP structure adaptation;
- To continue, user needs to copy MTP-related weights themselves (map
according to user-side implementation).
When at least one of above two risk types hits, risk level must not be
lower than "Medium".
Pass/Fail Criteria
- Pass: Implementation source is
transformers or model-local, model
type is pure LLM or multimodal understanding, and report is complete; if
quantization/MTP risks hit, clear user action requirements given in report.
- Fail: Source not parsed, unsupported implementation type, determined as
multimodal generation model, or hits "quantized model without dequantization
script" blocking condition.
Enhanced Features
Automated Compatibility Checker
This skill includes an automated model compatibility checker that scans model
architectures before migration:
Features:
- Migration Blocker Detection: Identifies unsupported operators, custom
layers, and framework-specific features
- Early Warning System: Provides early warning for known issues with
suggested workarounds
- Compatibility Score: Generates compatibility score with detailed breakdown
- Operator Coverage Analysis: Reports operator coverage rate for Ascend NPU
support
Compatibility Check Categories:
| Category |
Check Items |
| Operator Support |
Transformer layers, attention, normalization |
| Framework Features |
Custom ops, dynamic shapes, control flow |
| Weight Formats |
Safetensors, PyTorch, HF format compatibility |
| Special Structures |
MoE, MTP, hybrid architectures |
Output Format:
## Compatibility Check Result
- Overall Score: XX/100
- Passed: X/XX checks
- Warning: X items require attention
- Blockers: X items preventing migration
### Detailed Results
| Check Item | Status | Details |
|-------------------|------------|-----------------------------------|
| Operator coverage | ✓ Pass | 95% of operators supported |
| Custom layers | ⚠️ Warning | 2 custom ops need AscendC impl |
| Weight format | ✓ Pass | Standard Hugging Face format |
Reference Documents
- Analysis Checklist - Analysis verification
checklist
- Acceptance Criteria - Functional
acceptance criteria
- Verification Method - Verification approach
- Troubleshooting - Common issues and solutions
Prerequisites
- transformers >= 4.40.0 installed
- Model code available for analysis
- Basic understanding of model structure
Analysis Workflow
The analysis workflow follows these steps:
- Parse model configuration (
config.json)
- Determine implementation source (transformers or model-local)
- Analyze model architecture and structural features
- Assess MoE layout and fused weight risks
- Generate structured analysis report
- Provide adaptation recommendations
Parameter Reference
| Parameter |
Description |
Required |
| model |
Model name or path |
Yes |
| output |
Analysis report output path |
No |
| detailed |
Output detailed information |
No |
1---
2name: huawei-cloud-msmodelslim-model-analysis
3description: |
4 Analyze candidate models before adapter implementation. Determine model
5 implementation source (transformers or model-local), structural features,
6 layer-by-layer loading requirements, and MoE fused weight risks. Use this
7 skill when the user wants to: (1) assess model adaptation feasibility before
8 creating msModelSlim adapters, (2) analyze model structure and type
9 classification, (3) evaluate MoE compatibility for quantization. Trigger:
10 user mentions "model analysis", "msModelSlim", "adapter", "transformers",
11 "MoE", "layer-by-layer", "model assessment", "feasibility", "模型分析",
12 "适配可行性", "模型评估", "MoE分析"
13compatibility:
14 - transformers >= 4.40.0
15tags: [msModelSlim, analysis, model, MoE]
16allowed-tools:
17 - python3
18---
19
20# Huawei Cloud msModelSlim Model Analysis
21
22## Overview
23
24This skill analyzes candidate models before adapter implementation for msModelSlim.
25
26**Architecture**: Implementation Source Detection → Model Type Classification →
27Structural Feature Analysis → Risk Assessment
28
29**Related Skills**:
30
31- `huawei-cloud-msmodelslim-model-adapt` - Adapter creation based on analysis
32 results
33
34## Architecture Components
35
36This skill involves the following cloud services and components:
37
38- **msModelSlim**: Huawei Cloud's model quantization framework
39- **Transformers Library**: Hugging Face Transformers for model loading
40- **ModelScope**: Model download and management platform
41- **config.json**: Model configuration file for analysis
42
43**Architecture Diagram:**
44
45```text
46┌─────────────────────────────────────────────────────────────┐
47│ msModelSlim Model Analysis Skill │
48├─────────────────────────────────────────────────────────────┤
49│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
50│ │ Model │───▶│ Source │───▶│ Structure │ │
51│ │ Input │ │ Detection │ │ Analysis │ │
52│ │ (config) │ │ │ │ │ │
53│ └──────────────┘ └──────────────┘ └──────────────┘ │
54│ │ │ │ │
55│ ▼ ▼ ▼ │
56│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
57│ │ Type │ │ MoE │ │ Risk │ │
58│ │ Classification│ │ Assessment │ │ Assessment │ │
59│ └──────────────┘ └──────────────┘ └──────────────┘ │
60└─────────────────────────────────────────────────────────────┘
61```
62
63## Use Cases
64
65**Typical Problem Scenarios:**
66
67- Assessing model adaptation feasibility before creating msModelSlim adapters
68- Analyzing model structure and type classification
69- Evaluating MoE compatibility for quantization
70- Determining if a model can be quantized with msModelSlim
71- Identifying potential risks before adapter development
72
73**Typical User Phrases:**
74
75- "Analyze my model for msModelSlim compatibility"
76- "Check if this model can be quantized"
77- "Evaluate MoE fused weights risk"
78- "Assess model adaptation feasibility"
79- "Analyze model structure for quantization"
80- "AnalysisModelmsModelSlim"
81- "ModelQuantization"
82- "CheckMoE"
83
84## Scope
85
86**Supported:**
87
88- Decoder-only LLM
89- VLM text backbone analysis (LLM/text path only)
90
91**Not supported:**
92
93- Non-transformers implementations
94- Multimodal generation models (image/video/audio generation)
95
96## Required Input
97
98- Model path or model repository identifier
99- `config.json`
100- Optional: `modeling_*.py`, `model.safetensors.index.json` in the model
101 directory
102- If files are missing locally:
103
104 - Download non-weight files using:
105 `modelscope download --model <org>/<model> --local_dir ./models/<name>
106 --exclude '*.safetensors'`
107 - Read `config.json` and `modeling_*.py` from the download directory as input
108 for analysis.
109
110## Hard Requirement: Parse Implementation Source First
111
112Must complete before any structural analysis. Agent should manually parse
113following these steps:
114
1151. **Read `config.json`**:
116
117 - Get `model_type`
118 - Get `auto_map` (if present)
119
1202. **Try parsing from transformers**:
121
122 - Check if `transformers` library supports the `model_type`.
123 - Check if path exists:
124 `transformers/models/<model_type>/modeling_<model_type>.py`.
125 - If exists, record as `transformers` implementation.
126
1273. **If not parsed, try model-local implementation**:
128
129 - Check if files pointed by `auto_map` exist in the model directory.
130 - Check if `modeling_*.py` files exist in the model directory.
131 - If exists, record as `model-local` implementation.
132
1334. **If neither path available**:
134
135 - Stop analysis.
136 - Request user to provide readable model implementation code.
137
138## Minimum Workflow
139
1401. Parse implementation source (complete hard requirement above).
141
1422. Determine model type, structural differences, and connections:
143
144 - Type: Pure LLM / Multimodal understanding / Multimodal generation
145 - Compare with common Qwen2-like LLMs, record special structural designs
146 (e.g., MoE, non-standard attention, SSM/hybrid blocks, additional heads
147 or parallel branches)
148 - Check special structure connections (location, dependencies,
149 serial/parallel/residual connections, impact on backbone traversal)
150
1513. Identify structural features:
152
153 - Decoder layer class, attention/MLP module naming, forward signature
154
1554. Determine features affecting adaptation:
156
157 - Layer traversal path and order
158 - Whether layer-by-layer loading is needed
159 - MoE fused expert weight risk
160 - Quantized model dequantization script risk
161 - MTP structure implementation availability and weight handling risk
162
1635. Output structured analysis results (refer to template below).
164
1656. Provide next steps:
166
167 - Proceed to adapter creation workflow
168 - Or block and explain what user needs to provide
169
170### Model Type, Structural Differences, and Connection Determination
171
172(relative to common Qwen2)
173
174- **Pure LLM**: Text token input only, backbone is decoder-only language model.
175- **Multimodal understanding**: Contains vision/audio encoders, but generation
176 path centers on text backbone; only text portion can be analyzed and adapted.
177- **Multimodal generation**: Core goal is image/video/audio generation; current
178 workflow does not support, should block and explain reason directly.
179- Structural differences only need to record "existence + impact direction",
180 no deep implementation details required.
181- Connection relationships should record at minimum: which stage special
182 structure is located in backbone, which modules it connects to, connection
183 type (serial/parallel/residual), and impact on traversal/forward alignment.
184
185### MoE Layout Determination
186
187- **Non-fused MoE**: Experts expanded by module/list (commonly each expert has
188 its own `gate/up/down` linear layers).
189- **Fused MoE**: Multiple expert weights packaged as tensor parameters, no
190 longer independent linear layers.
191- If any of `gate/up/down` stored in `[..., num_experts, ...]` or
192 `[num_experts, ...]` form, treat as "fused".
193- Three-dimensional expert weights (e.g., gate/up/down each fused into 3D
194 parameters) uniformly classified as `MoE fused`, with "may need unpack"
195 marked in report.
196
197## Required Output: Analysis Report
198
199Agent should directly generate analysis report (Markdown format), must include
200following elements. Refer to template below:
201
202```markdown
203# Analysis Report
204
205## Model Identification
206- Model Path/Repository: {model_path}
207- `model_type`: {model_type}
208- `architectures`: {architectures}
209
210## Implementation Source Analysis
211- Result: `transformers` | `model-local` | `unsupported`
212- Basis:
213 - Resolved file path: {path}
214 - Related configuration fields (`model_type`, `auto_map`): {details}
215
216## Model Features and Specifications
217- Hidden size: {hidden_size}
218- Number of layers: {num_layers}
219- Attention heads / KV heads: {num_heads} / {num_kv_heads}
220- Analyze only VLM text portion: Yes/No
221
222## Model Type, Structural Differences and Connections
223- Model type: Pure LLM | Multimodal understanding | Multimodal generation
224- Special structures vs common Qwen2: {special_structures}
225- Special structure connections: {special_structure_connections}
226- Impact on adaptation workflow: {structure_impact}
227
228## Layer-by-Layer Loading Assessment
229- Need layer-by-layer loading: Yes/No
230- Reason: {reason}
231- Constraints (memory/runtime environment): {constraints}
232
233## MoE Assessment
234- Contains MoE: Yes/No
235- Layout type: No MoE | Non-fused MoE | Fused MoE
236- Suspected fused keys/modules: {keys}
237- Expert weight form: Independent linear layers | Packaged tensors
238- Needs unpack: Yes/No
239
240## Adaptation Impact Points
241- Decoder traversal path: {traversal_path}
242- Attention module naming: {attn_module}
243- MLP module naming: {mlp_module}
244- `visit/forward` strict alignment points: {alignment_points}
245
246## Quantization and MTP Risk Assessment
247- Model already quantized: Yes/No
248- Quantization determination basis: {quant_evidence}
249- Dequantization script provided: Yes/No
250- Dequantization script status: {dequant_status}
251- MTP structure exists: Yes/No
252- MTP implementation code accessibility: Accessible/Not accessible
253- MTP risk description: {mtp_risk}
254
255## Risks and Next Steps
256- Risk level: Low | Medium | High
257- Blockers: {blockers}
258- Recommended next steps:
259 - Proceed to adapter creation workflow
260 - Or request user to provide implementation code
261```
262
263### Risk Identification and User Communication Requirements (Mandatory)
264
265- If identified as "model already quantized", must mark "missing dequantization
266 script" as blocker, explicitly requiring user to actively provide
267 dequantization script before continuing adaptation.
268- If MTP structure identified but implementation code inaccessible, must
269 explicitly inform:
270
271 - Agent may not be able to fully implement MTP structure adaptation;
272 - To continue, user needs to copy MTP-related weights themselves (map
273 according to user-side implementation).
274
275- When at least one of above two risk types hits, `risk level` must not be
276 lower than "Medium".
277
278## Pass/Fail Criteria
279
280- **Pass**: Implementation source is `transformers` or `model-local`, model
281 type is pure LLM or multimodal understanding, and report is complete; if
282 quantization/MTP risks hit, clear user action requirements given in report.
283- **Fail**: Source not parsed, unsupported implementation type, determined as
284 multimodal generation model, or hits "quantized model without dequantization
285 script" blocking condition.
286
287## Enhanced Features
288
289### Automated Compatibility Checker
290
291This skill includes an automated model compatibility checker that scans model
292architectures before migration:
293
294**Features:**
295
296- **Migration Blocker Detection**: Identifies unsupported operators, custom
297 layers, and framework-specific features
298- **Early Warning System**: Provides early warning for known issues with
299 suggested workarounds
300- **Compatibility Score**: Generates compatibility score with detailed breakdown
301- **Operator Coverage Analysis**: Reports operator coverage rate for Ascend NPU
302 support
303
304**Compatibility Check Categories:**
305
306| Category | Check Items |
307|--------------------|----------------------------------------------|
308| Operator Support | Transformer layers, attention, normalization |
309| Framework Features | Custom ops, dynamic shapes, control flow |
310| Weight Formats | Safetensors, PyTorch, HF format compatibility|
311| Special Structures | MoE, MTP, hybrid architectures |
312
313**Output Format:**
314
315```markdown
316## Compatibility Check Result
317- Overall Score: XX/100
318- Passed: X/XX checks
319- Warning: X items require attention
320- Blockers: X items preventing migration
321
322### Detailed Results
323| Check Item | Status | Details |
324|-------------------|------------|-----------------------------------|
325| Operator coverage | ✓ Pass | 95% of operators supported |
326| Custom layers | ⚠️ Warning | 2 custom ops need AscendC impl |
327| Weight format | ✓ Pass | Standard Hugging Face format |
328```
329
330## Reference Documents
331
332- [Analysis Checklist](references/analysis_checklist.md) - Analysis verification
333 checklist
334- [Acceptance Criteria](references/acceptance-criteria.md) - Functional
335 acceptance criteria
336- [Verification Method](references/verification-method.md) - Verification approach
337- [Troubleshooting](references/troubleshooting.md) - Common issues and solutions
338
339## Prerequisites
340
341- transformers >= 4.40.0 installed
342- Model code available for analysis
343- Basic understanding of model structure
344
345## Analysis Workflow
346
347The analysis workflow follows these steps:
348
3491. Parse model configuration (`config.json`)
3502. Determine implementation source (transformers or model-local)
3513. Analyze model architecture and structural features
3524. Assess MoE layout and fused weight risks
3535. Generate structured analysis report
3546. Provide adaptation recommendations
355
356## Parameter Reference
357
358| Parameter | Description | Required |
359|------------|--------------------------------|----------|
360| model | Model name or path | Yes |
361| output | Analysis report output path | No |
362| detailed | Output detailed information | No |