| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
新增HiF4-cast 直转工具 Co-authored-by: Zhang Jian<jianmusings@gmail.com> # message auto-generated for no-merge-commit merge: !201 merge jian/hifloat4-cast into master 新增HiF4-cast 直转工具 Created-by: zhangj1an Commit-by: Zhang Jian Merged-by: cann-robot Description: ## Latest Status [13 Aug 2026] Ready for review, CI已通过 --- ## Description <!--Describe your changes in detail, including the reasons for the changes and the methods adopted.--> 本PR希望把HiF4-cast工具集成到AMCT仓库中,需求编号为AR00002U9R。命令行调用、实现细节可以参见 https://gitcode.com/cann/amct/issues/163。 HiF4是一种4比特的层级缩放、块浮点格式。每64个元素为一个块,先用E6M2进行一级缩放,再以8个和4个数字为一组分别算出二、三级微指数,最后每个元素以S1P2表示(1个符号位+2个尾数位),可取{-1.75, -1.5, ... 0, ... 1.5, 1.75}共15个值。细节可参见HiF4技术报告 https://arxiv.org/abs/2602.11287。 ### 主要功能 | 输入 | 路径 | 命令 | 调用链 | 输出 | |---|---|---|---|---| | FP16/BF16 | 伪量化,仅注入HiF4误差,不输出新模型权重 | ptq --quant_dtype hifp --bit_config configs/hifloat4.yaml | fake_quant → hifloat4_fake_quant(NPU kernel / CPU fallback) | 注入HiF4误差,不产出文件 | | FP16/BF16 | 打包,输出HiF4打包字节 | deploy --quant_dtype hifp --granularity block | export_block_deploy → hif4_pack | HiF4 打包字节 | | HiF4 | 解码,输出FP32格式 | deploy --quant_dtype hifp --granularity tensor | convert_state_dict → hif4_unpack | FP32 | 其中,伪量化(BF16/FP16 → HiF4 → BF16/FP16)由NPU伪算子实现;打包和解码由PyTorch实现。打包格式为低位优先,元素0放在低4位,元素1放在高4位。当一个64元素块内出现NaN/+Inf/-Inf时,打包scale byte 0写入0xFF,解码时整块恢复为NaN。 ## Design (设计方案) ### 与开源HiF4仓库对比 本PR的HiF4-cast工具在 https://github.com/global-computing-consortium/HiFloat4 基础上,根据程禹最新的HiF4算子私仓内容,做了以下5点改进,已和程禹对齐。原本的github仓库中的伪量化(BF16/FP16 → HiF4 → BF16/FP16)是由NPU伪算子实现的。 1. 新增了打包函数,由PyTorch实现。存储格式为低位优先,元素 0 放在低 4 bit,元素 1 放在高 4 bit。 2. 在编解码函数中,在把元素除掉块scale,也做完二三级缩放后,在量化成S1P2之前,先做了一次round_to_bf16。 3. 在编解码函数中,当一个64元素块内出现NaN, +Inf, -Inf取值时,打包scale byte 0 写入0xFF, 解码时整块恢复为NaN。 4. 在编解码函数中,当对block max做规约时,从amax(dim=-1),改成了amax(dim=qdim, keepdim=True)。不再需要手动把qdim调整到-1维度。 5. 在伪量化算子中,在host 侧增加了一步处理:将 N 补零pad到 BATCH=512 的整数倍后再调用kernel,kernel不再需要处理当N不符合batch=512的整数的情况。 kernel 输出后裁剪回原长。 ### 适配AMCT仓库 为了将算法接入amct仓库,主要新增/修改以下模块: 1. 新增HiF4伪量化NPU算子文件夹:(amct_ops/hifloat4_cast/) ,做一次FP→HiF4→FP往返仿真。 2. 修改文件,新增HiF4 PyTorch实现的打包、解包、伪算子调度器(amct_pytorch/quantization/dtypes/hifp_impl.py) , 与HiF8并列存放。公开API: - hif4_pack(x) :打包算法, 浮点 → HiF4 uint8字节 - hif4_unpack(scale, value) :解包算法: HiF4 uint8字节 → FP32 - hifloat4_fake_quant(x, qdim=-1) : 伪算子调度器:NPU kernel优先,CPU fallback 内部共用一样的PyTorch算法, hif4_encode / hif4_decode(3级scale + S1P2 golden reference),保证PTQ和deploy路径数值一致。 3. 修改文件,在dtype和带有解码功能的deploy tensorwise函数中注册HiF4格式,(hifp.py、deploy_export.py)。 QuantDequantHifp 已支持 bits=4;convert_state_dict 新增HiF4检测与解码。 ## How to Test <!--Describe the steps and prerequisites for testing this change.--> ### 1. 单元测试 tests/amct_ops/test_hifloat4_cast.py, 里面包括了伪量化算子与golden参考的一致性和异常值处理的测试。 ### 2. CLI端到端的测试 bash # 伪量化:注入HiF4误差(ptq,不产出文件) python -m amct_pytorch.cli.llm.ptq \ --quant_dtype hifp --bit_config amct_pytorch/configs/w4a4.yaml \ --model <IN> --output_dir <OUT> # 打包:输出HiF4字节(deploy blockwise) python -m amct_pytorch.cli.llm.deploy \ --quant_dtype hifp --granularity block \ --model <IN> --output_dir <OUT> # 解码:输出FP32(deploy tensorwise) python -m amct_pytorch.cli.llm.deploy \ --quant_dtype hifp --granularity tensor \ --model <IN> --output_dir <OUT> 可以将模型权重打包又解码的产出和直接做伪量化的产出进行对比,如果达到逐比特一致说明算法正确。 ### 3. 看PPL是否符合预期 用amct仓库内的eval测试,比较BF16, MXFP4, HiF4在wikitext-2数据集上的PPL,看趋势是否符合预期。 <details> <summary> 调用命令</summary> # 1) BF16 baseline —— 不需要 quant_dtype / bit_config / quant_target python -m amct_pytorch.eval \ --model $MODEL --model_name Qwen3.5-9B \ --device npu:0 --eval_mode bf16 \ --seq_len 4096 --output_dir ./outputs # 2) MXFP4 W4A4 python -m amct_pytorch.eval \ --model $MODEL --model_name Qwen3.5-9B \ --device npu:0 --eval_mode quant \ --quant_dtype mxfp \ --bit_config amct_pytorch/configs/w4a4.yaml \ --quant_target mlp attn-linear \ --seq_len 4096 --output_dir ./outputs # 3) HiF4 W4A4 —— 只改 quant_dtype python -m amct_pytorch.eval \ --model $MODEL --model_name Qwen3.5-9B \ --device npu:0 --eval_mode quant \ --quant_dtype hifp \ --bit_config amct_pytorch/configs/w4a4.yaml \ --quant_target mlp attn-linear \ --seq_len 4096 --output_dir ./outputs 另外,当与github上的HiF4私仓github.com/ddddwee1/HiFloat-private (commit id: f511fdd)进行对比时,MXFP4的量化应调用hif4_gpu/quant_cy/base/cusrc/extended_quant_cuda.cu 里mx_shared_scale 函数的mxfp4_c725 分支,并且把round_to_decimal的阈值从1.8125改成1.75,就和amct仓库的实现是一致的。 </details> ## Test Result 在量化时,我们选择W4A4, 将模型的mlp和attn-linear部分进行量化,(其中也会量化linear attention)。 用Qwen3.5-9B和wikitext-2数据集,将HiF4在amct上进行了测试,结果与HiF4算子repo里的PPL趋势一致,HiF4的PPL比MXFP4会差0.5。 |量化选项|HiF4算子repo(程禹写的golden reference), 在A100上测试| amct, 该分支,在npu 910C上测试| |---|---|---| |BF16 baseline|8.202739840420143|8.176278114318848| |MXFP4 w4a4|9.664575071762391| 9.502161026000977| |HiF4 w4a4|10.020700353404631| 9.901074409484863| 由于该结果不太符合预期,HiF4并没有比MXFP4有优势,我们另外在下游数据集上进行了测试。结果显示在Qwen3.5-9B上,HiF4的精度比MXFP4好0.6. 作为对比,在Qwen3-8B上,HiF4的精度比MXFP4好1.7。这两个模型的主要差异在于千问3.5-9b的结构是(3层linear attention+1层full attention)x8,而千问3-8b的结构是36层full attention. ### Qwen3.5-9B上,HiF4的精度比MXFP4好0.6 | Dataset / Metric | FP16 | HiF4 (HiF4算子私仓的版本) | MXFP4 (AMCT实现的版本) | Δ HiF4 - MXFP4 | |---|---:|---:|---:|---:| | arc_challenge (acc_norm) | 55.9 | 55.0 | 54.8 | +0.2 | | arc_easy (acc_norm) | 74.2 | 76.2 | 76.8 | -0.6 | | boolq (acc) | 89.1 | 86.8 | 85.0 | +1.8 | | copa (acc) | 89.0 | 89.0 | 89.0 | 0.0 | | piqa (acc_norm) | 80.1 | 78.8 | 78.2 | +0.6 | | sciq (acc_norm) | 96.0 | 96.2 | 95.3 | +0.9 | | hellaswag (acc_norm) | 78.1 | 76.3 | 74.8 | +1.5 | | **Average** | **80.3** | **79.8** | **79.1** | **+0.6** | 其中表格最后一行,未四舍五入之前的平均值应该是 HiF4 = 79.75,MXFP4 AMCT = 79.11,差值 = +0.64,表格里展示成一位小数就是 +0.6。 ### Qwen3-8B上,HiF4的精度比MXFP4好1.7 | Dataset / Metric | FP16 | (HiF4算子私仓的版本) | MXFP4 (AMCT实现的版本) | Δ HiF4 - MXFP4 | |---|---:|---:|---:|---:| | arc_challenge (acc_norm) | 56.5 | 52.3 | 52.6 | -0.3 | | arc_easy (acc_norm) | 80.8 | 76.9 | 73.4 | +3.5 | | boolq (acc) | 86.6 | 85.9 | 84.5 | +1.4 | | copa (acc) | 85.0 | 84.0 | 82.0 | +2.0 | | piqa (acc_norm) | 77.7 | 76.3 | 75.2 | +1.0 | | sciq (acc_norm) | 95.6 | 95.8 | 94.3 | +1.5 | | hellaswag (acc_norm) | 75.0 | 73.9 | 71.3 | +2.6 | | **Average** | **79.6** | **77.9** | **76.2** | **+1.7** | 另外我们也将Qwen3.5-9b每一层W4A4量化后的SQNR进行了对比。HiF4在每一层的SQNR都比MXFP4高。 ### Qwen3.5-9B上,对权重作比较时,HiF4所有层的SQNR都优于MXFP4 | Layer | HiF4 (dB) | MXFP4 (dB) | Δ HiF4 − MXFP4 | |---|---:|---:|---:| | linear_attn/in_proj_a | 21.40 | 18.56 | +2.84 | | linear_attn/in_proj_b | 21.28 | 18.36 | +2.92 | | linear_attn/in_proj_qkv | 21.56 | 18.94 | +2.62 | | linear_attn/in_proj_z | 21.57 | 18.96 | +2.61 | | linear_attn/out_proj | 21.54 | 18.92 | +2.62 | | mlp/down_proj | 21.55 | 18.88 | +2.67 | | mlp/gate_proj | 21.56 | 18.91 | +2.65 | | mlp/up_proj | 21.56 | 18.91 | +2.65 | | self_attn/k_proj | 21.40 | 18.63 | +2.77 | | self_attn/o_proj | 21.51 | 18.88 | +2.63 | | self_attn/q_proj | 21.54 | 18.91 | +2.63 | | self_attn/v_proj | 21.43 | 18.71 | +2.72 | ### Qwen3.5-9B上,对激活作比较时,HiF4所有层的SQNR都优于MXFP4 | Activation / Layer | HiF4 (dB) | MXFP4 (dB) | Δ HiF4 − MXFP4 | |---|---:|---:|---:| | linear_attn/in_proj_{a,b,qkv,z} | 21.21 | 18.05 | +3.16 | | linear_attn/out_proj | 20.81 | 17.28 | +3.53 | | mlp/down_proj | 20.73 | 17.09 | +3.64 | | mlp/{gate,up}_proj | 20.72 | 17.79 | +2.93 | | self_attn/{q,k,v}_proj | 21.10 | 17.90 | +3.20 | | self_attn/o_proj | 20.72 | 17.21 | +3.51 | <details><summary> 单元测试9项通过 </summary> $ python -m pytest tests/amct_ops/test_hifloat4_cast.py -v tests/amct_ops/test_hifloat4_cast.py::TestHiFloat4Kernel::test_kernel_bf16 PASSED [ 11%] tests/amct_ops/test_hifloat4_cast.py::TestHiFloat4Kernel::test_kernel_fp16 PASSED [ 22%] tests/amct_ops/test_hifloat4_cast.py::TestHiFloat4Kernel::test_kernel_padded PASSED [ 33%] tests/amct_ops/test_hifloat4_cast.py::TestHiFloat4Kernel::test_kernel_zero_is_nan_free PASSED [ 44%] tests/amct_ops/test_hifloat4_cast.py::TestHiFloat4CastShapes::test_dequant_shape_2x128 PASSED [ 55%] tests/amct_ops/test_hifloat4_cast.py::TestHiFloat4CastShapes::test_dequant_shape_3x512 PASSED [ 66%] tests/amct_ops/test_hifloat4_cast.py::TestHiFloat4CastShapes::test_packed_shape_1x64 PASSED [ 77%] tests/amct_ops/test_hifloat4_cast.py::TestHiFloat4CastShapes::test_packed_shape_2x128 PASSED [ 88%] tests/amct_ops/test_hifloat4_cast.py::TestHiFloat4CastShapes::test_packed_shape_3x512 PASSED [100%] ======================== 9 passed, 15 warnings in 1.98s ======================== </details> <details><summary> 以下两种方案达到了逐比特一致:1. NPU 伪算子(hifloat4_fake_quant) 和 2. PyTorch 打包再解包(hif4_pack + hif4_unpack)</summary> 以 Qwen3.5-9B MLP 权重形状(2560×10240, 10240×2560)的合成 BF16 张量在 NPU 上验证: python import torch from amct_pytorch.quantization.dtypes.hifp_impl import hifloat4_fake_quant, hif4_pack, hif4_unpack shapes = [(2560, 10240), (10240, 2560), (2560, 10240)] for M, N in shapes: x = torch.randn(M, N, dtype=torch.bfloat16).npu() npu_out = hifloat4_fake_quant(x).cpu() # NPU AscendC kernel scale, value = hif4_pack(x.cpu()) # CPU 打包 decoded = torch.from_numpy(hif4_unpack(scale, value)).to(torch.bfloat16) diff = (npu_out.to(torch.float32) - decoded.to(torch.float32)).abs().max().item() print(f' [{M}x{N}] diff={diff:.2e}', '✓' if diff < 1e-4 else '✗') 得到了以下输出内容: [2560x10240] diff=0.00e+00 ✓ [10240x2560] diff=0.00e+00 ✓ [2560x10240] diff=0.00e+00 ✓ All bit-identical ✓ </details> ## Documentation Updates <!--If this PR includes documentation updates, please indicate them here. For example: Updated the README.md file.--> 更新了HiF4伪算子的文档,amct_ops/hifloat4_cast/README.md 和 README_en.md。 ## Type Label <!-- [x] indicates selected --> - [ ] Bug fix - [x] New feature - [ ] Performance optimization - [ ] Documentation update - [x] Code refactoring - [ ] Other, please describe: See merge request: cann/amct!201 | 21 天前 | |
[Feature] Added structured pruning (amct_pytorch.pruning) Co-authored-by: leedongkun30-arch<lee.dongkun30@gmail.com> # message auto-generated for no-merge-commit merge: !140 merge feat/pruning into master [Feature] Added structured pruning (amct_pytorch.pruning) Created-by: leedongkun30-arch Commit-by: leedongkun30-arch Merged-by: cann-robot Description: ## 描述 新增 eager 模式**结构化剪枝**子系统 amct_pytorch.pruning,接口风格与 amct.quantize 对齐:对已实例化并加载权重的 torch.nn.Module 原地剪枝。覆盖三个目标域——**dense FFN 中间维 / CNN 通道 / MoE 专家**,仅剪枝“生产者↔消费者接口可验证”的维度,其余保守跳过(注意力投影、残差宽度等自动排除)。 改动为**增量式**:仅在 amct_pytorch/__init__.py 中以 PEP 562 惰性方式暴露剪枝入口,不修改既有量化代码;与 classic/graph_based 剪枝器共存,并复用其精度抽象 AutoCalibrationEvaluatorBase,使 prune→quantize 在同一预算下串联。 公开接口(__all__,与量化 1:1 对齐): - amct.prune(model, config=None, *, data, tolerance, evaluator, size_budget, finetune_fn, report) —— 原地剪枝,返回 None;可选传入 report=PruneReport() 就地收集统计(不保留任何进程级状态)。 - amct.accuracy_based_auto_prune(...) —— 按可接受精度损失自动搜索并应用满足容差的最大剪枝率,返回 AutoTuneResult,对应量化侧 accuracy_based_auto_calibration。 - 预定义配置 *_PRUNE_CFG:CNN_RECONSTRUCT / CNN_VARIANCE / DENSE_LOWVAR / FULL_STRUCTURED / MOE_MASSVAR / MOE_OUTPUT_MERGE / SENSITIVITY_ALLOC。 size_budget_prune / prune_finetune / prune_diagnose 及菜单配置为高级接口,可从 amct_pytorch.pruning 导入,不进入 __all__。剪枝与量化为正交压缩维度:先 prune 改变形状,再 amct.quantize / amct.convert。 ### 实测参考 在 16 个从零训练模型(CNN@MNIST / Dense-LM·MoE-LM@WikiText)与真实预训练 HF 模型上测得,供评审参考: - **CNN 输出保持重建**:训练后 MNIST CNN @0.3,naive variance_channel 0.343 vs reconstruct 0.574(参数量相同)。 - **Dense-LM 1% 预算空间**:无 finetune ≈0%;单遍 finetune(lr 1e-5 + warmup)后中位 27%(最高 61%)。真实 MoE(granite-1b-a400m)同样需要 finetune(≈0% → 17%)。 - **MoE 专家判据依赖路由深度**:全局 variance 劣于 mass,仅深层用 variance(boundary=K)在多专家路由上胜过 mass(OLMoE held-ppl 46.9→35.3);小专家路由(granite,32 专家)下菜单守卫正确回退到 mass。 - **敏感度分配依赖深度**:浅层网络(<10 层)6/6 胜,深层(≥10 层)4/19;guard='calib_nll' 在更差时回退均匀分配。 - **prune→int8 串联**:经恢复菜单剪枝的 SmolLM-135M 走完整 prune→int8→convert 流水线,ppl 1.649 → 剪枝后 1.699 → 叠加 int8 1.704。 ## 如何测试 本地运行单元测试: python -m pytest tests/amct_pytorch/test_pruning_*.py 覆盖核心剪枝、容差自动搜索、跨层敏感度分配、尺寸预算模式、MoE 输出合并、prune→quantize 串联,以及真实 HF 模型(Mixtral / Qwen3Moe / GraniteMoe / DeepseekV3 / Ernie4_5_Moe 等),全部通过。 ## 文档更新 - 新增 docs/zh/api/:prune.md、accuracy_based_auto_prune.md、size_budget_prune.md、prune_finetune.md、prune_diagnose.md、pruning_configs.md,并在 docs/zh/api/README.md 索引中登记。 - 新增示例 examples/algorithms/pruning/(dense / CNN / MoE)。 - amct_pytorch/pruning/README.md / README_en.md 增补“工作原理”走查(打分 → 剪枝 → 恢复 →(可选)量化),并配 5 张流程图(总流程、三个可剪枝的域、容差二分搜索、菜单择优、prune→quantize 串联),图片位于 amct_pytorch/pruning/figures/。 ## 类型标签 - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [x] 文档更新 - [ ] 代码重构 - [ ] 其他,请描述: See merge request: cann/amct!140 | 24 天前 | |
style: 执行 pre-commit 格式化(#161) Co-authored-by: fujun19<fujun19@hisilicon.com> # message auto-generated for no-merge-commit merge: !228 merge chore/precommit-format-161 into master style: 执行 pre-commit 格式化(#161) Created-by: fujun19 Commit-by: fujun19 Merged-by: cann-robot Description: ## 描述 按照 issue #161 提到的 pre-commit 本地格式化方法,对仓内 tracked C/C++ 和 Python 文件执行格式化。本 PR 仅包含 clang-format / ruff-format 自动格式化结果,不包含 ruff 历史例外配置。 ## 如何测试 - pre-commit run clang-format --all-files:Passed - pre-commit run ruff-format --all-files:Passed - 未运行完整 pre-commit run --all-files;ruff-check 的历史例外按要求未纳入本次提交。 ## 文档更新 无。 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 代码重构 - [x] 其他,请描述:pre-commit 格式化 See merge request: cann/amct!228 | 1 个月前 | |
feat: 新增 HiGPTQ 校准算法支持 Co-authored-by: zhangj1an<lanzhao944@gmail.com> Co-authored-by: zhangj1an<jianmusings@gmail.com> # message auto-generated for no-merge-commit merge: !252 merge higptq_cli into master feat: 新增 HiGPTQ 校准算法支持 Created-by: nancycyzl Commit-by: zl;Zhang Jian;ZL_PC;zhangj1an Merged-by: cann-robot Description: ## Description 本提议新增 HiGPTQ,把经典 GPTQ 的 Hessian 累积 + Cholesky 闭式求解思路引入 LLM PTQ 框架,并针对 HiFloat4(HiF4) 这个块浮点格式做适配。 AMCT PTQ 框架( amct_pytorch.ptq / LlmPtqWorkflow) 现有的算法(LAC、LWC、AutoRound、OmniQuant、FlatQuant)都是"可微分/可迭代"一类,以 weight/activation/structure 为 target 插件式串进 QuantLinear 正向传播,靠 BlockwiseSolver 反向传播+优化器多轮迭代求解。GPTQ / HiGPTQ 这种单次前向、闭式求解的路径,没有可学习参数,求解方式和上述算法不同。但只需要把求解过程中的中间结果罗盘,就可以复用框架现有的 BlockwiseSolver 和插件机制。 本提议延续框架现有的结构(CLI → LlmPtqWorkflow → Blockwise Solver → 具体算法),新增一个模块: - GPTQuant(amct_pytorch/algorithms/quant/gptq.py):继承 QuantAlgorithmBase,实现基于 INT 和 HiF4 的 GPTQ 算法。 ## How to Test 1. Unit test python -m pytest tests/unit_test/algorithms/test_higptq.py -v 结果: (amct) [ma-user amct]$python -m pytest tests/unit_test/algorithms/test_higptq.py -v ==================================================================================================== test session starts ===================================================================================================== platform linux -- Python 3.11.15, pytest-9.1.1, pluggy-1.6.0 -- /home/ma-user/.conda/envs/amct/bin/python cachedir: .pytest_cache rootdir: /home/ma-user/work/z84448474/amct configfile: pyproject.toml plugins: xdist-3.6.1, typeguard-4.5.2, anyio-4.14.1, env-1.7.0 collected 8 items tests/unit_test/algorithms/test_higptq.py::test_higptq_is_registered_as_a_calibrate_solver_algo PASSED [ 12%] tests/unit_test/algorithms/test_higptq.py::test_cal_scale_offset_static_has_no_external_quant_factors PASSED [ 25%] tests/unit_test/algorithms/test_higptq.py::test_cal_quant_weight_group_delegates_to_hifloat4_fake_quant PASSED [ 37%] tests/unit_test/algorithms/test_higptq.py::test_single_group_optimization_matches_direct_hifloat4_quant PASSED [ 50%] tests/unit_test/algorithms/test_higptq.py::test_dead_hessian_column_is_zeroed_before_quantization PASSED [ 62%] tests/unit_test/algorithms/test_higptq.py::test_optimization_handles_column_counts_not_aligned_to_group_or_block_size PASSED [ 75%] tests/unit_test/algorithms/test_higptq.py::test_fake_quant_forward_quantizes_once_and_reuses_cache PASSED [ 87%] tests/unit_test/algorithms/test_higptq.py::test_forward_updates_weight_after_batch_num_then_switches_to_fake_quant PASSED [100%] ===================================================================================================== 8 passed in 1.47s ====================================================================================================== 2. 端到端测试 a) 保存激活值 通过 amct_pytorch.extract_ptq_data 保存激活值,需对不同类型层分别运行,比如 --quant_target mlp 或者 --quant_target attn_linear python -m amct_pytorch.extract_ptq_data \ --model /home/ma-user/work/z84448474/models/Qwen3.5-9B \ --model_name qwen3_5 \ --seq_len 4096 \ --granularity block \ --device npu:0 \ --data_dir ptq_data/qwen3_5/mlp \ --quant_target mlp b) 运行 HiGPTQ 算法 需对不同类型层分别运行,比如 --quant_target mlp 或者 --quant_target attn_linear,以及配置对应的 --data_dir python -m amct_pytorch.ptq \ --model /home/ma-user/work/z84448474/models/Qwen3.5-9B \ --model_name qwen3_5 \ --seq_len 4096 \ --granularity block \ --device npu:0 \ --data_dir /data/z84448474/z84448474/ptq_data/qwen3_5/mlp \ --quant_dtype hifp \ --algos gptq \ --bit_config amct_pytorch/configs/hifloat4.yaml \ --quant_target mlp \ --moe_mlp_param_dir ptq_result/ptq_params/qwen3_5/mlp \ --output_dir ptq_result/ c) 进行 PPL 测评 配置 --attn_linear_param_dir 和 --moe_mlp_param_dir 等路径(第二步的结果) python -m amct_pytorch.eval \ --model /home/ma-user/work/z84448474/models/Qwen3.5-9B \ --model_name qwen3_5 \ --seq_len 4096 \ --granularity block \ --device npu:0 \ --eval_mode quant \ --quant_target mlp attn-linear \ --quant_dtype hifp \ --bit_config amct_pytorch/configs/hifloat4.yaml \ --attn_linear_param_dir ptq_result/ptq_params/qwen3_5/attn-linear \ --moe_mlp_param_dir ptq_result/ptq_params/qwen3_5/mlp 测试结果(PPL对比): HiF4 直转 (w4a16):9.948 HiGPTQ 校准后:8.401 ## Type Label <!-- [x] indicates selected --> - [ ] Bug fix - [x] New feature - [ ] Performance optimization - [ ] Documentation update - [ ] Code refactoring - [ ] Other, please describe: See merge request: cann/amct!252 | 19 天前 | |
build: use cann third party protobuf Co-authored-by: fujun19<fujun19@hisilicon.com> # message auto-generated for no-merge-commit merge: !124 merge fix/use-add-cann-third-party into master build: use cann third party protobuf Created-by: fujun19 Commit-by: fujun19 Merged-by: cann-robot Description: 关联 Issue:#121 ## 描述 将本仓 protobuf 三方依赖迁移到 cann-cmake 统一入口: - 使用 add_cann_third_party(protobuf) 替换本地 cmake/third_party/protobuf.cmake。 - 开启 ENABLE_OPEN_SRC,确保统一 protobuf 脚本创建 host_protoc、ascend_protobuf_static 等目标。 - 将 proto 编译路径从旧的 build/protobuf_host/bin/protoc 切换为 $<TARGET_FILE:host_protoc>。 - 删除迁移后不再需要的本地 protobuf 脚本和 patch 文件。 ## 如何测试 - git diff --check - cmake -S . -B build_add_cann_third_party_default_check -DENABLE_TEST=OFF - cmake -S . -B build_add_cann_third_party_test_check -DENABLE_TEST=ON 说明:ENABLE_TEST=ON 配置过程中当前环境会打印已有的 torch_npu 后端符号错误 traceback,但 CMake 退出码为 0 并完成配置生成。 ## 文档更新 不涉及文档更新。 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 代码重构 - [x] 其他,请描述:构建依赖迁移 See merge request: cann/amct!124 | 3 个月前 | |
[feat]: add amct llm Co-authored-by: w00852777<wanghui432@huawei.com> Co-authored-by: fujun19<fujun19@hisilicon.com> Co-authored-by: SwaggyAlex<zhangyi601@huawei.com> Co-authored-by: li_ting<liting73@hisilicon.com> # message auto-generated for no-merge-commit merge: !102 merge master into master [feat]: add amct llm Created-by: fujun19 Commit-by: SwaggyAlex;fujun19;wuranxx;li_ting;l00968832;lianghengyi;sophia1213;Hengyi Liang;w00852777 Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> 本 PR 新增LLM量化工具模块,用于面向大语言模型的后训练量化、精度评估和部署产物导出,主要包括: 1. 新增并整理 LLM 量化工作流能力 - 新增 amct_pytorch/workflows 与 amct_pytorch/cli/llm,覆盖 PTQ、PTQ 数据提取、部署导出、评估等流程。 - 新增通用配置解析、数据处理、模型适配、量化应用、优化器等公共模块。 - 补充 Qwen、LongCat、DeepSeek、GLM 等 LLM 模型适配与量化模块。 2. 调整 AMCT PyTorch 包结构 - 引入 algorithms、common、quantization、workflows 等更清晰的模块划分。 - 将 classic 图量化相关实现收敛到 amct_pytorch/classic/graph_based,保持历史能力可用。 - 修正安装包数据路径,确保 classic graph-based 相关 proto、so、配置等资源能正确打包。 3. 完善构建与测试能力 - build.sh -u 默认开启覆盖率采集。 - 新增 pyproject.toml,统一 pytest 与 coverage 配置。 - 调整 CMake UT 入口,使用 pytest 执行 tests/unit_test 与 tests/amct_pytorch。 - 大幅补充算法、配置、LLM 模型适配、量化模块、workflow 等单元测试。 4. 更新依赖、文档和样例 - 补充 LLM 相关运行依赖,如 datasets、accelerate、compressed_tensors、torchao、einops 等。 - 更新 README、算法说明、LLM 文档、快速安装和 PTQ 配置说明。 - 新增/整理一站式平台样例,包括 Qwen3.6-MoE、DeepSeek-V4 Flash,以及 PTQ、部署、评估、数据提取脚本。 - 将算法样例统一整理到 examples/algorithms 目录,提升样例可发现性和可维护性。 ## 如何测试 <!--描述测试此改动的步骤和前提条件。--> 已进行以下验证: 1. UT 与覆盖率验证 bash build.sh -u 结果: 1911 passed, 2 skipped, 1 xfailed, 371 warnings Coverage XML written to build/coverage.xml ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> - 更新根目录 README.md,补充 AMCT PyTorch 当前包结构、核心能力、一站式平台快速体验入口,并修正 amct_ops 文档链接。 - 更新 docs/AMCT_Pytorch_LLM.md,补充 LLM 量化流程说明,包括 PTQ 数据提取、PTQ 执行、部署导出和评估流程。 - 更新 docs/algorithm_brief.md,同步当前支持的量化算法说明。 - 更新 docs/context/ptq_config_param.md,修正配置示例引用路径,避免文档中的样例路径不可用。 - 更新 docs/quick_install.md 与 docs/README.md,同步依赖安装、构建验证和特性说明。 - 更新 examples/README.md,重新整理样例入口,明确算法样例与模型端到端样例的使用路径。 - 新增/完善 Qwen3.6-MoE 与 DeepSeek-V4 Flash 一站式平台样例文档,降低用户在 Atlas A3 环境中完成 NPU 推理体验的上手成本。 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 代码重构 - [ ] 其他,请描述: See merge request: cann/amct!102 | 3 个月前 | |
[feat]: add amct llm Co-authored-by: w00852777<wanghui432@huawei.com> Co-authored-by: fujun19<fujun19@hisilicon.com> Co-authored-by: SwaggyAlex<zhangyi601@huawei.com> Co-authored-by: li_ting<liting73@hisilicon.com> # message auto-generated for no-merge-commit merge: !102 merge master into master [feat]: add amct llm Created-by: fujun19 Commit-by: SwaggyAlex;fujun19;wuranxx;li_ting;l00968832;lianghengyi;sophia1213;Hengyi Liang;w00852777 Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> 本 PR 新增LLM量化工具模块,用于面向大语言模型的后训练量化、精度评估和部署产物导出,主要包括: 1. 新增并整理 LLM 量化工作流能力 - 新增 amct_pytorch/workflows 与 amct_pytorch/cli/llm,覆盖 PTQ、PTQ 数据提取、部署导出、评估等流程。 - 新增通用配置解析、数据处理、模型适配、量化应用、优化器等公共模块。 - 补充 Qwen、LongCat、DeepSeek、GLM 等 LLM 模型适配与量化模块。 2. 调整 AMCT PyTorch 包结构 - 引入 algorithms、common、quantization、workflows 等更清晰的模块划分。 - 将 classic 图量化相关实现收敛到 amct_pytorch/classic/graph_based,保持历史能力可用。 - 修正安装包数据路径,确保 classic graph-based 相关 proto、so、配置等资源能正确打包。 3. 完善构建与测试能力 - build.sh -u 默认开启覆盖率采集。 - 新增 pyproject.toml,统一 pytest 与 coverage 配置。 - 调整 CMake UT 入口,使用 pytest 执行 tests/unit_test 与 tests/amct_pytorch。 - 大幅补充算法、配置、LLM 模型适配、量化模块、workflow 等单元测试。 4. 更新依赖、文档和样例 - 补充 LLM 相关运行依赖,如 datasets、accelerate、compressed_tensors、torchao、einops 等。 - 更新 README、算法说明、LLM 文档、快速安装和 PTQ 配置说明。 - 新增/整理一站式平台样例,包括 Qwen3.6-MoE、DeepSeek-V4 Flash,以及 PTQ、部署、评估、数据提取脚本。 - 将算法样例统一整理到 examples/algorithms 目录,提升样例可发现性和可维护性。 ## 如何测试 <!--描述测试此改动的步骤和前提条件。--> 已进行以下验证: 1. UT 与覆盖率验证 bash build.sh -u 结果: 1911 passed, 2 skipped, 1 xfailed, 371 warnings Coverage XML written to build/coverage.xml ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> - 更新根目录 README.md,补充 AMCT PyTorch 当前包结构、核心能力、一站式平台快速体验入口,并修正 amct_ops 文档链接。 - 更新 docs/AMCT_Pytorch_LLM.md,补充 LLM 量化流程说明,包括 PTQ 数据提取、PTQ 执行、部署导出和评估流程。 - 更新 docs/algorithm_brief.md,同步当前支持的量化算法说明。 - 更新 docs/context/ptq_config_param.md,修正配置示例引用路径,避免文档中的样例路径不可用。 - 更新 docs/quick_install.md 与 docs/README.md,同步依赖安装、构建验证和特性说明。 - 更新 examples/README.md,重新整理样例入口,明确算法样例与模型端到端样例的使用路径。 - 新增/完善 Qwen3.6-MoE 与 DeepSeek-V4 Flash 一站式平台样例文档,降低用户在 Atlas A3 环境中完成 NPU 推理体验的上手成本。 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 代码重构 - [ ] 其他,请描述: See merge request: cann/amct!102 | 3 个月前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 21 天前 | ||
| 24 天前 | ||
| 1 个月前 | ||
| 19 天前 | ||
| 3 个月前 | ||
| 3 个月前 | ||
| 3 个月前 |