Skip to content

woshipapa/my_utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

151 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

my_utils

面向 PyTorch 训练/推理工作流的实用工具集,核心覆盖:

  • 性能采集与分析(NSYS / NCU / 统一 metrics)
  • 运行时追踪与 Hook(NVTX / module hooks)
  • 分布式辅助(时钟同步 / etcd barrier / sequence parallel padding)
  • 内存诊断(snapshot / OOM flag / GPU tracker)
  • 产物落盘与离线分析(dump / CSV)

30秒定位

flowchart TD
    A[开始: 我要做什么] --> B{目标}
    B -->|训练全局性能| C[profiling/templates + nsys]
    B -->|单kernel瓶颈| D[profiling/ncu]
    B -->|代码内埋点追踪| E[tracing + hooks]
    B -->|分布式辅助能力| F[distributed]
    B -->|内存诊断| G[memory]
    B -->|基础工具| H[core]
Loading

安装

cd my_utils
pip install -e .

可选依赖(按需):

pip install -e .[profiling,tensordict,etcd,nvml,nvtx,system,megatron]

常用组合:

# 仅安装 my_utils,不动你现有 torch/cuDNN 环境
pip install -e .

# 安装所有可选依赖(不含 torch)
pip install -e .[all]

# 安装所有可选依赖(含 torch)
pip install -e .[all_with_torch]

一眼可用命令(最常用)

NSYS 快速采集:

bash my_utils/profiling/templates/run_nsys_quick.sh -- python train.py --config cfg.yaml

NSYS 离线分析:

myutils-profile nsys-analyze --sqlite ./train_rank0.sqlite --output ./nsys_analyze.json

NCU 完整采集:

python my_utils/profiling/ncu/run_ncu_quick_yaml.py \
  --config my_utils/profiling/ncu/ncu_full_collection.yaml

NCU 报告分析:

myutils-profile ncu-report-analyze --report ./run.ncu-rep --top-k 20 --pretty

Python 最小示例

1) core: 计时 + 日志

from my_utils.core import setup_logging_and_timer

logger, timer = setup_logging_and_timer(
    logger_name="train",
    log_file="train.log",
    use_cuda=True,
    rank=0,
)

timer.start("forward")
# ... your forward ...
timer.stop("forward")

2) tracing: NVTX 自动降级

from my_utils.tracing import create_labeler

labeler = create_labeler(preferred="auto")
with labeler.range("train_step"):
    # ... your step ...
    pass

包结构(按用途)

兼容性说明

  • 旧导入路径(例如 from my_utils.utils import MyTimer)仍可用。
  • 新代码建议使用分层路径(例如 from my_utils.core import MyTimer)。
  • my_utils/__init__.py 内置了 legacy module aliases,便于旧项目平滑迁移。

文档推荐阅读顺序

  1. my_utils/profiling/README.md
  2. my_utils/profiling/docs/FRAMEWORK_INTEGRATION_PLAYBOOK_ZH.md
  3. my_utils/profiling/examples/framework_playbook_samples/README.md
  4. my_utils/profiling/templates/README.md
  5. my_utils/profiling/ncu/README.md
  6. my_utils/profiling/docs/README.md

About

some utils to messure and profile distributed training or inference

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors