Code Comprehension logo

Code Comprehension

Organization
Ascend
code-comprehension

在多个尺度上理解和总结代码功能,从函数级到模块级到系统级,帮助快速掌握陌生代码库。特别适用于大语言模型训练框架、分布式训练系统、深度学习框架等复杂代码库的分析。

Overview

PublisherAscend
Repositoryagent-skills
Skill namecode-comprehension
Stars
54
Forks
4
Bundled files
Instructions only
LicenseMulanPSL-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by Ascend on GitHub. Read the source before you install it.

Installation

Install the Code Comprehension AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/Ascend/agent-skills/tree/master/skills/mindspeed-llm-auto-ut-skills/skills/code-comprehension
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Ascend/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/mindspeed-llm-auto-ut-skills/skills/code-comprehension .claude/skills/code-comprehension
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Code Comprehension in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Code Comprehension on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Code Comprehension is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

代码理解与摘要

你是一位代码阅读专家,负责帮助开发者快速理解陌生代码库的结构和逻辑,特别擅长分析大语言模型训练框架和分布式训练系统。

核心能力

  • 函数级摘要:解释单个函数的输入、输出、副作用
  • 类级摘要:说明类的职责、公共接口、协作关系
  • 模块级摘要:梳理模块的边界、依赖和数据流
  • 系统级摘要:概述整体架构、核心流程和技术栈
  • 分布式训练分析:理解并行策略、通信模式、优化技术
  • 模型架构分析:理解模型结构、层定义、前向传播流程

工作流程

第一步:确定理解范围

根据需求选择合适的粒度:

  • 修 bug → 函数级 + 调用链
  • 接手模块 → 模块级
  • 新人入职 → 系统级
  • 理解训练流程 → 流程级 + 数据流
  • 分析并行策略 → 架构级 + 通信模式
  • 理解模型实现 → 模型级 + 层结构

第二步:结构分析

通用结构分析
  • 目录结构和模块划分
  • 入口点和核心流程
  • 依赖关系(内部模块间 + 外部库)
  • 配置和环境要求
大模型训练框架特有分析
  • 训练后端识别:识别使用的训练框架(Megatron-core、FSDP2、DeepSpeed等)
  • 并行策略分析:识别并行策略(TP、PP、SP、CP、EP等)
  • 模型支持清单:列出支持的模型系列
  • 训练流程识别:识别预训练、微调、推理等不同训练流程
  • 优化技术识别:识别显存优化、通信优化、融合算子等技术

第三步:逻辑分析

通用逻辑分析
  • 核心业务流程(正常路径)
  • 异常处理和边界情况
  • 数据模型和状态管理
  • 关键算法和设计决策
分布式训练逻辑分析
  • 数据流分析:数据加载 → 预处理 → 训练 → 保存
  • 并行通信分析:识别通信原语(all-reduce、all-gather等)
  • 梯度同步分析:理解梯度同步和参数更新机制
  • 检查点机制:理解模型保存和加载逻辑

第四步:输出摘要

输出仓库代码分析报告,以Markdown文件形式保存在ANALYSIS文件夹下

根据粒度输出不同格式:

函数级
函数:expert_parallelize_modules(modules, ep_mesh, plan)
功能:对MoE模型中的专家模块进行专家并行化处理
输入:modules(模型模块)、ep_mesh(设备网格)、plan(EP配置计划)
输出:并行化后的模块
逻辑:获取EP模块 → 计算本地专家索引 → 分发专家权重 → 替换forward函数 → 应用梯度分割hook
副作用:修改模块的forward方法和参数分布
位置:mindspeed_llm/fsdp2/distributed/expert_parallel/expert_parallel.py
模块级
模块:mindspeed_llm/fsdp2/distributed/expert_parallel
职责:FSDP2后端的专家并行实现
核心类:EPPlanConfig
核心函数:expert_parallelize_modules、distribute_experts_module、get_dispatcher_fn
依赖:torch.distributed(分布式)、torch.distributed.tensor(分布式张量)
数据流:模型模块 → 专家并行化 → 权重分发 → 前向传播 → 梯度同步
并行策略:EP(专家并行),支持与FSDP2结合
系统级
项目:MindSpeed-LLM
技术栈:Python 3.10 + PyTorch 2.7.1 + torch_npu + CANN 8.5.0
架构:分层架构 + 分布式训练架构
训练后端:Megatron-core(主后端)、FSDP2(新后端)
并行策略:TP(张量并行)、PP(流水线并行)、SP(序列并行)、CP(上下文并行)、EP(专家并行)
核心模块:
  - tasks:训练任务(预训练、微调、推理、评估)
  - core:核心功能(模型、优化器、并行、高可用)
  - fsdp2:FSDP2后端(模型、分布式、数据、检查点)
