Skip to content

Ascend/msagent / skills/profiler/memory-analysis

memory-analysis

Verified

对 msMemScope 显存数据做全链路处理:根据用户的显存问题诉求(OOM、显存泄漏、显存占比拆解、Step 间对比等),指导并帮助用户以最合适的 msMemScope 采集配置完成显存数据采集(支持命令行、Python 接口、mstx 打点三种采集方式,覆盖训练、推理 vLLM-Ascend、FSDP、强化学习 verl 等场景);对已采集的 memscope_dump_*.csv/db 数据做系统性解读与问题诊断(整体显存曲线趋势分析、显存使用大头按模块/组件拆解分析、显存峰值点各模块与流程占比分析,以及对显存泄漏、OOM 等典型问题的根因定位与原因分析)。

assets/collection_template.py

View on GitHub
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
msMemScope Python 接口采集参考模板。

【使用说明】
1. 先注入环境变量(必须 source):
     source msmemscope --load-api-env
2. 将本模板中的 train() 替换为用户实际训练/推理代码(或在采集范围处直接嵌入
   msmemscope.start()/stop())。
3. 采集完成后清理环境变量:
     source msmemscope --unload-api-env

【注意】
- 本模板仅作对照参考,不要求用户脚本照抄;按实际诉求裁剪 config 参数。
- 分析功能(analysis)需 events 含 alloc,free。
- 采集结束后务必清理环境变量,避免污染后续操作。
"""

import msmemscope


def train():
    """用户代码:替换为实际训练/推理逻辑。"""
    # 示例:采集 Step 信息(可选)
    for step in range(10):
        do_train_step(step)
        msmemscope.step()


def do_train_step(step: int):
    """占位函数,替换为用户的训练逻辑。"""
    pass


def main() -> None:
    # ---- 按诉求选择配置组合(以下为可选参数的示例) ----
    msmemscope.config(
        events="alloc,free",          # 必须包含 alloc,free(分析功能依赖)
        level="op",                   # op 或 kernel
        device="npu",                 # npu / npu:{id} / cpu
        analysis="leaks,decompose",   # leaks / decompose / oom[:K] / none
        call_stack="c:10,python:5",   # 泄漏/OOM 归因必需
        data_format="csv",            # csv(默认,推荐)或 db(仅 MindStudio Insight 可视化用)
        output="/home/user/output",   # 输出路径
    )

    # OOM 分析示例(自动联动 alloc/free 采集):
    # msmemscope.config(events="alloc,free", analysis="oom:50",
    #                   call_stack="python:10", output="/home/user/output")

    # 推理/RL 场景一键分析示例(vLLM-Ascend 11.0 快照):
    # msmemscope.cleanup_framework_hooks()
    # msmemscope.init_framework_hooks("vllm_ascend", "11.0", "worker", "snapshot")

    msmemscope.start()
    train()
    msmemscope.stop()


if __name__ == "__main__":
    main()
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall