SuperAPI AI Directory

external-mindstudio-msmodelslim-model-analysis

Agents & models

View repository

Updated 10-15 17:19

About this skill

Model Analysis Skill

Scope

  • Supported:
    • Decoder-only LLM
    • VLM text backbone analysis (LLM/text path only)
  • Not supported:
    • Implementations that are neither in transformers nor modeling_*.py in the model directory
    • Multimodal generative models (image/video/speech generation)

Required input

  • Model path or model repository identifier
  • config.json
  • Optional: within the model directory modeling_*.py、model.safetensors.index.json
  • If the above files are missing locally, complete the input first:
    • Use modelscope download --model <org>/<model> --local_dir ./models/<name> --exclude '*.safetensors' to download non-weight files.
    • In the download directory, read config.json and modeling_*.pyas input for subsequent analysis.

Hard gate: first resolve the implementation source

Must be completed before performing any structural analysis. The Agent should resolve this manually according to the following steps; no script is needed:

  1. Read config.json:

    • Get model_type
    • Get auto_map(if any)
  2. Try to resolve the implementation from transformers:

    • Check whether the transformers library supports this model_type。
    • Check path:transformers/models/<model_type>/modeling_<model_type>.py whether it exists.
    • If it exists, record it as transformers implementation.
  3. If not resolved, try the implementation within the model directory:

    • Check whether the file pointed to by auto_map exists in the model directory.
    • Check whether there is modeling_*.py file in the model directory.
    • If it exists, record it as model-local implementation.
  4. If neither path is available:

    • Stop the analysis.
    • Ask the user to provide readable model implementation code.

Minimal workflow

  1. Resolve the implementation source (complete the above hard gate).
  2. Determine the model type, structural differences, and connection relationships:
    • Type: pure LLM / multimodal understanding model / multimodal generative model
    • Compare with common Qwen2-like LLMs, record special structural designs (such as MoE, non-standard attention, SSM/hybrid blocks, extra heads, or parallel branches)
    • Check the connection relationships of special structures (access position, dependencies before and after, serial/parallel/residual connections, whether they affect backbone traversal)
  3. Identify structural features:
    • decoder layer class, attention/MLP module naming, forward signature
  4. Determine the features that affect adaptation:
    • Layer traversal path and order
    • Whether layer-by-layer loading is required
    • MoE fused expert weight risk
    • Quantized model dequantization script risk
    • MTP structure implementation availability and weight handling risk
  5. Produce structured analysis results (refer to the template below).
  6. Provide follow-up actions:
    • Proceed to model-adapt-core
    • or block and explain what the user needs to provide

Determination of model type, structural differences, and connection relationships (relative to common Qwen2)

  • 纯 LLM: Text-token input only, with a decoder-only language model as the backbone.
  • 多模态理解模型: Includes encoders such as vision/audio, but the generation path centers on the text backbone, and it is allowed to analyze and adapt only the text portion.
  • 多模态生成模型: The core objective is image/video/speech generation, which the current pipeline does not support and should directly block with an explanation of the reason.
  • For structural differences, only record "whether it exists + direction of impact"; deep implementation details are not required.
  • For connection relationships, at minimum record: at which stage of the backbone the special structure is located, which modules it connects to, the connection method (serial/parallel/residual), and its impact on traversal/forward alignment.

MoE Layout Determination

  • MoE 非融合: Experts are expanded by module/list (commonly each expert holds its own gate/up/down linear layer).
  • MoE 融合: The weights of multiple experts are packed as tensor parameters and are no longer a set of independent linear layers.
  • If any one or more of gate/up/down is seen stored in the form of [..., num_experts, ...] or [num_experts, ...] , it should be treated as "fused".
  • Three-dimensional expert weights (such as gate/up/down each fused into 3D parameters) are uniformly classified as MoE 融合, and "may require unpack" should be noted in the report.

Required Output: Analysis Report

The Agent should directly generate an analysis report (in Markdown format), and the content must include the following elements. Please refer to the template below:

# 分析报告

## 模型标识
- 模型路径/仓库:{model_path}
- `model_type`:{model_type}
- `architectures`:{architectures}

## 实现来源解析
- 结果:`transformers` | `model-local` | `unsupported`
- 依据:
  - 解析到的文件路径:{path}
  - 相关配置字段(`model_type`、`auto_map`):{details}

## 模型特征与规格
- Hidden size:{hidden_size}
- 层数:{num_layers}
- Attention heads / KV heads:{num_heads} / {num_kv_heads}
- 是否仅分析 VLM 文本部分:是/否

## 模型类型、结构差异与连接关系
- 模型类型:纯 LLM | 多模态理解模型 | 多模态生成模型
- 相对常见 Qwen2 的特殊结构:{special_structures}
- 特殊结构连接关系:{special_structure_connections}
- 对适配流程的影响:{structure_impact}

## 逐层加载评估
- 是否需要逐层加载:是/否
- 理由:{reason}
- 约束(内存/运行环境):{constraints}

## MoE 评估
- 是否含 MoE:是/否
- 布局类型:无 MoE | MoE 非融合 | MoE 融合
- 疑似融合的键/模块:{keys}
- 专家权重形态:独立线性层 | 打包张量(含 3D 专家权重)
- 是否需要 unpack:是/否

## 适配影响要点
- Decoder 遍历路径:{traversal_path}
- Attention 模块命名:{attn_module}
- MLP 模块命名:{mlp_module}
- `visit/forward` 严格对齐点:{alignment_points}

## 量化与 MTP 风险评估
- 模型是否已量化:是/否
- 量化判定依据:{quant_evidence}
- 是否已提供反量化脚本:是/否
- 反量化脚本状态说明:{dequant_status}
- 是否存在 MTP 结构:是/否
- MTP 实现代码可获取性:可获取/不可获取
- MTP 风险说明:{mtp_risk}

## 风险与后续动作
- 风险等级:低 | 中 | 高
- 阻塞项:{blockers}
- 建议下一步:
  - 进入 `model-adapt-core`
  - 或要求用户提供实现代码

Risk Identification and User Communication Requirements (Must Be Executed)

  • If it is identified as "the model itself has already been quantized", then "missing dequantization script" must be marked as a blocking item, and the user must be explicitly required to proactively provide a dequantization script before adaptation continues.
  • If an MTP structure is identified but its implementation code cannot be obtained, it must be clearly stated:
    • The Agent may be unable to fully implement MTP structure adaptation;
    • To continue, the user needs to copy the MTP-related weights themselves (mapping them according to the implementation already available on the user side).
  • When at least one of the above two types of risks is hit,风险等级 must not be lower than "medium".

Pass/Fail Criteria

  • Pass: The implementation source is transformers or model-local, the model type is a pure LLM or a multimodal understanding model, and the report is complete; if a quantization/MTP risk is hit, clear user action requirements have been given in the report.
  • Fail: The source is unresolved, is an unsupported implementation type, is determined to be a multimodal generation model, or hits the blocking condition of "quantized model but no dequantization script".

Reference