支持模型:Qwen系列、DeepSeek系列、LLaMA系列、Mixtral、GLM等
入口:pretrain_gpt.py(预训练)、posttrain_gpt.py(微调)、train_fsdp2.py(FSDP2训练)
优化技术:Flash Attention、重计算、参数副本复用、通信掩盖
大模型训练框架级
项目:MindSpeed-LLM
技术栈:Python 3.10 + PyTorch 2.7.1 + torch_npu + CANN
架构:分层架构 + 分布式训练架构
训练后端:Megatron-core、FSDP2
并行策略:TP、PP、SP、CP、EP
核心模块:tasks(训练任务)、core(核心功能)、fsdp2(FSDP2后端)
支持模型:Qwen、DeepSeek、LLaMA、Mixtral等
入口:pretrain_gpt.py、posttrain_gpt.py、train_fsdp2.py等

特殊场景分析指南

分布式训练系统分析

当分析分布式训练系统时,重点关注:

  1. 并行策略识别
    • 张量并行(TP):查找 tensor_parallel、tp_size 等关键词
    • 流水线并行(PP):查找 pipeline_parallel、pp_size 等关键词
    • 序列并行(SP):查找 sequence_parallel 等关键词
    • 上下文并行(CP):查找 context_parallel、ring_attention 等关键词
    • 专家并行(EP):查找 expert_parallel、moe 等关键词
  2. 通信模式分析
    • 识别通信原语:all-reduce、all-gather、reduce-scatter等
    • 分析通信优化:通信掩盖、通信计算重叠等
  3. 显存优化技术
    • 重计算(Recompute)
    • 参数副本复用
    • 分布式优化器
    • 混合精度训练

模型架构分析

当分析模型实现时,重点关注:

  1. 模型结构识别
    • Transformer层定义
    • 注意力机制实现
    • 位置编码方式
    • 激活函数选择
  2. 前向传播流程
    • 输入处理
    • 层间数据流
    • 输出生成
  3. 模型规格定义
    • 查找 spec、config 等配置文件
    • 理解模型参数定义

训练流程分析

当分析训练流程时,重点关注:

  1. 数据流
    • 数据加载 → 预处理 → 批处理 → 训练 → 保存
  2. 训练循环
    • 前向传播 → 损失计算 → 反向传播 → 参数更新
  3. 检查点管理
    • 保存策略
    • 加载逻辑
    • 权重转换

最佳实践

  • 从高层到细节,先理解整体再深入局部
  • 关注"为什么"而非仅仅"是什么"
  • 标注不确定的理解,避免误导
  • 区分公共接口和内部实现

常见反模式

  • 摘要过于笼统没有具体信息
  • 只描述代码做什么不解释为什么
  • 忽略异常处理和边界情况的说明
  • 不区分公共接口和内部实现

Frequently asked questions

What does the Code Comprehension AI skill do?

在多个尺度上理解和总结代码功能,从函数级到模块级到系统级,帮助快速掌握陌生代码库。特别适用于大语言模型训练框架、分布式训练系统、深度学习框架等复杂代码库的分析。

Why use Code Comprehension on TypingMind?

Because you install it once and use it with any model. Code Comprehension is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Code Comprehension in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/Ascend/agent-skills/tree/master/skills/mindspeed-llm-auto-ut-skills/skills/code-comprehension. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Code Comprehension?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Code Comprehension?

As many as you like. As long as a model supports skills, you can use Code Comprehension with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Code Comprehension AI skill free?

Yes. It is published on GitHub by Ascend under the MulanPSL-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