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