一键导入
msmodelslim-model-dequant
为 msModelSlim 适配流程注入反量化能力。先识别模型权重是否可反量化,再实现反量化脚本并接入 model_adapter。当前仅覆盖 FP8 的 per-block 与 per-channel 两类;若格式不确定或无公开反量化规则,要求用户提供反量化脚本或浮点权重。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
为 msModelSlim 适配流程注入反量化能力。先识别模型权重是否可反量化,再实现反量化脚本并接入 model_adapter。当前仅覆盖 FP8 的 per-block 与 per-channel 两类;若格式不确定或无公开反量化规则,要求用户提供反量化脚本或浮点权重。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
当用户需要部署 msmodeling optix 服务化自动寻优工具时使用。负责安装与验证。
当首次使用 msmodeling optix 的用户需要根据硬件、模型、负载和优化目标推荐 MindIE/vLLM 寻优参数、搜索范围、benchmark 侧字段或 config.toml 片段时使用。
指导并自动化完成昇腾 NPU 上 MindSpeed-LLM 训练的 Profiling 数据采集。支持配置并运行带 Profiling 的模型训练,包括 CPU 采集、内存采集、不同采集级别(level0/level1/level2)和自定义 step 范围。生成的 Profiling 数据可用 MindStudio Insight 进行性能分析。当用户需要在模型训练中采集 Profiling 数据、进行训练性能分析、或执行 性能数据采集/Profiling采集 时触发。触发关键词:profiling、性能分析、性能数据采集、Profiling采集、训练框架profiling、MindSpeed-LLM profiling。
指导并自动化完成昇腾 NPU 上 MindSpeed-MM 模型训练的 Profiling 数据采集。通过识别训练脚本,自动找到配置文件并启用内置 Profiler,支持静态采集(指定起止 step)和动态采集(运行时动态开关),支持 Megatron 引擎(tools.json)和独立 FSDP2 引擎(YAML)两种配置方式。生成的 Profiling 数据可用 MindStudio Insight 进行性能分析。当用户需要在多模态模型训练中采集 Profiling 数据、进行训练性能分析、或执行 性能数据采集/Profiling采集 时触发。触发关键词:profiling、性能分析、性能数据采集、Profiling采集、多模态训练profiling、MindSpeed-MM profiling。
Skill for analyzing communication performance bottlenecks and detecting slow/fast rank issues in Ascend NPU systems. Use this skill whenever you need to analyze communication efficiency, data transfer bottlenecks, or identify slow/fast rank problems using profiling data.
用于分析Ascend NPU系统中计算性能瓶颈的技能,专注于算子效率和计算优化
| name | msmodelslim-model-dequant |
| description | 为 msModelSlim 适配流程注入反量化能力。先识别模型权重是否可反量化,再实现反量化脚本并接入 model_adapter。当前仅覆盖 FP8 的 per-block 与 per-channel 两类;若格式不确定或无公开反量化规则,要求用户提供反量化脚本或浮点权重。 |
本 Skill 用于在模型适配前处理 FP8 量化权重,将可识别权重恢复为 bf16/fp16 再进入后续适配与量化流程。
config.json、model.safetensors.index.json)model_adapter.py在编写任何脚本前,必须先判定是否属于可接受类型:
config.json,提取可用量化配置字段(如量化类型、group/block 相关参数)model.safetensors.index.json 的 weight_mapxxx.weight_scale_inv / xxx.scale),且可推导块大小 block_size[out_features]、[in_features] 或可广播到对应通道维)M 与 N 可按 block_size 分块并与 scale 网格对应必须输出判定依据(命中的键模式、样例键名、对应文件)。
未量化:直接跳过反量化步骤,进入后续适配可接受量化(FP8 per-block/per-channel):进入脚本实现与适配器接入未知/不接受量化:阻塞并向用户提出材料请求(见“阻塞话术”)convert_*_to_bf16.py)按 FP8 模式创建脚本,最小要求:
convert_* 主转换函数(必须带可见进度条与异常提示)torch.bfloat16(或项目默认浮点 dtype)tqdm(或等价方案)显示转换进度,禁止仅打印日志让用户等待total 必须可追踪(例如按待转换参数个数/层数),并实时更新 desc(如当前层名)chat_template.jinja 文件,该文件缺失会导致服务化异常。建议函数骨架:
@lru_cache(maxsize=1)
def get_weight_map(model_path: str) -> Dict[str, str]:
...
@torch.no_grad()
def convert_module_xxx_to_bf16(name: str, module: nn.Module, model_path: str, weight_map: Dict[str, str]):
...
per-block 示例:
def decode_fp8_per_block(weight: torch.Tensor, scale: torch.Tensor, block_size: int = 128) -> torch.Tensor:
m, n = weight.shape
scale_expanded = scale.repeat_interleave(block_size, dim=0).repeat_interleave(block_size, dim=1)[:m, :n]
return (weight.float() * scale_expanded.float()).to(torch.bfloat16)
参数回写(通用伪代码):
dequant_weight = dequantize(fp8_weight, scale_info) # dequant_weight: BF16/F16
if original_param_storage_is_fp8:
promote_original_param_storage_to_target_float_dtype()
assign_or_copy_with_device_dtype_alignment(dequant_weight)
verify_param_dtype_is_target_float_dtype_not_fp8()
可选工具脚本(用于判定权重/scale 形状):
scripts/inspect_safetensors.pypython scripts/inspect_safetensors.py -m /path/to/modelpython scripts/inspect_safetensors.py -m /path/to/model -p "model.layers.*.mlp*.weight*"model_adapter.py在适配器中注入反量化调用,要求:
config.json 是否包含量化字段(如 quantization_config、quant_method、fmt、weight_block_size、modules_to_not_convert 等)config.json 后加载;或config 并确保后续加载明确使用该配置convert_*_to_bf16接入示例:
from .convert_fp8_to_bf16 import convert_module_fp8_to_bf16
def init_model(...):
model = ...
convert_module_fp8_to_bf16(name="", module=model, model_path=model_path, weight_map=...)
return model
per-block 或 per-channel 判定结果当量化格式不确定或缺反量化规则时,必须明确告知:
Agent 每次执行本 Skill 后,输出以下结构:
## 反量化判定结果
- 量化状态:未量化 | FP8 per-block(可接受) | FP8 per-channel(可接受) | 未知(阻塞)
- 判定依据:{keys/file evidence}
## 反量化实现动作
- 新增/复用脚本:{path}
- 核心函数:{functions}
- 适配器接入点:{adapter_path + function}
## 验证结果
- 读取校验:通过/失败
- dtype 校验:通过/失败
- 适配器触发校验:通过/失败
## 后续动作
- 若阻塞:请求用户提供反量化脚本或浮点权重
- 若通过:进入模型适配主流程