huawei-cloud-msmodelslim-model-analysis
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHuawei Cloud msModelSlim Model Analysis
华为云msModelSlim模型分析
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:
- - Adapter creation based on analysis results
huawei-cloud-msmodelslim-model-adapt
本技能用于在为msModelSlim实现适配器前分析候选模型。
架构:实现来源检测 → 模型类型分类 → 结构特征分析 → 风险评估
相关技能:
- - 基于分析结果创建适配器
huawei-cloud-msmodelslim-model-adapt
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:
text
┌─────────────────────────────────────────────────────────────┐
│ msModelSlim Model Analysis Skill │
├─────────────────────────────────────────────────────────────┤
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Model │───▶│ Source │───▶│ Structure │ │
│ │ Input │ │ Detection │ │ Analysis │ │
│ │ (config) │ │ │ │ │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Type │ │ MoE │ │ Risk │ │
│ │ Classification│ │ Assessment │ │ Assessment │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────────────┘本技能涉及以下云服务和组件:
- msModelSlim:华为云的模型量化框架
- Transformers Library:用于模型加载的Hugging Face Transformers
- ModelScope:模型下载与管理平台
- config.json:用于分析的模型配置文件
架构图:
text
┌─────────────────────────────────────────────────────────────┐
│ 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"
典型问题场景:
- 在创建msModelSlim适配器前评估模型适配可行性
- 分析模型结构与类型分类
- 评估MoE与量化的兼容性
- 判断模型是否可通过msModelSlim进行量化
- 在适配器开发前识别潜在风险
典型用户表述:
- "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)
支持:
- 仅解码器架构LLM
- VLM文本主干分析(仅LLM/文本路径)
不支持:
- 非transformers实现的模型
- 多模态生成模型(图像/视频/音频生成)
Required Input
所需输入
-
Model path or model repository identifier
-
config.json -
Optional:,
modeling_*.pyin the model directorymodel.safetensors.index.json -
If files are missing locally:
- Download non-weight files using:
modelscope download --model <org>/<model> --local_dir ./models/<name> --exclude '*.safetensors' - Read and
config.jsonfrom the download directory as input for analysis.modeling_*.py
- Download non-weight files using:
-
模型路径或模型仓库标识符
-
config.json -
可选:模型目录中的、
modeling_*.pymodel.safetensors.index.json -
若本地文件缺失:
- 使用以下命令下载非权重文件:
modelscope download --model <org>/<model> --local_dir ./models/<name> --exclude '*.safetensors' - 从下载目录读取和
config.json作为分析输入modeling_*.py
- 使用以下命令下载非权重文件:
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 (if present)
auto_map
- Get
-
Try parsing from transformers:
- Check if library supports the
transformers.model_type - Check if path exists:
.
transformers/models/<model_type>/modeling_<model_type>.py - If exists, record as implementation.
transformers
- Check if
-
If not parsed, try model-local implementation:
- Check if files pointed by exist in the model directory.
auto_map - Check if files exist in the model directory.
modeling_*.py - If exists, record as implementation.
model-local
- Check if files pointed by
-
If neither path available:
- Stop analysis.
- Request user to provide readable model implementation code.
必须在任何结构分析前完成。Agent需按照以下步骤手动解析:
-
读取:
config.json- 获取
model_type - 获取(若存在)
auto_map
- 获取
-
尝试从transformers解析:
- 检查库是否支持该
transformersmodel_type - 检查路径是否存在:
transformers/models/<model_type>/modeling_<model_type>.py - 若存在,记录为实现
transformers
- 检查
-
若解析失败,尝试模型本地实现:
- 检查指向的文件是否存在于模型目录中
auto_map - 检查模型目录中是否存在文件
modeling_*.py - 若存在,记录为实现
model-local
- 检查
-
若两种路径均不可用:
- 停止分析
- 请求用户提供可读的模型实现代码
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
-
解析实现来源(完成上述硬性要求)
-
确定模型类型、结构差异与关联:
- 类型:纯LLM / 多模态理解 / 多模态生成
- 与常见Qwen2类LLM对比,记录特殊结构设计(如MoE、非标准注意力、SSM/混合模块、额外头部或并行分支)
- 检查特殊结构的关联(位置、依赖关系、串行/并行/残差连接、对主干遍历的影响)
-
识别结构特征:
- 解码器层类、注意力/MLP模块命名、前向传播签名
-
确定影响适配的特征:
- 层遍历路径与顺序
- 是否需要分层加载
- MoE融合专家权重风险
- 量化模型反量化脚本风险
- MTP结构实现可用性与权重处理风险
-
输出结构化分析结果(参考下方模板)
-
提供下一步建议:
- 进入适配器创建工作流
- 或说明需要用户补充的内容
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.
(相对于常见Qwen2模型)
- 纯LLM:仅接受文本token输入,主干为仅解码器语言模型
- 多模态理解:包含视觉/音频编码器,但生成路径以文本主干为核心;仅可分析与适配文本部分
- 多模态生成:核心目标为图像/视频/音频生成;当前工作流不支持,需直接阻断并说明原因
- 结构差异仅需记录“存在性 + 影响方向”,无需深入实现细节
- 关联关系至少需记录:特殊结构在主干中的所处阶段、连接的模块、连接类型(串行/并行/残差)、对遍历/前向对齐的影响
MoE Layout Determination
MoE布局确定
- Non-fused MoE: Experts expanded by module/list (commonly each expert has
its own linear layers).
gate/up/down - Fused MoE: Multiple expert weights packaged as tensor parameters, no longer independent linear layers.
- If any of stored in
gate/up/downor[..., num_experts, ...]form, treat as "fused".[num_experts, ...] - Three-dimensional expert weights (e.g., gate/up/down each fused into 3D
parameters) uniformly classified as , with "may need unpack" marked in report.
MoE fused
- 非融合MoE:专家通过模块/列表扩展(通常每个专家拥有独立的线性层)
gate/up/down - 融合MoE:多个专家权重打包为张量参数,不再是独立线性层
- 若中任意一项以
gate/up/down或[..., num_experts, ...]形式存储,则视为“融合型”[num_experts, ...] - 三维专家权重(如gate/up/down各自融合为3D参数)统一归类为,并在报告中标记“可能需要解包”
MoE fused
Required Output: Analysis Report
必需输出:分析报告
Agent should directly generate analysis report (Markdown format), must include
following elements. Refer to template below:
markdown
undefinedAgent需直接生成分析报告(Markdown格式),必须包含以下元素。参考下方模板:
markdown
undefinedAnalysis Report
分析报告
Model Identification
模型标识
- Model Path/Repository: {model_path}
- : {model_type}
model_type - : {architectures}
architectures
- 模型路径/仓库: {model_path}
- : {model_type}
model_type - : {architectures}
architectures
Implementation Source Analysis
实现来源分析
- Result: |
transformers|model-localunsupported - Basis:
- Resolved file path: {path}
- Related configuration fields (,
model_type): {details}auto_map
- 结果: |
transformers|model-localunsupported - 依据:
- 解析的文件路径: {path}
- 相关配置字段(,
model_type): {details}auto_map
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
- 隐藏层大小: {hidden_size}
- 层数: {num_layers}
- 注意力头数/KV头数: {num_heads} / {num_kv_heads}
- 仅分析VLM文本部分: 是/否
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}
- 模型类型: 纯LLM | 多模态理解 | 多模态生成
- 与常见Qwen2的特殊结构差异: {special_structures}
- 特殊结构关联: {special_structure_connections}
- 对适配工作流的影响: {structure_impact}
Layer-by-Layer Loading Assessment
分层加载评估
- Need layer-by-layer loading: Yes/No
- Reason: {reason}
- Constraints (memory/runtime environment): {constraints}
- 需要分层加载: 是/否
- 原因: {reason}
- 约束条件(内存/运行环境): {constraints}
MoE Assessment
MoE评估
- 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
- 包含MoE: 是/否
- 布局类型: 无MoE | 非融合MoE | 融合MoE
- 疑似融合的键/模块: {keys}
- 专家权重形式: 独立线性层 | 打包张量
- 需要解包: 是/否
Adaptation Impact Points
适配影响点
- Decoder traversal path: {traversal_path}
- Attention module naming: {attn_module}
- MLP module naming: {mlp_module}
- strict alignment points: {alignment_points}
visit/forward
- 解码器遍历路径: {traversal_path}
- 注意力模块命名: {attn_module}
- MLP模块命名: {mlp_module}
- 严格对齐点: {alignment_points}
visit/forward
Quantization and MTP Risk Assessment
量化与MTP风险评估
- 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}
- 模型已量化: 是/否
- 量化判定依据: {quant_evidence}
- 提供反量化脚本: 是/否
- 反量化脚本状态: {dequant_status}
- 存在MTP结构: 是/否
- MTP实现代码可访问性: 可访问/不可访问
- MTP风险描述: {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
undefined- 风险等级: 低 | 中 | 高
- 阻塞项: {blockers}
- 建议下一步操作:
- 进入适配器创建工作流
- 或请求用户提供实现代码
undefinedRisk 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,must not be lower than "Medium".
risk level
-
若识别到“模型已量化”,必须将“缺失反量化脚本”标记为阻塞项,明确要求用户主动提供反量化脚本后才能继续适配
-
若识别到MTP结构但实现代码不可访问,必须明确告知:
- Agent可能无法完整实现MTP结构适配
- 如需继续,用户需自行复制MTP相关权重(根据用户侧实现映射)
-
当上述两种风险类型中至少一种出现时,不得低于“中”
风险等级
Pass/Fail Criteria
通过/失败判定标准
- Pass: Implementation source is or
transformers, model type is pure LLM or multimodal understanding, and report is complete; if quantization/MTP risks hit, clear user action requirements given in report.model-local - Fail: Source not parsed, unsupported implementation type, determined as multimodal generation model, or hits "quantized model without dequantization script" blocking condition.
- 通过: 实现来源为或
transformers,模型类型为纯LLM或多模态理解,且报告完整;若存在量化/MTP风险,报告中需给出明确的用户操作要求model-local - 失败: 来源未解析、不支持的实现类型、判定为多模态生成模型,或触发“已量化模型无反量化脚本”阻塞条件
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:
markdown
undefined本技能包含自动化模型兼容性检查器,可在迁移前扫描模型架构:
功能:
- 迁移阻塞项检测: 识别不支持的算子、自定义层和框架特定特征
- 预警系统: 针对已知问题提供预警及建议解决方案
- 兼容性评分: 生成兼容性评分及详细分项
- 算子覆盖分析: 报告算子对Ascend NPU的支持覆盖率
兼容性检查类别:
| 类别 | 检查项 |
|---|---|
| 算子支持 | Transformer层、注意力机制、归一化 |
| 框架特性 | 自定义算子、动态形状、控制流 |
| 权重格式 | Safetensors、PyTorch、HF格式兼容性 |
| 特殊结构 | MoE、MTP、混合架构 |
输出格式:
markdown
undefinedCompatibility Check Result
兼容性检查结果
- Overall Score: XX/100
- Passed: X/XX checks
- Warning: X items require attention
- Blockers: X items preventing migration
- 整体评分: XX/100
- 通过检查项: X/XX
- 预警项: X项需关注
- 阻塞项: X项阻碍迁移
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 |
undefined| 检查项 | 状态 | 详情 |
|---|---|---|
| 算子覆盖率 | ✓ 通过 | 95%的算子受支持 |
| 自定义层 | ⚠️ 预警 | 2个自定义算子需AscendC实现 |
| 权重格式 | ✓ 通过 | 标准Hugging Face格式 |
undefinedReference Documents
参考文档
- Analysis Checklist - Analysis verification checklist
- Acceptance Criteria - Functional acceptance criteria
- Verification Method - Verification approach
- Troubleshooting - Common issues and solutions
- Analysis Checklist - 分析验证清单
- Acceptance Criteria - 功能验收标准
- Verification Method - 验证方法
- Troubleshooting - 常见问题与解决方案
Prerequisites
前置条件
- transformers >= 4.40.0 installed
- Model code available for analysis
- Basic understanding of model structure
- 已安装transformers >= 4.40.0
- 模型代码可用于分析
- 对模型结构有基本了解
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
分析工作流遵循以下步骤:
- 解析模型配置()
config.json - 确定实现来源(transformers或model-local)
- 分析模型架构与结构特征
- 评估MoE布局与融合权重风险
- 生成结构化分析报告
- 提供适配建议
Parameter Reference
参数参考
| Parameter | Description | Required |
|---|---|---|
| model | Model name or path | Yes |
| output | Analysis report output path | No |
| detailed | Output detailed information | No |
| 参数 | 描述 | 是否必填 |
|---|---|---|
| model | 模型名称或路径 | 是 |
| output | 分析报告输出路径 | 否 |
| detailed | 输出详细信息 | 否 |