huawei-cloud-msmodelslim-model-analysis

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Huawei 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:
  • huawei-cloud-msmodelslim-model-adapt
    - Adapter creation based on analysis results
本技能用于在为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_*.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.
  • 模型路径或模型仓库标识符
  • config.json
  • 可选:模型目录中的
    modeling_*.py
    model.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:
  1. Read
    config.json
    :
    • Get
      model_type
    • Get
      auto_map
      (if present)
  2. 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.
  3. 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.
  4. If neither path available:
    • Stop analysis.
    • Request user to provide readable model implementation code.
必须在任何结构分析前完成。Agent需按照以下步骤手动解析:
  1. 读取
    config.json
    :
    • 获取
      model_type
    • 获取
      auto_map
      (若存在)
  2. 尝试从transformers解析:
    • 检查
      transformers
      库是否支持该
      model_type
    • 检查路径是否存在:
      transformers/models/<model_type>/modeling_<model_type>.py
    • 若存在,记录为
      transformers
      实现
  3. 若解析失败,尝试模型本地实现:
    • 检查
      auto_map
      指向的文件是否存在于模型目录中
    • 检查模型目录中是否存在
      modeling_*.py
      文件
    • 若存在,记录为
      model-local
      实现
  4. 若两种路径均不可用:
    • 停止分析
    • 请求用户提供可读的模型实现代码

Minimum Workflow

最小工作流

  1. Parse implementation source (complete hard requirement above).
  2. 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)
  3. Identify structural features:
    • Decoder layer class, attention/MLP module naming, forward signature
  4. 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
  5. Output structured analysis results (refer to template below).
  6. Provide next steps:
    • Proceed to adapter creation workflow
    • Or block and explain what user needs to provide
  1. 解析实现来源(完成上述硬性要求)
  2. 确定模型类型、结构差异与关联:
    • 类型:纯LLM / 多模态理解 / 多模态生成
    • 与常见Qwen2类LLM对比,记录特殊结构设计(如MoE、非标准注意力、SSM/混合模块、额外头部或并行分支)
    • 检查特殊结构的关联(位置、依赖关系、串行/并行/残差连接、对主干遍历的影响)
  3. 识别结构特征:
    • 解码器层类、注意力/MLP模块命名、前向传播签名
  4. 确定影响适配的特征:
    • 层遍历路径与顺序
    • 是否需要分层加载
    • MoE融合专家权重风险
    • 量化模型反量化脚本风险
    • MTP结构实现可用性与权重处理风险
  5. 输出结构化分析结果(参考下方模板)
  6. 提供下一步建议:
    • 进入适配器创建工作流
    • 或说明需要用户补充的内容

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
    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.
  • 非融合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
undefined
Agent需直接生成分析报告(Markdown格式),必须包含以下元素。参考下方模板:
markdown
undefined

Analysis 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-local
    |
    unsupported
  • Basis:
    • Resolved file path: {path}
    • Related configuration fields (
      model_type
      ,
      auto_map
      ): {details}
  • 结果:
    transformers
    |
    model-local
    |
    unsupported
  • 依据:
    • 解析的文件路径: {path}
    • 相关配置字段(
      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
  • 隐藏层大小: {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}
  • visit/forward
    strict alignment points: {alignment_points}
  • 解码器遍历路径: {traversal_path}
  • 注意力模块命名: {attn_module}
  • MLP模块命名: {mlp_module}
  • visit/forward
    严格对齐点: {alignment_points}

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}
  • 建议下一步操作:
    • 进入适配器创建工作流
    • 或请求用户提供实现代码
undefined

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".
  • 若识别到“模型已量化”,必须将“缺失反量化脚本”标记为阻塞项,明确要求用户主动提供反量化脚本后才能继续适配
  • 若识别到MTP结构但实现代码不可访问,必须明确告知:
    • Agent可能无法完整实现MTP结构适配
    • 如需继续,用户需自行复制MTP相关权重(根据用户侧实现映射)
  • 当上述两种风险类型中至少一种出现时,
    风险等级
    不得低于“中”

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.
  • 通过: 实现来源为
    transformers
    model-local
    ,模型类型为纯LLM或多模态理解,且报告完整;若存在量化/MTP风险,报告中需给出明确的用户操作要求
  • 失败: 来源未解析、不支持的实现类型、判定为多模态生成模型,或触发“已量化模型无反量化脚本”阻塞条件

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:
CategoryCheck Items
Operator SupportTransformer layers, attention, normalization
Framework FeaturesCustom ops, dynamic shapes, control flow
Weight FormatsSafetensors, PyTorch, HF format compatibility
Special StructuresMoE, MTP, hybrid architectures
Output Format:
markdown
undefined
本技能包含自动化模型兼容性检查器,可在迁移前扫描模型架构:
功能:
  • 迁移阻塞项检测: 识别不支持的算子、自定义层和框架特定特征
  • 预警系统: 针对已知问题提供预警及建议解决方案
  • 兼容性评分: 生成兼容性评分及详细分项
  • 算子覆盖分析: 报告算子对Ascend NPU的支持覆盖率
兼容性检查类别:
类别检查项
算子支持Transformer层、注意力机制、归一化
框架特性自定义算子、动态形状、控制流
权重格式Safetensors、PyTorch、HF格式兼容性
特殊结构MoE、MTP、混合架构
输出格式:
markdown
undefined

Compatibility 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 ItemStatusDetails
Operator coverage✓ Pass95% of operators supported
Custom layers⚠️ Warning2 custom ops need AscendC impl
Weight format✓ PassStandard Hugging Face format
undefined
检查项状态详情
算子覆盖率✓ 通过95%的算子受支持
自定义层⚠️ 预警2个自定义算子需AscendC实现
权重格式✓ 通过标准Hugging Face格式
undefined

Reference 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:
  1. Parse model configuration (
    config.json
    )
  2. Determine implementation source (transformers or model-local)
  3. Analyze model architecture and structural features
  4. Assess MoE layout and fused weight risks
  5. Generate structured analysis report
  6. Provide adaptation recommendations
分析工作流遵循以下步骤:
  1. 解析模型配置(
    config.json
  2. 确定实现来源(transformers或model-local)
  3. 分析模型架构与结构特征
  4. 评估MoE布局与融合权重风险
  5. 生成结构化分析报告
  6. 提供适配建议

Parameter Reference

参数参考

ParameterDescriptionRequired
modelModel name or pathYes
outputAnalysis report output pathNo
detailedOutput detailed informationNo
参数描述是否必填
model模型名称或路径
output分析报告输出路径
detailed输出详细信息