diff --git "a/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/README.md" "b/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/README.md" index e504fa9f28690c0519334a088035f61c7167602b..cd3b369a37557ba6a160e89886c188826f3433ca 100644 --- "a/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/README.md" +++ "b/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/README.md" @@ -30,6 +30,12 @@ bash ./test/train_full_8p.sh --data_path=real_data_path # training 8p performance bash ./test/train_performance_8p.sh --data_path=real_data_path + +#test 8p accuracy +bash test/train_eval_8p.sh --data_path=real_data_path --weight_path=real_pre_train_model_path + +# finetuning 1p +bash test/train_finetune_1p.sh --data_path=real_data_path --weight_path=real_pre_train_model_path ``` Log path: diff --git "a/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/main.py" "b/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/main.py" index a99b07efc19ac24399e8c4b512e67653d42a4315..2cd1f50ed96be48de00bcacf85e36bb81bb7573a 100644 --- "a/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/main.py" +++ "b/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/main.py" @@ -65,6 +65,8 @@ parser.add_argument('-e', '--evaluate', dest='evaluate', action='store_true', help='evaluate model on validation set') parser.add_argument('--pretrained', dest='pretrained', action='store_true', help='use pre-trained model') +parser.add_argument('--weight_path', default='', help='pretrained weight path') +parser.add_argument('--num_classes', default=None,type=int, help='num_classes') parser.add_argument('--world-size', default=-1, type=int, help='number of nodes for distributed training') parser.add_argument('--rank', default=-1, type=int, @@ -189,9 +191,16 @@ def main_worker(gpu, ngpus_per_node, args): if args.pretrained: print("=> using pre-trained model wide_resnet50_2") model = resnet_0_6_0.wide_resnet50_2(num_classes=args.num_classes) - print("loading model of yours...") - pretrained_dict = torch.load("./model_best.pth.tar", map_location="cpu")["state_dict"] + + if os.path.exists(args.weight_path): + print("loading model of your give") + pretrained_dict = torch.load(args.weight_path, map_location="cpu")["state_dict"] + else: + print("loading model default ") + pretrained_dict = torch.load("./model_best.pth.tar", map_location="cpu")["state_dict"] + model.load_state_dict({k.replace('module.',''):v for k, v in pretrained_dict.items()}) + if "fc.weight" in pretrained_dict: pretrained_dict.pop('fc.weight') pretrained_dict.pop('fc.bias') @@ -359,7 +368,10 @@ def main_worker(gpu, ngpus_per_node, args): num_workers=args.workers, pin_memory=False, drop_last=True) if args.evaluate: + print("===eval start===") validate(val_loader, model, criterion, args, ngpus_per_node) + print("===eval over===") + return if args.prof: @@ -389,6 +401,7 @@ def main_worker(gpu, ngpus_per_node, args): and args.rank % ngpus_per_node == 0): ############## npu modify begin ############# + print("=========save model======") if args.amp: save_checkpoint({ 'epoch': epoch + 1, diff --git "a/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/test/train_eval_8p.sh" "b/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/test/train_eval_8p.sh" index 7f09f2fbfe86ed7dd5925d55228290cfb1d9dc1f..0afbaaf4580816fe0b2911daa1a569838337641d 100644 --- "a/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/test/train_eval_8p.sh" +++ "b/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/test/train_eval_8p.sh" @@ -9,8 +9,8 @@ batch_size=4096 # 训练使用的npu卡数 export RANK_SIZE=8 # checkpoint文件路径,以实际路径为准 -resume=/home/checkpoint.pth.tar -# 数据集路径,保持为空,不需要修改 +# resume=/home/checkpoint.pth.tar +# 数据集路径,需要根据实际情况填入 data_path="" # 训练epoch @@ -28,6 +28,8 @@ do workers=`echo ${para#*=}` elif [[ $para == --data_path* ]];then data_path=`echo ${para#*=}` + elif [[ $para == --weight_path* ]];then + weight_path=`echo ${para#*=}` fi done @@ -73,7 +75,6 @@ fi python3.7 ./main.py \ ${data_path} \ --evaluate \ - --resume ${resume} \ --addr=$(hostname -I |awk '{print $1}') \ --seed=49 \ --workers=${workers} \ @@ -91,6 +92,8 @@ python3.7 ./main.py \ --warm_up_epochs=5 \ --loss-scale=32 \ --amp \ + --pretrained \ + --weight_path=${weight_path} \ --batch-size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & wait diff --git "a/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/test/train_finetune_1p.sh" "b/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/test/train_finetune_1p.sh" index 30dac86bf9162a5421cb525f0d8363fec42009f0..f87422ddcb6c197f55ce9a20da315d8cfb09eae6 100644 --- "a/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/test/train_finetune_1p.sh" +++ "b/Pytorch\350\256\255\347\273\203\347\244\272\344\276\213/WideResNet50_2_ID1627_for_PyTorch/test/train_finetune_1p.sh" @@ -25,6 +25,8 @@ do device_id=`echo ${para#*=}` elif [[ $para == --data_path* ]];then data_path=`echo ${para#*=}` + elif [[ $para == --weight_path* ]];then + weight_path=`echo ${para#*=}` fi done @@ -94,8 +96,8 @@ python3.7 ./main.py \ --warm_up_epochs=5 \ --loss-scale=32 \ --amp \ - --pretrained \ --num_classes=1200 \ + --resume=${weight_path} \ --batch-size=${batch_size} > ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 & wait diff --git "a/pytorch-train-guide/Pytorch\350\256\255\347\273\203-FAQ.md" "b/pytorch-train-guide/Pytorch\350\256\255\347\273\203-FAQ.md" index 7cd2438d6b3ca93d957c7b5a569a197032397c86..56e4d679410a6db01a7952091eb39e333fad58ed 100644 --- "a/pytorch-train-guide/Pytorch\350\256\255\347\273\203-FAQ.md" +++ "b/pytorch-train-guide/Pytorch\350\256\255\347\273\203-FAQ.md" @@ -1,1063 +1,1128 @@ -# Ascend PyTorch训练常见问题FAQ -- [Ascend PyTorch训练常见问题FAQ](#ascend-pytorch训练常见问题faq) -- [1 介绍](#1-介绍) -- [2 常见问题FAQ](#2-常见问题faq) - - [2.1 NPU模型打通常见问题FAQ](#21-npu模型打通常见问题faq) - - [FAQ1、在模型运行或者算子运行时遇到报错,“RuntimeError: ExchangeDevice:”](#faq1在模型运行或者算子运行时遇到报错runtimeerror-exchangedevice) - - [FAQ2、在模型运行或者算子运行时遇到报错,“Error in atexit._run_exitfuncs:”](#faq2在模型运行或者算子运行时遇到报错error-in-atexit_run_exitfuncs) - - [FAQ3、在模型运行遇到报错,“terminate called after throwing an instance of 'c10::Error' what(): HelpACLExecute:”](#faq3在模型运行遇到报错terminate-called-after-throwing-an-instance-of-c10error-what--helpaclexecute) - - [FAQ4、在模型调测遇到报错,“RuntimeError: malloc:/..../pytorch/c10/npu/NPUCachingAllocator.cpp:293 NPU error, error code is 500000.”](#faq4在模型调测遇到报错runtimeerror-mallocpytorchc10npunpucachingallocatorcpp293-npu-error-error-code-is-500000) - - [FAQ5、在模型调测遇到报错,RuntimeError: Could not run 'aten::trunc.out' with arguments from the 'NPUTensorId' backend.](#faq5在模型调测遇到报错runtimeerror-could-not-run-atentruncout-with-arguments-from-the-nputensorid-backend) - - [FAQ6、在模型调测中,遇到某个算子报错的情况,如下分别为MaxPoolGradWithArgmaxV1算子和max算子报错。](#faq6在模型调测中遇到某个算子报错的情况如下分别为maxpoolgradwithargmaxv1算子和max算子报错) - - [FAQ7、在模型运行遇到报错,ImportError: libhccl.so.](#faq7在模型运行遇到报错importerror-libhcclso) - - [FAQ8、在模型运行将多任务下发关闭(export TASK_QUEUE_ENABLE=0)后仍然遇到报错,HelpACLExecute.](#faq8在模型运行将多任务下发关闭export-task_queue_enable0后仍然遇到报错helpaclexecute) - - [FAQ9、在模型运行遇到报错,RuntimeError: Initialize.](#faq9在模型运行遇到报错runtimeerror-initialize) - - [FAQ10、在模型运行遇到报错,TVM/te/cce error.](#faq10在模型运行遇到报错tvmtecce-error) - - [FAQ11、在调用torch时,遇到ModuleNotFoundError: No module named 'torch._C'报错。](#faq11在调用torch时遇到modulenotfounderror-no-module-named-torch_c报错) - - [FAQ12、cuda流同步操作报错。](#faq12cuda流同步操作报错) - - [FAQ13、aicpu_kernels/libpt_kernels.so找不到](#faq13aicpu_kernelslibpt_kernelsso找不到) - - [FAQ14、npu-smi info 查看显存时发现有残留](#faq14npu-smi-info-查看显存时发现有残留) - - [FAQ15、match op inputs failed](#faq15match-op-inputs-failed) - - [FAQ16、Op type SigmoidCrossEntropyWithLogitsV2 of ops kernel AIcoreEngine is unsupported,](#faq16op-type-sigmoidcrossentropywithlogitsv2-of-ops-kernel-aicoreengine-is-unsupported) - - [FAQ17、Hook失败](#faq17hook失败) - - [FAQ18、模型报错运行时MemCopySync:drvMemcpy failed.](#faq18模型报错运行时memcopysyncdrvmemcpy-failed) - - [FAQ19、加载权重时发生load state_dict error.](#faq19加载权重时发生load-state_dict-error) - - [FAQ20、加载数据集时发生cannot identify image.](#faq20加载数据集时发生cannot-identify-image) - - [FAQ21、timm框架版本问题导致错误](#faq21timm框架版本问题导致错误) - - [FAQ22、GPU场景下安装DCN2v模块](#faq22gpu场景下安装dcn2v模块) - - [FAQ23、模型训练时报libtorch_npu.so: undefined symbol: aclopSetCompileFlag错误。](#faq23模型训练时报libtorch_npuso-undefined-symbol-aclopsetcompileflag错误) - - [FAQ24、模型训练时报fill算子错误](#faq24模型训练时报fill算子错误) - - [FAQ25、cpu下运行scatter算子报错:RuntimeError: index 4558486308284583594 is out of bounds for dimension 1 with size 4233.](#faq25cpu下运行scatter算子报错runtimeerror-index-4558486308284583594-is-out-of-bounds-for-dimension-1-with-size-4233) - - [FAQ26、NPU训练时,第一个batch训练速度特别慢,第二个开始速度正常,和gpu差不多。](#faq26npu训练时第一个batch训练速度特别慢第二个开始速度正常和gpu差不多) - - [FAQ26、pip安装包 matplotlib pillow numpy scipy xtcocotools torchvision 等包,在x86环境安装顺利但是在arm环境失败](#faq26pip安装包-matplotlib-pillow-numpy-scipy-xtcocotools-torchvision-等包在x86环境安装顺利但是在arm环境失败) - - [FAQ27、模型训练时出现argmax算子计算问题。](#faq27模型训练时出现argmax算子计算问题) - - [FAQ28、模型推理时加载pth出现问题。](#faq28模型推理时加载pth出现问题) - - [FAQ29、多个环境都遇到了安装升级5.0.1的toolkit包,安装时报错的问题。](#faq29多个环境都遇到了安装升级501的toolkit包安装时报错的问题) - - [FAQ30、某个算子不支持,GE层报错,如何排查](#faq30某个算子不支持ge层报错如何排查) - - [FAQ31 dict加载的时候提示key缺少](#faq31-dict加载的时候提示key缺少) - - [FAQ32 pip3报错](#faq32-pip3报错) - - [FAQ33 toolkit包安装报错](#faq33-toolkit包安装报错) - - [FAQ34 driver安装crl报错](#faq34-driver安装crl报错) - - [FAQ35 onnx安装问题, protobuf-compiler缺失](#faq35-onnx安装问题-protobuf-compiler缺失) - - [FAQ36 conda拷贝环境后发现pip使用不了](#faq36--conda拷贝环境后发现pip使用不了报错如下) - - [FAQ37 执行pip安装的时候缺少so的包](#faq37--执行pip安装的时候缺少so的包) - - [FAQ38 环境安装前需要基础依赖安装](#faq38-环境安装前需要基础依赖安装) - - [FAQ39 conda使用,外部的python环境指定的不是自己安装的版本](#faq39-conda使用外部的python环境指定的不是自己安装的版本) - - [FAQ40、Alexnet dropout 精度不达标规避方法。](#faq40alexnet-dropout-精度不达标规避方法) - - [FAQ41、mmdet在做hook定位时反向过程报错](#faq41mmdet在做hook定位时反向过程报错) - - [FAQ42、如何确定模型中是否有动态算子](#faq42如何确定模型中是否有动态算子) - - [FAQ43、模型训练过程报ACL stream的错误](#faq43模型训练过程报acl-stream的错误) - - [FAQ44、模型刚开始训练没有报错或日志信息,等待时间久](#faq44模型刚开始训练没有报错或日志信息等待时间久) - - [FAQ45、模型训练过程DCNv2算子+混合精度报错:excepted scalar type float but found half](#faq45模型训练过程dcnv2算子混合精度报错excepted-scalar-type-float-but-found-half) - - [FAQ46、模型训练过程中算子PadV3D报错:constant_values value mismatches](#faq46模型训练过程中算子padv3d报错constant_values-value-mismatches) - - [FAQ47、模型训练过程中python层报错:Expected isFloatingType(grad[i].scalar_type()) to be true, but got false](#faq47模型训练过程中报Expected-isFloatingType(grad[i].scalar_type())-to-be-true-but-got-false) - - [FAQ48、h5py安装方法](#faq48h5py安装方法) - - [2.2 NPU模型分布式运行常见问题FAQ](#22-npu模型分布式运行常见问题faq) - - [FAQ1、在模型分布式训练时,遇到报错 host not found.](#faq1在模型分布式训练时遇到报错-host-not-found) - - [FAQ2、在模型运行时,遇到eval模式下loss值特别大,过万.](#faq2在模型运行时遇到eval模式下loss值特别大过万) - - [FAQ3、在模型运行时,模型训练的精度和loss值多卡之间不同步.](#faq3在模型运行时模型训练的精度和loss值多卡之间不同步) - - [FAQ4、在模型运行时,模型训练跑到中途中断.](#faq4在模型运行时模型训练跑到中途中断) - -# [1 介绍](#1-介绍) - - 本文目标读者为Ascend模型迁移开发者,用于指导开发者在昇腾版本的 PyTorch + Apex 下,实现模型训练精度性能达标。这里仅列举模型迁移中遇到的常见问题与解决方法,持续更新。 - - -# [2 常见问题FAQ](#2-常见问题FAQ) - -## [2.1 NPU模型打通常见问题FAQ](#21-NPU模型打通常见问题FAQ) - -### FAQ1、在模型运行或者算子运行时遇到报错,“RuntimeError: ExchangeDevice:” - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq_1103.png) - -* 原因分析 - - 目前在一个线程内,只能调用一个npu设备,当切换不同的npu device时,会出现上述错误。 - -* 处理方法 - - 检查代码中在调用torch.npu.set_device(device)、tensor.to(device)或者model.to(device)时,同一个线程内前后调用时device名称不一致。对于多个线程情况(如多卡训练),每个线程也是只能调用固定的npu device。 - - -### FAQ2、在模型运行或者算子运行时遇到报错,“Error in atexit._run_exitfuncs:” - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq_6_1111.png) - -* 原因分析 - - 在torch初始化时,若未通过torch.npu.device(id)指定npu设备,则默认使用device 0设备。若直接使用其他npu设备,如指定在device 1上创建tensor,那么在运行时会出现上述错误。 - -* 处理方法 - - 在调用npu设备之前,通过torch.npu.set_device(device)指定需要使用的npu 设备即可。 - -### FAQ3、在模型运行遇到报错,“terminate called after throwing an instance of 'c10::Error' what(): HelpACLExecute:” - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_1103.png) - -* 原因分析 - - 目前HelpACLExecute的报错信息是无法直接找到报错位置的,这里是在task任务下发时报错,由于开启TASK多线程下发(export TASK_QUEUE_ENABLE=1),报错信息被上层封装起来,无法获取更加详细的报错日志。 - -* 处理方法 - - 遇到这种情况处理方式有两种:一是查看host日志,可以查看具体的报错日志信息。日志默认位置是/root/ascend/log/plog/下,可能会有多个日志文件,日志文件以host-0为前缀,根据时间标识查找对应的日志文件。打开日志文件,搜索“ERROR”,查询具体的报错信息。二是关闭多线程下发(export TASK_QUEUE_ENABLE=0),同时开启错误日志级别(export ASCEND_GLOBAL_LOG_LEVEL=3)然后再次运行代码,一般可根据终端报错信息知道错误原因。 - -### FAQ4、在模型调测遇到报错,“RuntimeError: malloc:/..../pytorch/c10/npu/NPUCachingAllocator.cpp:293 NPU error, error code is 500000.” - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq3_1109.png) - -* 原因分析 - - 对于NPUCachingAllocator中malloc类型的错误,一般是npu显存不足,所需显存小于npu上可用显存,导致报错。 - -* 处理方法 - - 在模型调测中,可用通过减小batch size参数,来减少NPU显存的分配,解决该问题。 - -### FAQ5、在模型调测遇到报错,RuntimeError: Could not run 'aten::trunc.out' with arguments from the 'NPUTensorId' backend. - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq5_1109.png) - -* 原因分析 - - 目前npu设备仅支持pytorch部分算子,对于不支持的算子在使用时均会报上述错误,算子正在不断开发中。[查看NPU设备已经支持的算子](https://support.huaweicloud.com/opl-pytorch/atlasptol_09_0001.html), 持续更新。 - -* 处理方法 - - 在模型调测中,可用通过减小batch size参数,来减少NPU显存的分配,解决该问题。 - - -### FAQ6、在模型调测中,遇到某个算子报错的情况,如下分别为MaxPoolGradWithArgmaxV1算子和max算子报错。 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq4_1109.png) - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq4_2_1109.png) - -* 原因分析 - - 在模型搭建中,算子输入参数是多样的。某些算子在特定参数下,计算报错或者不支持,根据报错信息可以定位到具体算子。 - -* 处理方法 - - 根据报错信息定位到具体算子,解决步骤如下: - 1) 排查模型中对该算子的调用方式和参数正确; - 2) 根据报错算子构建单算子用例,构建报错场景; - 3) 一般算子错误无法在python侧解决,构建出报错场景。在论坛中发帖附上报错场景,求助华为工程师即可。 - 注:输入参数shape 和 dtype需要重点关注,一般是导致算子报错的主要原因。 - - 前述图中,根据报错信息,定位到是MaxPoolGradWithArgmaxV1算子和max算子报错。MaxPoolGradWithArgmaxV1是在反向计算过程中报错,那么构建测试用例时需要构建对应的反向场景; - 而对于max算子,是正向计算时报错,构建正向场景即可。在模型中遇到算子报错,首选是仅构建单算子测试用例,确定报错场景和原因即可;若无法在单算子中构建单算子用例,则需要构建基于上下文的单算子场景, 可以参考[Ascend PyTorch模型迁移指导.md](https://gitee.com/ascend/docs-dev/blob/master/tutorials/Ascend%20PyTorch%E6%A8%A1%E5%9E%8B%E8%BF%81%E7%A7%BB%E6%8C%87%E5%AF%BC.md#44-%E5%8D%95%E7%AE%97%E5%AD%90%E7%94%A8%E4%BE%8B%E7%BC%96%E5%86%99%E8%AF%B4%E6%98%8E) 编写用例。 +* # Ascend PyTorch训练常见问题FAQ + - [Ascend PyTorch训练常见问题FAQ](#ascend-pytorch训练常见问题faq) + - [1 介绍](#1-介绍) + - [2 常见问题FAQ](#2-常见问题faq) + - [2.1 NPU模型打通常见问题FAQ](#21-npu模型打通常见问题faq) + - [FAQ1、在模型运行或者算子运行时遇到报错,“RuntimeError: ExchangeDevice:”](#faq1在模型运行或者算子运行时遇到报错runtimeerror-exchangedevice) + - [FAQ2、在模型运行或者算子运行时遇到报错,“Error in atexit._run_exitfuncs:”](#faq2在模型运行或者算子运行时遇到报错error-in-atexit_run_exitfuncs) + - [FAQ3、在模型运行遇到报错,“terminate called after throwing an instance of 'c10::Error' what(): HelpACLExecute:”](#faq3在模型运行遇到报错terminate-called-after-throwing-an-instance-of-c10error-what--helpaclexecute) + - [FAQ4、在模型调测遇到报错,“RuntimeError: malloc:/..../pytorch/c10/npu/NPUCachingAllocator.cpp:293 NPU error, error code is 500000.”](#faq4在模型调测遇到报错runtimeerror-mallocpytorchc10npunpucachingallocatorcpp293-npu-error-error-code-is-500000) + - [FAQ5、在模型调测遇到报错,RuntimeError: Could not run 'aten::trunc.out' with arguments from the 'NPUTensorId' backend.](#faq5在模型调测遇到报错runtimeerror-could-not-run-atentruncout-with-arguments-from-the-nputensorid-backend) + - [FAQ6、在模型调测中,遇到某个算子报错的情况,如下分别为MaxPoolGradWithArgmaxV1算子和max算子报错。](#faq6在模型调测中遇到某个算子报错的情况如下分别为maxpoolgradwithargmaxv1算子和max算子报错) + - [FAQ7、在模型运行遇到报错,ImportError: libhccl.so.](#faq7在模型运行遇到报错importerror-libhcclso) + - [FAQ8、在模型运行将多任务下发关闭(export TASK_QUEUE_ENABLE=0)后仍然遇到报错,HelpACLExecute.](#faq8在模型运行将多任务下发关闭export-task_queue_enable0后仍然遇到报错helpaclexecute) + - [FAQ9、在模型运行遇到报错,RuntimeError: Initialize.](#faq9在模型运行遇到报错runtimeerror-initialize) + - [FAQ10、在模型运行遇到报错,TVM/te/cce error.](#faq10在模型运行遇到报错tvmtecce-error) + - [FAQ11、在调用torch时,遇到ModuleNotFoundError: No module named 'torch._C'报错。](#faq11在调用torch时遇到modulenotfounderror-no-module-named-torch_c报错) + - [FAQ12、cuda流同步操作报错。](#faq12cuda流同步操作报错) + - [FAQ13、aicpu_kernels/libpt_kernels.so找不到](#faq13aicpu_kernelslibpt_kernelsso找不到) + - [FAQ14、npu-smi info 查看显存时发现有残留](#faq14npu-smi-info-查看显存时发现有残留) + - [FAQ15、match op inputs failed](#faq15match-op-inputs-failed) + - [FAQ16、Op type SigmoidCrossEntropyWithLogitsV2 of ops kernel AIcoreEngine is unsupported,](#faq16op-type-sigmoidcrossentropywithlogitsv2-of-ops-kernel-aicoreengine-is-unsupported) + - [FAQ17、Hook失败](#faq17hook失败) + - [FAQ18、模型报错运行时MemCopySync:drvMemcpy failed.](#faq18模型报错运行时memcopysyncdrvmemcpy-failed) + - [FAQ19、加载权重时发生load state_dict error.](#faq19加载权重时发生load-state_dict-error) + - [FAQ20、加载数据集时发生cannot identify image.](#faq20加载数据集时发生cannot-identify-image) + - [FAQ21、timm框架版本问题导致错误](#faq21timm框架版本问题导致错误) + - [FAQ22、GPU场景下安装DCN2v模块](#faq22gpu场景下安装dcn2v模块) + - [FAQ23、模型训练时报libtorch_npu.so: undefined symbol: aclopSetCompileFlag错误。](#faq23模型训练时报libtorch_npuso-undefined-symbol-aclopsetcompileflag错误) + - [FAQ24、模型训练时报fill算子错误](#faq24模型训练时报fill算子错误) + - [FAQ25、cpu下运行scatter算子报错:RuntimeError: index 4558486308284583594 is out of bounds for dimension 1 with size 4233.](#faq25cpu下运行scatter算子报错runtimeerror-index-4558486308284583594-is-out-of-bounds-for-dimension-1-with-size-4233) + - [FAQ26、NPU训练时,第一个batch训练速度特别慢,第二个开始速度正常,和gpu差不多。](#faq26npu训练时第一个batch训练速度特别慢第二个开始速度正常和gpu差不多) + - [FAQ26、pip安装包 matplotlib pillow numpy scipy xtcocotools torchvision 等包,在x86环境安装顺利但是在arm环境失败](#faq26pip安装包-matplotlib-pillow-numpy-scipy-xtcocotools-torchvision-等包在x86环境安装顺利但是在arm环境失败) + - [FAQ27、模型训练时出现argmax算子计算问题。](#faq27模型训练时出现argmax算子计算问题) + - [FAQ28、模型推理时加载pth出现问题。](#faq28模型推理时加载pth出现问题) + - [FAQ29、多个环境都遇到了安装升级5.0.1的toolkit包,安装时报错的问题。](#faq29多个环境都遇到了安装升级501的toolkit包安装时报错的问题) + - [FAQ30、某个算子不支持,GE层报错,如何排查](#faq30某个算子不支持ge层报错如何排查) + - [FAQ31 dict加载的时候提示key缺少](#faq31-dict加载的时候提示key缺少) + - [FAQ32 pip3报错](#faq32-pip3报错) + - [FAQ33 toolkit包安装报错](#faq33-toolkit包安装报错) + - [FAQ34 driver安装crl报错](#faq34-driver安装crl报错) + - [FAQ35 onnx安装问题, protobuf-compiler缺失](#faq35-onnx安装问题-protobuf-compiler缺失) + - [FAQ36 conda拷贝环境后发现pip使用不了](#faq36--conda拷贝环境后发现pip使用不了报错如下) + - [FAQ37 执行pip安装的时候缺少so的包](#faq37--执行pip安装的时候缺少so的包) + - [FAQ38 环境安装前需要基础依赖安装](#faq38-环境安装前需要基础依赖安装) + - [FAQ39 conda使用,外部的python环境指定的不是自己安装的版本](#faq39-conda使用外部的python环境指定的不是自己安装的版本) + - [FAQ40、Alexnet dropout 精度不达标规避方法。](#faq40alexnet-dropout-精度不达标规避方法) + - [FAQ41、mmdet在做hook定位时反向过程报错](#faq41mmdet在做hook定位时反向过程报错) + - [FAQ42、如何确定模型中是否有动态算子](#faq42如何确定模型中是否有动态算子) + - [FAQ43、模型训练过程报ACL stream的错误](#faq43模型训练过程报acl-stream的错误) + - [FAQ44、模型刚开始训练没有报错或日志信息,等待时间久](#faq44模型刚开始训练没有报错或日志信息等待时间久) + - [FAQ45、模型训练过程DCNv2算子+混合精度报错:excepted scalar type float but found half](#faq45模型训练过程dcnv2算子混合精度报错excepted-scalar-type-float-but-found-half) + - [FAQ46、模型训练过程中算子PadV3D报错:constant_values value mismatches](#faq46模型训练过程中算子padv3d报错constant_values-value-mismatches) + - [FAQ47、模型训练过程中python层报错:Expected isFloatingType(grad[i].scalar_type()) to be true, but got false](#faq47模型训练过程中报Expected-isFloatingType(grad[i].scalar_type())-to-be-true-but-got-false) + - [FAQ48、h5py安装方法](#faq48h5py安装方法) + - [2.2 NPU模型分布式运行常见问题FAQ](#22-npu模型分布式运行常见问题faq) + - [FAQ1、在模型分布式训练时,遇到报错 host not found.](#faq1在模型分布式训练时遇到报错-host-not-found) + - [FAQ2、在模型运行时,遇到eval模式下loss值特别大,过万.](#faq2在模型运行时遇到eval模式下loss值特别大过万) + - [FAQ3、在模型运行时,模型训练的精度和loss值多卡之间不同步.](#faq3在模型运行时模型训练的精度和loss值多卡之间不同步) + - [FAQ4、在模型运行时,模型训练跑到中途中断.](#faq4在模型运行时模型训练跑到中途中断) - -### FAQ7、在模型运行遇到报错,ImportError: libhccl.so. - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq6_1118.png) - -* 原因分析 - - 目前对外发布的pytorch安装包,默认是使用NPU和HCCL功能,因此在调用时需要将HCCL模块路径添加到环境变量中。根据报错信息,can not find libhccl.so,缺少hccl库文件。 - -* 处理方法 - - 将hccl模块的路径添加到环境变量中即可,一般hccl库文件路径是安装包下的.../fwkacllib/python/site-packages/hccl。 - - -### FAQ8、在模型运行将多任务下发关闭(export TASK_QUEUE_ENABLE=0)后仍然遇到报错,HelpACLExecute. - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq7_1118.png) - -* 原因分析 - - 目前pytorch算子在npu上运行,通过ACL接口调用底层经过优化的算子,部分算子发生错误时,报错信息获取异常,在上层报错信息显示为HelpACLExecute. 内部也正在对报错信息与日志逐步完善中。 - -* 处理方法 - - 查看host日志,确定报错算子和位置。日志默认路径为/var/log/npu/slog/host-0,查找对应时间的log文件,搜索ERROR字段,查找错误信息。如对上述的错误,查询日志中的ERROR字段为: - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq7_1_1118.png) - - 从日志信息EEROR部分可以发现,报错算子为topKD,报错原因是 The number of attrs in op desc and op store does not match. 定位到是topk算子错误,具体原因是算子参数不匹配。 在模型代码中查找topk算子调用位置,确定该算子是否可有其他算子代替,若可由其他算子报错,暂时使用代替方案,并将算子报错信息报告华为工程师。若无替代算子,请将算子报错信息通知华为工程师解决。 - - -### FAQ9、在模型运行遇到报错,RuntimeError: Initialize. - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq8_1118.png) - - -* 原因分析 - - 根据报错信息,是npu设备初始化错误。查看host日志内容,根据前述步骤查找日志。日志报错如下: - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq8_1_1118.png) - -* 处理方法 - - 从日志中定位到是在拉起npu设备时报错。一般可以通过重启服务器解决该问题,所有npu device也会重新启动。若重启服务器后,仍然存在该问题,检查安装的driver和fireware版本是否匹配,更换正确版本的driver和fireware,或者向华为工程师报告求助解决。 - - -### FAQ10、在模型运行遇到报错,TVM/te/cce error. - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq10_1118.png) - -* 原因分析 - - pytorch内调用npu类型算子时,强依赖于te、cce、tvm组件,pytorch、toolkit/nnae和te版本需要一致。在更新toolkit/nnae后,te等组件不会自动更新,当版本不匹配时,则会出现该报错。 - -* 处理方法 - - 更新te等组件版本,具体是需要更新te-*.whl和topi-*.whl安装包。在安装的toolkit或者nnae的fwkacllib子目录下(对于默认安装路径,在/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64目录下,更新安装包即可。在该目录下有安装包topi-0.4.0-py3-none-any.whl和te-0.4.0-py3-none-any.whl,分别运行 pip install --upgrade topi-0.4.0-py3-none-any.whl, pip install --upgrade te-0.4.0-py3-none-any.whl. - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq10_1_1118.png) - -### FAQ11、在调用torch时,遇到ModuleNotFoundError: No module named 'torch._C'报错。 - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq11_1123.png) - -* 原因分析 - - 首先确定报错位置,上述报错在.../code/pytorch/torch/__init__.py ,而当前运行路径在.../code/pytorch下,在执行import torch时,默认首先在当前目录下查找torch文件夹,因此会报错。这里应该是调用在系统目录下安装的torch包,而不是当前目录下的torch。 - -* 处理方法 - - 切换到其他目录执行脚本即可。 - -### FAQ12、cuda流同步操作报错。 - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq11_20210728.jpg) - -* 原因分析 - - npu请使用npu的流同步方法 - -* 处理方法 - - ```python - stream = torch.npu.current_stream() - stream.synchronize() - ``` - - -### FAQ13、aicpu_kernels/libpt_kernels.so找不到 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq12_0126.png) - -* 原因分析 - - 未导入AICPU - -* 处理方法 - - ```export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest``` - - -### FAQ14、npu-smi info 查看显存时发现有残留 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq13_0126.png) - -* 原因分析 - - 有python进程残留,需要kill - -* 处理方法 - - ```pkill -9 python``` - -### FAQ15、match op inputs failed - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq14_0126.png) - -* 原因分析 - - PTIndexPut编译的算子和输入的shape对不上, 并有acl_dynamic_shape_op打头的日志字样,可以确定是动态shape报错 - -* 处理方法 - PTIndexPut对应 ```tensor[indices] = value``` ,需要在代码中找到对应的地方将动态shape修改为固定shape - - - -### FAQ16、Op type SigmoidCrossEntropyWithLogitsV2 of ops kernel AIcoreEngine is unsupported, - -``` -[ERROR] GE(24836,python3.7):2021-01-27-18:27:51.562.111 [../../../../../../graphengine/ge/engine_manager/dnnengine_manager.cc:266]25155 GetDNNEngineName: ErrorNo: 1343242282(assign engine failed) GetDNNEngineName:Op type SigmoidCrossEntropyWithLogitsV2 of ops kernel AIcoreEngine is unsupported, reason:Op SigmoidCrossEntropyWithLogitsV2 not supported reason: The type of this op is not found in op store, check whether the op store has this type of op. Op store name is tbe-custom. -The dtype, format or shape of input in op desc is not supported in op store, check the dtype, format or shape of input between the op store and the graph. Op store name is tbe-builtin. -``` - -* 原因分析 - - 给SigmoidCrossEntropyWithLogitsV2这个算子了不支持的输入类型 - -* 处理方法 - 检查对应python代码中输入的数据类型,多半是由于输入int64类型导致的错误 - - -### FAQ17、Hook失败 - -```shell -Traceback (most recent call last): - File "tools/train.py", line 227, in - main() - File "tools/train.py", line 221, in main - meta=meta) - File "/root/YoloV3/mmdetection/mmdet/apis/train.py", line 192, in train_detector - runner.run(data_loaders, cfg.workflow, cfg.total_epochs) - File "/usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 166, in run - epoch_runner(data_loaders[i], **kwargs) - File "/usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 50, in train - self.run_iter(data_batch, train_mode=True) - File "/usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 30, in run_iter - outputs = self.model.train_step(data_batch, self.optimizer, **kwargs) - File "/usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/parallel/data_parallel.py", line 100, in train_step - return self.module.train_step(*inputs[0], **kwargs[0]) - File "/root/YoloV3/mmdetection/mmdet/models/detectors/base.py", line 251, in train_step - losses = self(**data) - File "/usr/local/python3.7.5/lib/python3.7/site-packages/torch/nn/modules/module.py", line 660, in __call__ - var = next((v for v in var.values() if isinstance(v, torch.Tensor))) -StopIteration -``` - -* 原因分析 - - mmdet的loss部分结构触发了pytorch原生的一个hook的bug,会导致死循环 - -* 处理方法 - - 解决方案是 /usr/local/python3.7.5/lib/python3.7/site-packages/torch/nn/modules/module.py 在这个文件的658行加try跳过 - ```python - if len(self._backward_hooks) > 0: - var = result - try: - while not isinstance(var, torch.Tensor): - if isinstance(var, dict): - var = next((v for v in var.values() if isinstance(v, torch.Tensor))) - else: - var = var[0] - grad_fn = var.grad_fn - if grad_fn is not None: - for hook in self._backward_hooks.values(): - wrapper = functools.partial(hook, self) - functools.update_wrapper(wrapper, hook) - grad_fn.register_hook(wrapper) - except Exception as e: - print('hook failed..') - print(str(e)) - return result + # [1 介绍](#1-介绍) + + 本文目标读者为Ascend模型迁移开发者,用于指导开发者在昇腾版本的 PyTorch + Apex 下,实现模型训练精度性能达标。这里仅列举模型迁移中遇到的常见问题与解决方法,持续更新。 + + + # [2 常见问题FAQ](#2-常见问题FAQ) + + ## [2.1 NPU模型打通常见问题FAQ](#21-NPU模型打通常见问题FAQ) + + ### FAQ1、在模型运行或者算子运行时遇到报错,“RuntimeError: ExchangeDevice:” + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq_1103.png) + + * 原因分析 + + 目前在一个线程内,只能调用一个npu设备,当切换不同的npu device时,会出现上述错误。 + + * 处理方法 + + 检查代码中在调用torch.npu.set_device(device)、tensor.to(device)或者model.to(device)时,同一个线程内前后调用时device名称不一致。对于多个线程情况(如多卡训练),每个线程也是只能调用固定的npu device。 + + + ### FAQ2、在模型运行或者算子运行时遇到报错,“Error in atexit._run_exitfuncs:” + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq_6_1111.png) + + * 原因分析 + + 在torch初始化时,若未通过torch.npu.device(id)指定npu设备,则默认使用device 0设备。若直接使用其他npu设备,如指定在device 1上创建tensor,那么在运行时会出现上述错误。 + + * 处理方法 + + 在调用npu设备之前,通过torch.npu.set_device(device)指定需要使用的npu 设备即可。 + + ### FAQ3、在模型运行遇到报错,“terminate called after throwing an instance of 'c10::Error' what(): HelpACLExecute:” + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_1103.png) + + * 原因分析 + + 目前HelpACLExecute的报错信息是无法直接找到报错位置的,这里是在task任务下发时报错,由于开启TASK多线程下发(export TASK_QUEUE_ENABLE=1),报错信息被上层封装起来,无法获取更加详细的报错日志。 + + * 处理方法 + + 遇到这种情况处理方式有两种:一是查看host日志,可以查看具体的报错日志信息。日志默认位置是/root/ascend/log/plog/下,可能会有多个日志文件,日志文件以host-0为前缀,根据时间标识查找对应的日志文件。打开日志文件,搜索“ERROR”,查询具体的报错信息。二是关闭多线程下发(export TASK_QUEUE_ENABLE=0),同时开启错误日志级别(export ASCEND_GLOBAL_LOG_LEVEL=3)然后再次运行代码,一般可根据终端报错信息知道错误原因。 + + ### FAQ4、在模型调测遇到报错,“RuntimeError: malloc:/..../pytorch/c10/npu/NPUCachingAllocator.cpp:293 NPU error, error code is 500000.” + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq3_1109.png) + + * 原因分析 + + 对于NPUCachingAllocator中malloc类型的错误,一般是npu显存不足,所需显存小于npu上可用显存,导致报错。 + + * 处理方法 + + 在模型调测中,可用通过减小batch size参数,来减少NPU显存的分配,解决该问题。 + + ### FAQ5、在模型调测遇到报错,RuntimeError: Could not run 'aten::trunc.out' with arguments from the 'NPUTensorId' backend. + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq5_1109.png) + + * 原因分析 + + 目前npu设备仅支持pytorch部分算子,对于不支持的算子在使用时均会报上述错误,算子正在不断开发中。[查看NPU设备已经支持的算子](https://support.huaweicloud.com/opl-pytorch/atlasptol_09_0001.html), 持续更新。 + + * 处理方法 + + 在模型调测中,可用通过减小batch size参数,来减少NPU显存的分配,解决该问题。 + + + ### FAQ6、在模型调测中,遇到某个算子报错的情况,如下分别为MaxPoolGradWithArgmaxV1算子和max算子报错。 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq4_1109.png) + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq4_2_1109.png) + + * 原因分析 + + 在模型搭建中,算子输入参数是多样的。某些算子在特定参数下,计算报错或者不支持,根据报错信息可以定位到具体算子。 + + * 处理方法 + + 根据报错信息定位到具体算子,解决步骤如下: + 1) 排查模型中对该算子的调用方式和参数正确; + 2) 根据报错算子构建单算子用例,构建报错场景; + 3) 一般算子错误无法在python侧解决,构建出报错场景。在论坛中发帖附上报错场景,求助华为工程师即可。 + 注:输入参数shape 和 dtype需要重点关注,一般是导致算子报错的主要原因。 + + + 前述图中,根据报错信息,定位到是MaxPoolGradWithArgmaxV1算子和max算子报错。MaxPoolGradWithArgmaxV1是在反向计算过程中报错,那么构建测试用例时需要构建对应的反向场景; + 而对于max算子,是正向计算时报错,构建正向场景即可。在模型中遇到算子报错,首选是仅构建单算子测试用例,确定报错场景和原因即可;若无法在单算子中构建单算子用例,则需要构建基于上下文的单算子场景, 可以参考[Ascend PyTorch模型迁移指导.md](https://gitee.com/ascend/docs-dev/blob/master/tutorials/Ascend%20PyTorch%E6%A8%A1%E5%9E%8B%E8%BF%81%E7%A7%BB%E6%8C%87%E5%AF%BC.md#44-%E5%8D%95%E7%AE%97%E5%AD%90%E7%94%A8%E4%BE%8B%E7%BC%96%E5%86%99%E8%AF%B4%E6%98%8E) 编写用例。 + + + ### FAQ7、在模型运行遇到报错,ImportError: libhccl.so. + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq6_1118.png) + + * 原因分析 + + 目前对外发布的pytorch安装包,默认是使用NPU和HCCL功能,因此在调用时需要将HCCL模块路径添加到环境变量中。根据报错信息,can not find libhccl.so,缺少hccl库文件。 + + * 处理方法 + + 将hccl模块的路径添加到环境变量中即可,一般hccl库文件路径是安装包下的.../fwkacllib/python/site-packages/hccl。 + + + ### FAQ8、在模型运行将多任务下发关闭(export TASK_QUEUE_ENABLE=0)后仍然遇到报错,HelpACLExecute. + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq7_1118.png) + + * 原因分析 + + 目前pytorch算子在npu上运行,通过ACL接口调用底层经过优化的算子,部分算子发生错误时,报错信息获取异常,在上层报错信息显示为HelpACLExecute. 内部也正在对报错信息与日志逐步完善中。 + + * 处理方法 + + 查看host日志,确定报错算子和位置。日志默认路径为/var/log/npu/slog/host-0,查找对应时间的log文件,搜索ERROR字段,查找错误信息。如对上述的错误,查询日志中的ERROR字段为: + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq7_1_1118.png) + + 从日志信息EEROR部分可以发现,报错算子为topKD,报错原因是 The number of attrs in op desc and op store does not match. 定位到是topk算子错误,具体原因是算子参数不匹配。 在模型代码中查找topk算子调用位置,确定该算子是否可有其他算子代替,若可由其他算子报错,暂时使用代替方案,并将算子报错信息报告华为工程师。若无替代算子,请将算子报错信息通知华为工程师解决。 + + + ### FAQ9、在模型运行遇到报错,RuntimeError: Initialize. + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq8_1118.png) + + + * 原因分析 + + 根据报错信息,是npu设备初始化错误。查看host日志内容,根据前述步骤查找日志。日志报错如下: + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq8_1_1118.png) + + * 处理方法 + + 从日志中定位到是在拉起npu设备时报错。一般可以通过重启服务器解决该问题,所有npu device也会重新启动。若重启服务器后,仍然存在该问题,检查安装的driver和fireware版本是否匹配,更换正确版本的driver和fireware,或者向华为工程师报告求助解决。 + + + ### FAQ10、在模型运行遇到报错,TVM/te/cce error. + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq10_1118.png) + + * 原因分析 + + pytorch内调用npu类型算子时,强依赖于te、cce、tvm组件,pytorch、toolkit/nnae和te版本需要一致。在更新toolkit/nnae后,te等组件不会自动更新,当版本不匹配时,则会出现该报错。 + + * 处理方法 + + 更新te等组件版本,具体是需要更新te-*.whl和topi-*.whl安装包。在安装的toolkit或者nnae的fwkacllib子目录下(对于默认安装路径,在/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64目录下,更新安装包即可。在该目录下有安装包topi-0.4.0-py3-none-any.whl和te-0.4.0-py3-none-any.whl,分别运行 pip install --upgrade topi-0.4.0-py3-none-any.whl, pip install --upgrade te-0.4.0-py3-none-any.whl. + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq10_1_1118.png) + + ### FAQ11、在调用torch时,遇到ModuleNotFoundError: No module named 'torch._C'报错。 + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq11_1123.png) + + * 原因分析 + + 首先确定报错位置,上述报错在.../code/pytorch/torch/__init__.py ,而当前运行路径在.../code/pytorch下,在执行import torch时,默认首先在当前目录下查找torch文件夹,因此会报错。这里应该是调用在系统目录下安装的torch包,而不是当前目录下的torch。 + + * 处理方法 + + 切换到其他目录执行脚本即可。 + + ### FAQ12、cuda流同步操作报错。 + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq11_20210728.jpg) + + * 原因分析 + + npu请使用npu的流同步方法 + + * 处理方法 + + ```python + stream = torch.npu.current_stream() + stream.synchronize() + ``` + + + ### FAQ13、aicpu_kernels/libpt_kernels.so找不到 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq12_0126.png) + + * 原因分析 + + 未导入AICPU + + * 处理方法 + + ```export ASCEND_AICPU_PATH=/usr/local/Ascend/ascend-toolkit/latest``` + + + ### FAQ14、npu-smi info 查看显存时发现有残留 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq13_0126.png) + + * 原因分析 + + 有python进程残留,需要kill + + * 处理方法 + + ```pkill -9 python``` + + + ### FAQ15、match op inputs failed + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq14_0126.png) + + * 原因分析 + + PTIndexPut编译的算子和输入的shape对不上, 并有acl_dynamic_shape_op打头的日志字样,可以确定是动态shape报错 + + * 处理方法 + PTIndexPut对应 ```tensor[indices] = value``` ,需要在代码中找到对应的地方将动态shape修改为固定shape + + + + ### FAQ16、Op type SigmoidCrossEntropyWithLogitsV2 of ops kernel AIcoreEngine is unsupported, + ``` - - -### FAQ18、模型报错运行时MemCopySync:drvMemcpy failed. - -```shell - 脚本: - import torch - - def test_sum(): - xs_shape = [22400, 8] - ys_shape = [22400, 8] - gt_bboxes_shape = [22400, 8,4] - xs = torch.rand(xs_shape).npu() - ys = torch.rand(ys_shape).npu() - gt_bboxes = torch.rand(gt_bboxes_shape).npu().half() - left = xs - gt_bboxes[..., 0] - right = gt_bboxes[..., 2] - xs - top = ys - gt_bboxes[..., 1] - bottom = gt_bboxes[..., 3] - ys - # stream = torch.npu.current_stream() - # stream.synchronize() - # left, top 结果是fp32, right, bottom 结果是fp16, - # print(left.dtype, top.dtype, right.dtype, bottom.dtype) - bbox_targets = torch.stack((left, top, right, bottom), -1) #报错位置在这里 - # stream.synchronize() - - bbox_targets = torch.sum(bbox_targets) - shell报错信息: - RuntimeError: Run:/usr1/workspace/PyTorch_Apex_Daily_c20tr5/CODE/aten/src/ATen/native/npu/utils/OpParamMaker.h:280 NPU error,NPU error code is:500002 - [ERROR] RUNTIME(160809)kernel task happen error, retCode=0x28, [aicpu timeout]. - [ERROR] RUNTIME(160809)aicpu kernel execute failed, device_id=0, stream_id=512, task_id=24, fault so_name=, fault kernel_name=, extend_info=. - Error in atexit._run_exitfuncs: + [ERROR] GE(24836,python3.7):2021-01-27-18:27:51.562.111 [../../../../../../graphengine/ge/engine_manager/dnnengine_manager.cc:266]25155 GetDNNEngineName: ErrorNo: 1343242282(assign engine failed) GetDNNEngineName:Op type SigmoidCrossEntropyWithLogitsV2 of ops kernel AIcoreEngine is unsupported, reason:Op SigmoidCrossEntropyWithLogitsV2 not supported reason: The type of this op is not found in op store, check whether the op store has this type of op. Op store name is tbe-custom. + The dtype, format or shape of input in op desc is not supported in op store, check the dtype, format or shape of input between the op store and the graph. Op store name is tbe-builtin. + ``` + + * 原因分析 + + 给SigmoidCrossEntropyWithLogitsV2这个算子了不支持的输入类型 + + * 处理方法 + 检查对应python代码中输入的数据类型,多半是由于输入int64类型导致的错误 + + + ### FAQ17、Hook失败 + + ```shell Traceback (most recent call last): - File "/usr/local/python3.7.5/lib/python3.7/site-packages/torch/__init__.py", line 429, in _npu_shutdown - torch._C._npu_shutdown() - RuntimeError: npuSynchronizeDevice:/usr1/workspace/PyTorch_Apex_Daily_c20tr5/CODE/c10/npu/NPUStream.cpp:806 NPU error, error code is 0 - - 日志信息: - [ERROR] RUNTIME(12731,python3.7):2021-02-02-22:23:56.475.679 [../../../../../../runtime/feature/src/npu_driver.cc:1408]12828 MemCopySync:drvMemcpy failed: dst=0x108040288000, destMax=1240, src=0x7fe7649556d0, size=1240, kind=1, drvRetCode=17! - [ERROR] RUNTIME(12731,python3.7):2021-02-02-22:23:56.475.698 [../../../../../../runtime/feature/src/logger.cc:113]12828 KernelLaunch:launch kernel failed, kernel=140631803535760/ArgMinWithValue_tvmbin, dim=32, stream=0x55b22b3def50 - [ERROR] RUNTIME(12731,python3.7):2021-02-02-22:23:56.475.717 [../../../../../../runtime/feature/src/api_c.cc:224]12828 rtKernelLaunch:ErrCode=207001, desc=[module new memory error], InnerCode=0x70a0002 -``` - -* 原因分析 - - 根据shell和日志报错信息,两者报错信息不匹配,甚至是矛盾的。shell报错是在同步操作中和ai cpu错误,而日志却是在min算子(内部调用ArgMinWithValue_tvmbin),之间的报错信息完全不对应。实际上出现这种问题,日志内的报错信息会比较滞后,不具有参考价值。经过分析,该类错误一般都是由AI cpu算子引起的,因算子执行可能是异步的,报错信息可能滞后,即使关闭多任务算子下发也是一样的结果。所以实际上的错误位置是在shell脚本报错位置和日志报错算子之前就已经出现错误了。这时在根据报错加上stream同步操作,不断缩小错误范围,定位错误算子。stream同步操作可以保证代码运行到当前位置时,前面所有的计算一定是完成的,这样就可以确定范围。 - -* 处理方法 - -通过在代码中加上stream同步操作,可以确定报错算子是在stack,那么打印stack所有参数的shape、dtype、npu_format,然后构造单算子用例就能很好的复现和解决问题。所以这里的问题是,减法计算输入参数数据类型不同导致a-b和b-a结果的数据类型也不一致,最终在stack算子中报错。可以将stack入参数据类型转换为一致即可临时规避问题。对于该报错需要根据实际的错误来定位。 - -### FAQ19、加载权重时发生load state_dict error. - -* 现象描述 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq18_01.png) -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq18_02.png) - -* 原因分析 - - 模型训练后保存的state_dict的key值与加载时state_dict的key值不一致,保存时会在每个key的最前面多一个module前缀。 - -* 处理方法 - - 加载权重时先遍历state_dict字典,修改key值,并使用新建的字典,具体用例参考demo.py。 - ```shell - 脚本: - ckpt = torch.load("checkpoint.pth", map_location=loc) - # model.load_state_dict(ckpt['state_dict']) - state_dict_old = ckpt['state_dict'] - state_dict = {} - for key, value in state_dict_old.items(): - key = key[7:] - state_dict[key] = value - model.load_state_dict(state_dict) - ``` - -### FAQ20、加载数据集时发生cannot identify image. - -* 现象描述 -![](https://gitee.com/zhangjie11ee/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq19_0527.png) - - -* 原因分析 - - 模型训练时无法找到对应的数据集出现错误。 - -* 处理方法 - - 找不到数据集,检查数据集路径和数据集是否有效。 - -### FAQ21、timm框架版本问题导致错误 - -* 现象描述 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq20_0607.png) - 模型出差copy_npu的错误,使用的是timm框架结构。 - - -* 原因分析 - - 使用的timm框架有问题,需要定位分析 - -* 处理方法 - - 进行timme框架替换,环境上timm安装的是4.9版本,需要替换为是4.6版本的。 - -### FAQ22、GPU场景下安装DCN2v模块 - -* 现象描述 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq21_0607.png) - 导入DCNv2失败,出现未定义符合错误。 - - -* 原因分析 - - 该模块是模型自带的,导致导入失败,需要自己进行编译安装DCNv2模块 - -* 处理方法 - - 下载https://github.com/CharlesShang/DCNv2的源码,进行编译安装, - 可以参考https://www.gitmemory.com/issue/xingyizhou/CenterNet/7/486653333进行安装。 - - - - - -### FAQ23、模型训练时报libtorch_npu.so: undefined symbol: aclopSetCompileFlag错误。 - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq20_0528.png) - -* 原因分析 - - 环境中的pytorch版本与toolkit版本不匹配,或存在多个tookit版本,环境变量未正确指定。 - -* 处理方法 - - 1)重新安装版本匹配的torch或者toolkit。 - 2)重新设置环境变量,指定正确的toolkit路径。 - - -### FAQ24、模型训练时报fill算子错误 - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq21_0529.PNG) - -* 原因分析 - - 脚本中fill算子输入的类型是int64, 查看vim /usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe/config/ascend910/aic-ascend910-ops-info.json中Fills算子支持的输入类型是float16,float32,int32 - -* 处理方法 - - 1)将fill算子输入的类型改成int32。 - - -### FAQ25、cpu下运行scatter算子报错:RuntimeError: index 4558486308284583594 is out of bounds for dimension 1 with size 4233. - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq22_0604.PNG) - -* 原因分析 - - scatter算子中的index参数仅支持long类型 - index (LongTensor) – the indices of elements to scatter, can be either empty or the same size of src. When empty, the operation returns identity - -* 处理方法 - - 修改代码中b的类型为long。 - - -### FAQ26、NPU训练时,第一个batch训练速度特别慢,第二个开始速度正常,和gpu差不多。 - -* 现象描述 - -无 - -* 原因分析 - - NPU是在线编译算子的,在执行第一步的时候会去编译算子,所以第一步会特别慢。 - -* 处理方法 - - 正常现象。 - - -### FAQ26、pip安装包 matplotlib pillow numpy scipy xtcocotools torchvision 等包,在x86环境安装顺利但是在arm环境失败 - -* 现象描述 + File "tools/train.py", line 227, in + main() + File "tools/train.py", line 221, in main + meta=meta) + File "/root/YoloV3/mmdetection/mmdet/apis/train.py", line 192, in train_detector + runner.run(data_loaders, cfg.workflow, cfg.total_epochs) + File "/usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 166, in run + epoch_runner(data_loaders[i], **kwargs) + File "/usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 50, in train + self.run_iter(data_batch, train_mode=True) + File "/usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 30, in run_iter + outputs = self.model.train_step(data_batch, self.optimizer, **kwargs) + File "/usr/local/python3.7.5/lib/python3.7/site-packages/mmcv/parallel/data_parallel.py", line 100, in train_step + return self.module.train_step(*inputs[0], **kwargs[0]) + File "/root/YoloV3/mmdetection/mmdet/models/detectors/base.py", line 251, in train_step + losses = self(**data) + File "/usr/local/python3.7.5/lib/python3.7/site-packages/torch/nn/modules/module.py", line 660, in __call__ + var = next((v for v in var.values() if isinstance(v, torch.Tensor))) + StopIteration + ``` + + * 原因分析 + + mmdet的loss部分结构触发了pytorch原生的一个hook的bug,会导致死循环 + + * 处理方法 + + 解决方案是 /usr/local/python3.7.5/lib/python3.7/site-packages/torch/nn/modules/module.py 在这个文件的658行加try跳过 + ```python + if len(self._backward_hooks) > 0: + var = result + try: + while not isinstance(var, torch.Tensor): + if isinstance(var, dict): + var = next((v for v in var.values() if isinstance(v, torch.Tensor))) + else: + var = var[0] + grad_fn = var.grad_fn + if grad_fn is not None: + for hook in self._backward_hooks.values(): + wrapper = functools.partial(hook, self) + functools.update_wrapper(wrapper, hook) + grad_fn.register_hook(wrapper) + except Exception as e: + print('hook failed..') + print(str(e)) + return result + ``` + + + ### FAQ18、模型报错运行时MemCopySync:drvMemcpy failed. + + ```shell + 脚本: + import torch + + def test_sum(): + xs_shape = [22400, 8] + ys_shape = [22400, 8] + gt_bboxes_shape = [22400, 8,4] + xs = torch.rand(xs_shape).npu() + ys = torch.rand(ys_shape).npu() + gt_bboxes = torch.rand(gt_bboxes_shape).npu().half() + left = xs - gt_bboxes[..., 0] + right = gt_bboxes[..., 2] - xs + top = ys - gt_bboxes[..., 1] + bottom = gt_bboxes[..., 3] - ys + # stream = torch.npu.current_stream() + # stream.synchronize() + # left, top 结果是fp32, right, bottom 结果是fp16, + # print(left.dtype, top.dtype, right.dtype, bottom.dtype) + bbox_targets = torch.stack((left, top, right, bottom), -1) #报错位置在这里 + # stream.synchronize() + + bbox_targets = torch.sum(bbox_targets) + shell报错信息: + RuntimeError: Run:/usr1/workspace/PyTorch_Apex_Daily_c20tr5/CODE/aten/src/ATen/native/npu/utils/OpParamMaker.h:280 NPU error,NPU error code is:500002 + [ERROR] RUNTIME(160809)kernel task happen error, retCode=0x28, [aicpu timeout]. + [ERROR] RUNTIME(160809)aicpu kernel execute failed, device_id=0, stream_id=512, task_id=24, fault so_name=, fault kernel_name=, extend_info=. + Error in atexit._run_exitfuncs: + Traceback (most recent call last): + File "/usr/local/python3.7.5/lib/python3.7/site-packages/torch/__init__.py", line 429, in _npu_shutdown + torch._C._npu_shutdown() + RuntimeError: npuSynchronizeDevice:/usr1/workspace/PyTorch_Apex_Daily_c20tr5/CODE/c10/npu/NPUStream.cpp:806 NPU error, error code is 0 + + 日志信息: + [ERROR] RUNTIME(12731,python3.7):2021-02-02-22:23:56.475.679 [../../../../../../runtime/feature/src/npu_driver.cc:1408]12828 MemCopySync:drvMemcpy failed: dst=0x108040288000, destMax=1240, src=0x7fe7649556d0, size=1240, kind=1, drvRetCode=17! + [ERROR] RUNTIME(12731,python3.7):2021-02-02-22:23:56.475.698 [../../../../../../runtime/feature/src/logger.cc:113]12828 KernelLaunch:launch kernel failed, kernel=140631803535760/ArgMinWithValue_tvmbin, dim=32, stream=0x55b22b3def50 + [ERROR] RUNTIME(12731,python3.7):2021-02-02-22:23:56.475.717 [../../../../../../runtime/feature/src/api_c.cc:224]12828 rtKernelLaunch:ErrCode=207001, desc=[module new memory error], InnerCode=0x70a0002 + ``` + + * 原因分析 + + 根据shell和日志报错信息,两者报错信息不匹配,甚至是矛盾的。shell报错是在同步操作中和ai cpu错误,而日志却是在min算子(内部调用ArgMinWithValue_tvmbin),之间的报错信息完全不对应。实际上出现这种问题,日志内的报错信息会比较滞后,不具有参考价值。经过分析,该类错误一般都是由AI cpu算子引起的,因算子执行可能是异步的,报错信息可能滞后,即使关闭多任务算子下发也是一样的结果。所以实际上的错误位置是在shell脚本报错位置和日志报错算子之前就已经出现错误了。这时在根据报错加上stream同步操作,不断缩小错误范围,定位错误算子。stream同步操作可以保证代码运行到当前位置时,前面所有的计算一定是完成的,这样就可以确定范围。 + + * 处理方法 + + 通过在代码中加上stream同步操作,可以确定报错算子是在stack,那么打印stack所有参数的shape、dtype、npu_format,然后构造单算子用例就能很好的复现和解决问题。所以这里的问题是,减法计算输入参数数据类型不同导致a-b和b-a结果的数据类型也不一致,最终在stack算子中报错。可以将stack入参数据类型转换为一致即可临时规避问题。对于该报错需要根据实际的错误来定位。 + + ### FAQ19、加载权重时发生load state_dict error. + + * 现象描述 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq18_01.png) + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq18_02.png) + + * 原因分析 + + 模型训练后保存的state_dict的key值与加载时state_dict的key值不一致,保存时会在每个key的最前面多一个module前缀。 + + * 处理方法 + + 加载权重时先遍历state_dict字典,修改key值,并使用新建的字典,具体用例参考demo.py。 + ```shell + 脚本: + ckpt = torch.load("checkpoint.pth", map_location=loc) + # model.load_state_dict(ckpt['state_dict']) + state_dict_old = ckpt['state_dict'] + state_dict = {} + for key, value in state_dict_old.items(): + key = key[7:] + state_dict[key] = value + model.load_state_dict(state_dict) + ``` + + ### FAQ20、加载数据集时发生cannot identify image. + + * 现象描述 + ![](https://gitee.com/zhangjie11ee/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq19_0527.png) + + * 原因分析 + + 模型训练时无法找到对应的数据集出现错误。 + + * 处理方法 + + 找不到数据集,检查数据集路径和数据集是否有效。 + + ### FAQ21、timm框架版本问题导致错误 + + * 现象描述 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq20_0607.png) + 模型出差copy_npu的错误,使用的是timm框架结构。 + + * 原因分析 + + 使用的timm框架有问题,需要定位分析 + + * 处理方法 + + 进行timme框架替换,环境上timm安装的是4.9版本,需要替换为是4.6版本的。 + + ### FAQ22、GPU场景下安装DCN2v模块 + + * 现象描述 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq21_0607.png) + 导入DCNv2失败,出现未定义符合错误。 + + + * 原因分析 + + 该模块是模型自带的,导致导入失败,需要自己进行编译安装DCNv2模块 + + * 处理方法 + + 下载https://github.com/CharlesShang/DCNv2的源码,进行编译安装, + 可以参考https://www.gitmemory.com/issue/xingyizhou/CenterNet/7/486653333进行安装。 + + + + + + ### FAQ23、模型训练时报libtorch_npu.so: undefined symbol: aclopSetCompileFlag错误。 + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq20_0528.png) + + * 原因分析 + + 环境中的pytorch版本与toolkit版本不匹配,或存在多个tookit版本,环境变量未正确指定。 + + * 处理方法 + + 1)重新安装版本匹配的torch或者toolkit。 + 2)重新设置环境变量,指定正确的toolkit路径。 + + + ### FAQ24、模型训练时报fill算子错误 + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq21_0529.PNG) + + * 原因分析 + + 脚本中fill算子输入的类型是int64, 查看vim /usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe/config/ascend910/aic-ascend910-ops-info.json中Fills算子支持的输入类型是float16,float32,int32 + + * 处理方法 + + 1)将fill算子输入的类型改成int32。 + + + ### FAQ25、cpu下运行scatter算子报错:RuntimeError: index 4558486308284583594 is out of bounds for dimension 1 with size 4233. + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq22_0604.PNG) + + * 原因分析 + + scatter算子中的index参数仅支持long类型 + index (LongTensor) – the indices of elements to scatter, can be either empty or the same size of src. When empty, the operation returns identity + + * 处理方法 + + 修改代码中b的类型为long。 + + + ### FAQ26、NPU训练时,第一个batch训练速度特别慢,第二个开始速度正常,和gpu差不多。 + + * 现象描述 + + 无 + + * 原因分析 + + NPU是在线编译算子的,在执行第一步的时候会去编译算子,所以第一步会特别慢。 + + * 处理方法 + + 正常现象。 + + + ### FAQ26、pip安装包 matplotlib pillow numpy scipy xtcocotools torchvision 等包,在x86环境安装顺利但是在arm环境失败 + + * 现象描述 + + arm环境上安装很多包的时候会报错,报错的内容,现象各不相同,找不到包或者缺少底层依赖。 + + * 原因分析 + + 1. pip根据你当前的pip版本下载的,不同版本对应的包再pip源的中是相互隔离的,所以即使有些包已经出了arm版本,但是你的pip不够新下载也会出错,或者找不到。 + 2. 有些包在你选定的源里的确没有,尝试使用其他的pip源 + 3. arm上的环境上的python生态并不好,有些包即使是最新的pip版本依然下载不到。那只能编译源码了。 + + * 处理方法 + + 1)尝试更新pip,注意你若是使用的pip3.7则下面命令对应改成pip3.7 + ```bash + pip install --upgrade pip + ``` + + 2)临时切换pip源下载,使用 -i 参数指定临时源,常用的源还有 清华源,阿里源,豆瓣源 + ```bash + pip install torchvision==0.2.2 -i https://repo.huaweicloud.com/repository/pypi/simple/ + ``` + 其他源: + ```bash + 清华大学 :https://pypi.tuna.tsinghua.edu.cn/simple/ + 阿里云:http://mirrors.aliyun.com/pypi/simple/ + 豆瓣源:http://pypi.douban.com/simple/ + ``` + + 3)对于前两种办法都无法安装的包,那只能使用源码安装了,目前像 kaldi,xtcocotools 这类包需要使用gitee或者github上共享的源码,根据他的readme来编译安装。 + + ### FAQ27、模型训练时出现argmax算子计算问题。 + + * 现象描述 + + ![](https://gitee.com/zhangjie11ee/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq27_0618.png) + + * 原因分析 + + 1.因为传进去的输入的NCHW会发生变化,需要提前固定,不然会出现形状问题 + + * 处理方法 + + 1)需要对输入进行处理,参考如下: + output.data = output.data.npu_format_cast(0) + predict = torch.argmax(output, 1).to(torch.int32) + 1 + + ### FAQ28、模型推理时加载pth出现问题。 + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq28_0618.png) + + * 原因分析 + + 1.pth在npu上时加载会出现加载失败的现象 + + * 处理方法 + + 1)需要添加:pretrained_net = torch.load(cfg["test"]["ckpt_path"], map_location='cpu') + + ### FAQ29、多个环境都遇到了安装升级5.0.1的toolkit包,安装时报错的问题。 + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_2901.png) + + * 原因分析 - arm环境上安装很多包的时候会报错,报错的内容,现象各不相同,找不到包或者缺少底层依赖。 - -* 原因分析 + 通过分析发现是环境中/usr/bin/pip3目录不存在,或者没有软链到/usr/bin/pip3.7 - 1. pip根据你当前的pip版本下载的,不同版本对应的包再pip源的中是相互隔离的,所以即使有些包已经出了arm版本,但是你的pip不够新下载也会出错,或者找不到。 - 2. 有些包在你选定的源里的确没有,尝试使用其他的pip源 - 3. arm上的环境上的python生态并不好,有些包即使是最新的pip版本依然下载不到。那只能编译源码了。 + * 处理方法 + + 如果环境中/usr/bin/pip3目录已经存在,但没有软链到/usr/bin/pip3.7,那就删除/usr/bin/pip3目录,然后做软链;如果/usr/bin/pip3目录不存在,直接做软链接。软链接命令如下:ln -s /usr/bin/pip3.7 /usr/bin/pip3 + + ### FAQ30、某个算子不支持,GE层报错,如何排查 + * 现象描述 + 问题显示如下 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3001.png) + * 原因分析 + 提示的 NLLossGrad 算子不支持 + * 处理办法 + + 在 /usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe/config/ascend910 你去这个目录下的aic-ascend910-ops-info.json文件搜下这个NLLossGrad + 查看的结果如上发现类型不匹配导致 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3002.png) + + ### FAQ31 dict加载的时候提示key缺少 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3101.png) + 因为ddp保存的权重会在key的前面加上moudule.所以需要简单处理下对齐下key, + 模型训练后保存的state_dict的key值与加载时state_dict的key值不一致,保存时会在每个key的最前面多一个module前缀。 + load进来都是dict,可以print看看 + 这里是提示的key缺失所以要加上 + pth.tar后缀的 + ```python + def proc_node_module(checkpoint, AttrName): + new_state_dict = OrderedDict() + for k, v in checkpoint[AttrName].items(): + if k[0:7] == "module.": + name = k[7:] + else: + name = k[0:] + new_state_dict[name] = v + return new_state_dict + checkpoint = torch.load("checkpoint.pth.tar", map_location='cpu') + checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') + model.load_state_dict(checkpoint['state_dict']) + ``` + pth后缀的 + ```python + def proc_nodes_module(checkpoint): + new_state_dict = OrderedDict() + for k,v in checkpoint.items(): + if(k[0:7] == "module."): + name = k[7:] + else: + name = k[0:] + new_state_dict[name]=v + return new_state_dict + pretrained_net = torch.load(pth_file, map_location='cpu') + pretrained_net['state_dict'] = proc_nodes_module(pretrained_net) + model.load_state_dict(pretrained_net['state_dict']) + ``` + + ### FAQ32 pip3报错 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3201.png) + + 原因 没有pip3这个快捷方式 + + 1.检查 + + 首先确定环境中是有python3.7.5的 + + 确定自己的 pip3.7 存在的软连接位置 -* 处理方法 - - 1)尝试更新pip,注意你若是使用的pip3.7则下面命令对应改成pip3.7 ```bash - pip install --upgrade pip + which pip3.7 #返回值应该是 /usr/bin/pip3.7 ``` - 2)临时切换pip源下载,使用 -i 参数指定临时源,常用的源还有 清华源,阿里源,豆瓣源 + 2.创建软连接 + ```bash - pip install torchvision==0.2.2 -i https://repo.huaweicloud.com/repository/pypi/simple/ + ln -s /usr/bin/pip3.7 /usr/bin/pip3 ``` - 其他源: + + ### FAQ33 toolkit包安装报错 ```bash - 清华大学 :https://pypi.tuna.tsinghua.edu.cn/simple/ - 阿里云:http://mirrors.aliyun.com/pypi/simple/ - 豆瓣源:http://pypi.douban.com/simple/ + The user and group are not same with last installation,do not support overwriting installation ``` - 3)对于前两种办法都无法安装的包,那只能使用源码安装了,目前像 kaldi,xtcocotools 这类包需要使用gitee或者github上共享的源码,根据他的readme来编译安装。 - -### FAQ27、模型训练时出现argmax算子计算问题。 - -* 现象描述 - -![](https://gitee.com/zhangjie11ee/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq27_0618.png) - -* 原因分析 - - 1.因为传进去的输入的NCHW会发生变化,需要提前固定,不然会出现形状问题 - -* 处理方法 - - 1)需要对输入进行处理,参考如下: - output.data = output.data.npu_format_cast(0) - predict = torch.argmax(output, 1).to(torch.int32) + 1 - -### FAQ28、模型推理时加载pth出现问题。 - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq28_0618.png) - -* 原因分析 - - 1.pth在npu上时加载会出现加载失败的现象 - -* 处理方法 - - 1)需要添加:pretrained_net = torch.load(cfg["test"]["ckpt_path"], map_location='cpu') + 原因 -### FAQ29、多个环境都遇到了安装升级5.0.1的toolkit包,安装时报错的问题。 - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_2901.png) - -* 原因分析 - - 通过分析发现是环境中/usr/bin/pip3目录不存在,或者没有软链到/usr/bin/pip3.7 - -* 处理方法 - - 如果环境中/usr/bin/pip3目录已经存在,但没有软链到/usr/bin/pip3.7,那就删除/usr/bin/pip3目录,然后做软链;如果/usr/bin/pip3目录不存在,直接做软链接。软链接命令如下:ln -s /usr/bin/pip3.7 /usr/bin/pip3 + 当前指定的驱动运行用户与“/etc/ascend_install.info”文件中记录的运行用户不一致,导致校验失败,安装退出。原因是之前卸载驱动和CANN软件时,aicpu没有被卸载,导致“/etc/ascend_install.info”文件未清空。 + + 先卸载aicpu,再安装驱动。卸载aicpu操作如下: + + 1. 以root用户登录安装环境。 + + 2. 进入卸载脚本所在目录。 + + cd /usr/local/Ascend/opp/aicpu/script + + 3. 执行**./uninstall.sh**命令运行脚本,完成卸载。 + + ### FAQ34 driver安装crl报错 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3401.png) + 原因目录 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3402.png) + 原因老版本的安装信息 /ascend/ascend_check 存在,driver安装前校验无法通过 + + 解决办法,删除这个文件 + ### FAQ35 onnx安装问题, protobuf-compiler缺失 + + arm 安装 onnx 步骤 x86的直接安装就行 + + pip安装 + 更新一下pip 或者 pip3.7 安装 + arm在21版本的pip中可以下载并执行编译安装,但是可能提示编译缺少包 + 获取源码安装 + git clone https://github.com/onnx/onnx.git + cd ./onnx + python3.7 setup.py build + python3.7 setup.py install + 但是可能会有问题 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3501.png) + + 问题处理 : 缺失编译条件 + protobuf-compiler缺失 + + ubutu: + sudo apt-get install libprotobuf-dev protobuf-compiler + cent: + yum install libprotobuf-dev protobuf-compiler + 再次尝试安装试试,还是失败,就下一步 + + 安装protobuf + wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz + tar xvf protobuf-2.6.1.tar.gz + cd protobuf-2.6.1 + ./configure + make -j 4 + make check + make install + 再次尝试安装下试试,否则继续下一步 + + 安装 protoc + wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.2.1/protobuf-c-1.2.1.tar.gz + tar xvf protobuf-c-1.2.1.tar.gz + cd protobuf-c-1.2.1 + export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig // 指定protobuf.pc文件所在 + ./configure + make -j 4 + make install + + 还是失败的话,建议看下 环境基础依赖是否安装, + 最后实在不行就放弃吧,换个操作系统。 + + ### FAQ36 conda拷贝环境后发现pip使用不了报错如下: + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3601.png) + ##### **问题原因:** + + conda现存的conda存在的bug,当你clone的环境是中的pip版本过高(21.0.1的版本就不行),那么继承的子环境会存在问题。 + + ##### **解决办法** + + 方法1 单独使用如下命令创建环境,然后apex包和torch包根据实际环境安装 + + conda create -n wangyuanming python=3.7.5 + + 方法2 确定你拷贝的基础环境pip版本正确 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3602.png) + + ### FAQ37 执行pip安装的时候缺少so的包 + + 不一定是 openblas的包,也有可能是其他的包报错也是一样的 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3702.png) + **原因及解决办法** + + 因为基础的依赖包没有安装 + + 下面两种不同的环境需要安装的依赖有说不同 + + 看下面的 FAQ38 + + ### FAQ38 环境安装前需要基础依赖安装 + 环境安装前需要基础依赖安装 + ● CentOS/EulerOS/Tlinux/BClinux/Suse + + 一般依赖需求 + + yum install -y libjpeg python-devel zlib-devel libjpeg-turbo-devel protobuf-compiler + + 依赖+工具集 + + yum install -y gcc gcc-c++ make cmake unzip zlib-devel libffi-devel openssl-devel pciutils net-tools sqlite-devel lapack-devel openblas-devel gcc-gfortran dos2unix + + ● Ubuntu/Debian/UOS + + 一般依赖需求 + + apt-get install -y libjpeg python-devel zlib-devel libjpeg-turbo-devel + + 依赖+工具集 -### FAQ30、某个算子不支持,GE层报错,如何排查 + apt-get install -y gcc g++ make cmake zlib1g zlib1g-dev openssl libsqlite3-dev libssl-dev libffi-dev unzip pciutils net-tools libblas-dev gfortran libblas3 libopenblas-dev libncursesw5-dev dos2unix + + ### FAQ39 conda使用,外部的python环境指定的不是自己安装的版本 + + **问题现象** + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3901.png) + 检查pip出处 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3902.png) + Python版本不对,执行位置也不对 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3903.png) + 原因和解决办法 + 安装完的环境初始化操作被修改了,一般conda正常激活的时候前面应该有括号表示当前的conda环境 + 所以这里想用外面的环境直接conda deactivate 为了一直有效直接添加到环境变量中。 + + + ### FAQ40、Alexnet dropout 精度不达标规避方法。 * 现象描述 - 问题显示如下 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3001.png) - * 原因分析 - 提示的 NLLossGrad 算子不支持 - * 处理办法 + Alexnet dropout npu精度不达标 + * 处理方法 + + 我们采用规避dropout的方法,然后使模型精度达标。 + 源代码如下 + ``` + self.classifier = nn.Sequential( + nn.Dropout(), + nn.Linear(256 * 6 * 6, 4096), + nn.ReLU(inplace=True), + nn.Dropout(), + nn.Linear(4096, 4096), + nn.ReLU(inplace=True), + nn.Linear(4096, num_classes), + ) + ``` + 修改为如下: + ``` + class Dropout(nn.Module): + def __init__(self, p=0.5, inplace=False): + super(Dropout, self).__init__() + self.p = p + self.inplace = inplace + + def forward(self, x): + x = F.dropout(x.float().cpu(), self.p, self.training, self.inplace).npu().half() + return x + ....... + + self.avgpool = nn.AdaptiveAvgPool2d((6, 6)) + self.classifier = nn.Sequential( + Dropout(), + nn.Linear(256 * 6 * 6, 4096), + nn.ReLU(inplace=True), + Dropout(), + nn.Linear(4096, 4096), + nn.ReLU(inplace=True), + nn.Linear(4096, num_classes), + ) + ``` + + ### FAQ41、mmdet在做hook定位时反向过程报错 + - 现象描述 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq41_0625_fig1.PNG) + + - 原因分析 + + 这个是torch的原始BUG,如果是空dict就会死循环;因为mmdet自己会包装dict,所以这里一定要读到tensor,才会正常执行 + - 处理方法 + 代码参考路径为:/usr/local/python3.7.5/lib/python3.7/site-packages/torch/nn/modules/module.py + 适配代码参考如下: + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq41_0625_fig2.PNG) + + + ### FAQ42、如何确定模型中是否有动态算子 + - 现象描述 + 模型训练过程性能越来越低 + + - 原因分析 + 可能存在动态算子 + + - 处理方法 + 通过这个命令可以看到算子是否一直在增长,如果一直在增长说明存在动态shape, 需要固定shape + ``` + watch -n 1 "ls -ltr kernel_meta/ | wc -l" + ``` + + ### FAQ43、模型训练过程报ACL stream的错误 + - 现象描述 + 没有提示算子报错,只是提示ACL stream的错误 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq43_0714.PNG) + + - 原因分析 + 由于Pytorch是异步执行框架,直接print可能无法准确定位到错误的地方,需使用流通步接口辅助打点 + + - 处理方法 + print之前添加如下代码,一步步定位,如果point可以正常打印,说明前一行代码没问题;如果不能正常打印,则上一行应该是错误的地方,需要排查分析 + ``` + stream = torch.npu.current_stream() + print(stream.synchronize(),"point") + ``` + + ### FAQ44、模型刚开始训练没有报错或日志信息,等待时间久 + - 现象描述 + 模型刚开始训练时没有报错信息或日志信息,等待时间很久都没反应,不确定训练是否在正常运行 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq44_0714.PNG) + + - 原因分析 + 刚开始训练过程,需要编译算子,这一步时间稍长 + + - 处理方法 + (1)可通过top指令查看是否有cpu使用率,如果有使用率,说明正在编译算子 + (2)通过ps -ef|grep python指令查看模型进程是否还在,还在的话说明程序正常运行中 + 每个模型编译算子耗时时间都不一样,一般耗时会在几分钟内。 + + ### FAQ45、模型训练过程DCNv2算子+混合精度报错:excepted scalar type float but found half + - 现象描述 + 模型训练过程使用到DCNv2算子,混合精度配置为O2模式,训练过程报错 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq45_fig1_0719.PNG) + + - 原因分析 + DCNv2算子不支持混合精度O2模式 + + - 处理方法 + 修改混合精度为O1模式,同时修改dcn_v2.py文件中DCNv2算子的前向传播和反向传播的入参类型为fp32。 + DCNv2安装版本以该链接为例:https://github.com/jinfagang/DCNv2_latest + 对比源码,适配后的dcn_v2.py文件对比差异如下: + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq45_fig2_0719.PNG) + + ### FAQ46、模型训练过程中算子PadV3D报错:constant_values value mismatches + - 现象描述 + 模型训练反向过程中算子PadV3D报错 + ![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq46_fig1_0803.png) + + - 原因分析 + 找到源码报错位置,发现使用场景是先用F.pad()做same padding, 然后进行卷积计算 + + - 处理方法 + 手算pad参数,去掉F.pad()这一运算,将这个运算加到卷积里面,两者是等价的 + + ![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq46_fig2_0803.png) + + ### FAQ47、模型训练过程中报错:Expected isFloatingType(grad[i].scalar_type())to be true but got false + - 现象描述 + 屏幕报错信息如下所示: + ![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq47_fig1_0812.jpg) + 从中可以看到是反向报错,并且是aicpu算子报错,然后查看host侧日志,显示如下: + ![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq47_fig2_0812.png) + + - 原因分析 + 根据host侧日志信息可以看到是aicpu算子GatherElements报错,然后源码查找反向调用gather算子的位置,查看pytorch源码derivatives.yaml发现只有scatter_和scatter_add_算子反向会调用gather算子,排查模型源码forward没有调用scatter_和scatter_add_这两个算子,但是forward有调用gather,所以问题可能出现在模型正向gather算子报错。 + - 处理方法 + 将模型中调用gather的算子全部to cpu计算,host侧日志问题复现如下: + ![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq47_fig3_0812.png) + + 然后利用模型中的数据构造gather单算子,问题复现,结论是gather算子的输入输非法的,然后npu的gather正常计算,进而在反向报错 + + ### FAQ48、h5py安装方法 + ``` + ####################################### + 安装h5py + ####################################### + 下载hdf5源码包 + wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.5/src/hdf5-1.10.5.tar.gz --no-check-certificate + 解压 + tar -zxvf hdf5-1.10.5.tar.gz + 进入目录,编译 + cd hdf5-1.10.5/ + ./configure --prefix=/usr/include/hdf5 + make install + + 配置环境变量 + export CPATH="/usr/include/hdf5/include/:/usr/include/hdf5/lib/" + + 建立动态链接库软链接 + ln -s /usr/include/hdf5/lib/libhdf5.so /usr/lib/libhdf5.so + ln -s /usr/include/hdf5/lib/libhdf5_hl.so /usr/lib/libhdf5_hl.so + + 安装h5py依赖包 + pip3.7 install pkgconfig Cython + 安装h5py + pip3.7 install h5py + + ``` + + + + ### FAQ49、argparse传递bool值的判断一直为Ture - 在 /usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe/config/ascend910 你去这个目录下的aic-ascend910-ops-info.json文件搜下这个NLLossGrad - 查看的结果如上发现类型不匹配导致 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3002.png) - -### FAQ31 dict加载的时候提示key缺少 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3101.png) - 因为ddp保存的权重会在key的前面加上moudule.所以需要简单处理下对齐下key, - 模型训练后保存的state_dict的key值与加载时state_dict的key值不一致,保存时会在每个key的最前面多一个module前缀。 - load进来都是dict,可以print看看 - 这里是提示的key缺失所以要加上 - pth.tar后缀的 - ```python -def proc_node_module(checkpoint, AttrName): - new_state_dict = OrderedDict() - for k, v in checkpoint[AttrName].items(): - if k[0:7] == "module.": - name = k[7:] - else: - name = k[0:] - new_state_dict[name] = v - return new_state_dict -checkpoint = torch.load("checkpoint.pth.tar", map_location='cpu') -checkpoint['state_dict'] = proc_node_module(checkpoint, 'state_dict') -model.load_state_dict(checkpoint['state_dict']) -``` -pth后缀的 ```python -def proc_nodes_module(checkpoint): - new_state_dict = OrderedDict() - for k,v in checkpoint.items(): - if(k[0:7] == "module."): - name = k[7:] - else: - name = k[0:] - new_state_dict[name]=v - return new_state_dict -pretrained_net = torch.load(pth_file, map_location='cpu') -pretrained_net['state_dict'] = proc_nodes_module(pretrained_net) -model.load_state_dict(pretrained_net['state_dict']) + parser.add_argument("--flag", + type=bool, + default=True) ``` -### FAQ32 pip3报错 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3201.png) - - 原因 没有pip3这个快捷方式 - -1.检查 +这里传入的值虽然申明成 bool 值,最后这个flag得到的数据是个字符串,所以最后得到的一定是 Ture -首先确定环境中是有python3.7.5的 - -确定自己的 pip3.7 存在的软连接位置 +解决办法1 直接说明 action ```bash -which pip3.7 #返回值应该是 /usr/bin/pip3.7 +parser.add_argument("--flag", + action="store_true", + help="Run or not.") ``` -2.创建软连接 - -```bash -ln -s /usr/bin/pip3.7 /usr/bin/pip3 -``` +解决办法2 python中对得到的字符串再判断,然后确定是Ture还是False + + ### FAQ50、 源码编译安装包的时候,报错 mpi.h 文件缺失 +解决办法 +![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_5001.png) +原因是你的环境上缺少 mpicc这个工具,这个东西做什么的我也不清楚,其作用大概类似辅助gcc编译 +安装这个环境就行 cent就使用yum就行 -### FAQ33 toolkit包安装报错 ```bash -The user and group are not same with last installation,do not support overwriting installation -``` - -原因 - -当前指定的驱动运行用户与“/etc/ascend_install.info”文件中记录的运行用户不一致,导致校验失败,安装退出。原因是之前卸载驱动和CANN软件时,aicpu没有被卸载,导致“/etc/ascend_install.info”文件未清空。 - -先卸载aicpu,再安装驱动。卸载aicpu操作如下: - -1. 以root用户登录安装环境。 - -2. 进入卸载脚本所在目录。 - - cd /usr/local/Ascend/opp/aicpu/script - -3. 执行**./uninstall.sh**命令运行脚本,完成卸载。 - -### FAQ34 driver安装crl报错 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3401.png) -原因目录 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3402.png) -原因老版本的安装信息 /ascend/ascend_check 存在,driver安装前校验无法通过 - -解决办法,删除这个文件 -### FAQ35 onnx安装问题, protobuf-compiler缺失 - -arm 安装 onnx 步骤 x86的直接安装就行 - -pip安装 - 更新一下pip 或者 pip3.7 安装 - arm在21版本的pip中可以下载并执行编译安装,但是可能提示编译缺少包 -获取源码安装 - git clone https://github.com/onnx/onnx.git - cd ./onnx - python3.7 setup.py build - python3.7 setup.py install - 但是可能会有问题 - ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3501.png) - -问题处理 : 缺失编译条件 - protobuf-compiler缺失 - -ubutu: - sudo apt-get install libprotobuf-dev protobuf-compiler -cent: - yum install libprotobuf-dev protobuf-compiler - 再次尝试安装试试,还是失败,就下一步 - -安装protobuf - wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz - tar xvf protobuf-2.6.1.tar.gz - cd protobuf-2.6.1 - ./configure - make -j 4 - make check - make install - 再次尝试安装下试试,否则继续下一步 - -安装 protoc - wget https://github.com/protobuf-c/protobuf-c/releases/download/v1.2.1/protobuf-c-1.2.1.tar.gz - tar xvf protobuf-c-1.2.1.tar.gz - cd protobuf-c-1.2.1 - export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig // 指定protobuf.pc文件所在 - ./configure - make -j 4 - make install - -还是失败的话,建议看下 环境基础依赖是否安装, -最后实在不行就放弃吧,换个操作系统。 - -### FAQ36 conda拷贝环境后发现pip使用不了报错如下: -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3601.png) -##### **问题原因:** - -conda现存的conda存在的bug,当你clone的环境是中的pip版本过高(21.0.1的版本就不行),那么继承的子环境会存在问题。 - -##### **解决办法** - -方法1 单独使用如下命令创建环境,然后apex包和torch包根据实际环境安装 - -conda create -n wangyuanming python=3.7.5 - -方法2 确定你拷贝的基础环境pip版本正确 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3602.png) - -### FAQ37 执行pip安装的时候缺少so的包 - -不一定是 openblas的包,也有可能是其他的包报错也是一样的 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3702.png) - **原因及解决办法** - -因为基础的依赖包没有安装 - -下面两种不同的环境需要安装的依赖有说不同 - -看下面的 FAQ38 - -### FAQ38 环境安装前需要基础依赖安装 -环境安装前需要基础依赖安装 -● CentOS/EulerOS/Tlinux/BClinux/Suse - -一般依赖需求 - -yum install -y libjpeg python-devel zlib-devel libjpeg-turbo-devel protobuf-compiler - -依赖+工具集 - -yum install -y gcc gcc-c++ make cmake unzip zlib-devel libffi-devel openssl-devel pciutils net-tools sqlite-devel lapack-devel openblas-devel gcc-gfortran dos2unix - -● Ubuntu/Debian/UOS - -一般依赖需求 - -apt-get install -y libjpeg python-devel zlib-devel libjpeg-turbo-devel - -依赖+工具集 - - apt-get install -y gcc g++ make cmake zlib1g zlib1g-dev openssl libsqlite3-dev libssl-dev libffi-dev unzip pciutils net-tools libblas-dev gfortran libblas3 libopenblas-dev libncursesw5-dev dos2unix - -### FAQ39 conda使用,外部的python环境指定的不是自己安装的版本 - -**问题现象** -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3901.png) -检查pip出处 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3902.png) -Python版本不对,执行位置也不对 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_3903.png) -原因和解决办法 -安装完的环境初始化操作被修改了,一般conda正常激活的时候前面应该有括号表示当前的conda环境 -所以这里想用外面的环境直接conda deactivate 为了一直有效直接添加到环境变量中。 - - -### FAQ40、Alexnet dropout 精度不达标规避方法。 -* 现象描述 - Alexnet dropout npu精度不达标 -* 处理方法 - - 我们采用规避dropout的方法,然后使模型精度达标。 - 源代码如下 - ``` - self.classifier = nn.Sequential( - nn.Dropout(), - nn.Linear(256 * 6 * 6, 4096), - nn.ReLU(inplace=True), - nn.Dropout(), - nn.Linear(4096, 4096), - nn.ReLU(inplace=True), - nn.Linear(4096, num_classes), - ) - ``` - 修改为如下: - ``` - class Dropout(nn.Module): - def __init__(self, p=0.5, inplace=False): - super(Dropout, self).__init__() - self.p = p - self.inplace = inplace - - def forward(self, x): - x = F.dropout(x.float().cpu(), self.p, self.training, self.inplace).npu().half() - return x - ....... - - self.avgpool = nn.AdaptiveAvgPool2d((6, 6)) - self.classifier = nn.Sequential( - Dropout(), - nn.Linear(256 * 6 * 6, 4096), - nn.ReLU(inplace=True), - Dropout(), - nn.Linear(4096, 4096), - nn.ReLU(inplace=True), - nn.Linear(4096, num_classes), - ) - ``` - -### FAQ41、mmdet在做hook定位时反向过程报错 -- 现象描述 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq41_0625_fig1.PNG) - -- 原因分析 - -这个是torch的原始BUG,如果是空dict就会死循环;因为mmdet自己会包装dict,所以这里一定要读到tensor,才会正常执行 -- 处理方法 -代码参考路径为:/usr/local/python3.7.5/lib/python3.7/site-packages/torch/nn/modules/module.py -适配代码参考如下: -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq41_0625_fig2.PNG) - - -### FAQ42、如何确定模型中是否有动态算子 -- 现象描述 -模型训练过程性能越来越低 - -- 原因分析 -可能存在动态算子 - -- 处理方法 - 通过这个命令可以看到算子是否一直在增长,如果一直在增长说明存在动态shape, 需要固定shape -``` -watch -n 1 "ls -ltr kernel_meta/ | wc -l" -``` - -### FAQ43、模型训练过程报ACL stream的错误 -- 现象描述 -没有提示算子报错,只是提示ACL stream的错误 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq43_0714.PNG) - -- 原因分析 -由于Pytorch是异步执行框架,直接print可能无法准确定位到错误的地方,需使用流通步接口辅助打点 - -- 处理方法 -print之前添加如下代码,一步步定位,如果point可以正常打印,说明前一行代码没问题;如果不能正常打印,则上一行应该是错误的地方,需要排查分析 -``` -stream = torch.npu.current_stream() -print(stream.synchronize(),"point") -``` - -### FAQ44、模型刚开始训练没有报错或日志信息,等待时间久 -- 现象描述 -模型刚开始训练时没有报错信息或日志信息,等待时间很久都没反应,不确定训练是否在正常运行 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq44_0714.PNG) - -- 原因分析 -刚开始训练过程,需要编译算子,这一步时间稍长 - -- 处理方法 -(1)可通过top指令查看是否有cpu使用率,如果有使用率,说明正在编译算子 -(2)通过ps -ef|grep python指令查看模型进程是否还在,还在的话说明程序正常运行中 -每个模型编译算子耗时时间都不一样,一般耗时会在几分钟内。 - -### FAQ45、模型训练过程DCNv2算子+混合精度报错:excepted scalar type float but found half -- 现象描述 -模型训练过程使用到DCNv2算子,混合精度配置为O2模式,训练过程报错 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq45_fig1_0719.PNG) - -- 原因分析 -DCNv2算子不支持混合精度O2模式 - -- 处理方法 -修改混合精度为O1模式,同时修改dcn_v2.py文件中DCNv2算子的前向传播和反向传播的入参类型为fp32。 -DCNv2安装版本以该链接为例:https://github.com/jinfagang/DCNv2_latest -对比源码,适配后的dcn_v2.py文件对比差异如下: -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq45_fig2_0719.PNG) - - ### FAQ46、模型训练过程中算子PadV3D报错:constant_values value mismatches - - 现象描述 - 模型训练反向过程中算子PadV3D报错 - ![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq46_fig1_0803.png) - - - 原因分析 - 找到源码报错位置,发现使用场景是先用F.pad()做same padding, 然后进行卷积计算 - - - 处理方法 - 手算pad参数,去掉F.pad()这一运算,将这个运算加到卷积里面,两者是等价的 - - ![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq46_fig2_0803.png) - -### FAQ47、模型训练过程中报错:Expected isFloatingType(grad[i].scalar_type())to be true but got false -- 现象描述 -屏幕报错信息如下所示: -![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq47_fig1_0812.jpg) -从中可以看到是反向报错,并且是aicpu算子报错,然后查看host侧日志,显示如下: -![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq47_fig2_0812.png) - -- 原因分析 -根据host侧日志信息可以看到是aicpu算子GatherElements报错,然后源码查找反向调用gather算子的位置,查看pytorch源码derivatives.yaml发现只有scatter_和scatter_add_算子反向会调用gather算子,排查模型源码forward没有调用scatter_和scatter_add_这两个算子,但是forward有调用gather,所以问题可能出现在模型正向gather算子报错。 -- 处理方法 -将模型中调用gather的算子全部to cpu计算,host侧日志问题复现如下: -![](https://gitee.com/xiaxia3/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq47_fig3_0812.png) - -然后利用模型中的数据构造gather单算子,问题复现,结论是gather算子的输入输非法的,然后npu的gather正常计算,进而在反向报错 - -### FAQ48、h5py安装方法 -``` -####################################### -安装h5py -####################################### -下载hdf5源码包 -wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.5/src/hdf5-1.10.5.tar.gz --no-check-certificate -解压 -tar -zxvf hdf5-1.10.5.tar.gz -进入目录,编译 -cd hdf5-1.10.5/ -./configure --prefix=/usr/include/hdf5 -make install - -配置环境变量 -export CPATH="/usr/include/hdf5/include/:/usr/include/hdf5/lib/" - -建立动态链接库软链接 -ln -s /usr/include/hdf5/lib/libhdf5.so /usr/lib/libhdf5.so -ln -s /usr/include/hdf5/lib/libhdf5_hl.so /usr/lib/libhdf5_hl.so - -安装h5py依赖包 -pip3.7 install pkgconfig Cython -安装h5py -pip3.7 install h5py - + apt-get install mpich ``` -## [2.2 NPU模型分布式运行常见问题FAQ](#22-NPU模型分布式运行常见问题FAQ) -### FAQ1、在模型分布式训练时,遇到报错 host not found. - -* 现象描述 - -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq11_1120.png) - -* 原因分析 - - 对模型进行分布式训练时,会调用集合通信模块HCCL,需要根据实际情况设置IP和端口信息。根据报错信息,确定是IP地址设置错误。 - -* 处理方法 - - 在运行脚本中设置正确的IP地址,对于单机情况,设置为本机的IP即可;对于多机情况,每个服务器上脚本中的IP需要设置为master节点的IP。 - -### FAQ2、在模型运行时,遇到eval模式下loss值特别大,过万. - -* 现象描述 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_0201.png) - - -* 原因分析 - - 通过打印输入、查看数据集,降低loss_scale等方式均没有效果,通过重装torch和apex解决,该问题应该是包的版本不匹配引起的 - -* 处理方法 - - 重装环境中的torch和apex,问题得到解决。 - -### FAQ3、在模型运行时,模型训练的精度和loss值多卡之间不同步. - - -* 现象描述 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_0301.png) +安装完后,可以在环境中找到 mpicc工具 +![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq1_5002.png) -* 原因分析 - - 只填加了train_sampler,没有添加set_epoch,导致不同步问题 - -* 处理方法 - - 在train epoch循环过程中,添加set_epoch,问题得到解决。 - -### FAQ4、在模型运行时,模型训练跑到中途中断. - - -* 现象描述 -![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_0401.png) +重新编译安装 + + ### FAQ51、 pip包安装避坑(持续更新) +pip包中有部分包存在致命问题,具体如下: -* 原因分析 +| 包名 | 建议安装版本 | 备注 | +| ------------ | ------------ | --------------------------------------------------------- | +| scikit-image | <=0.16.2 | 使用 0.17或者0.18 版本时,发现有 底层报段错误或是指针异常 | +| numpy | !=1.19.2 | 使用1.19.2会导入错误 | - 模型在训练时,跑到中途中断报错,经分析是linux环境本身的限制,需要修改默认的打开进程数目值 - -* 处理方法 - 通过ulimit -SHn 51200命令(可把该命令加入到env.sh文件中,方便跑模型时同步执行)修改打开进程数目值,该问题解决。 \ No newline at end of file + + + + + + + + + ## [2.2 NPU模型分布式运行常见问题FAQ](#22-NPU模型分布式运行常见问题FAQ) + + ### FAQ1、在模型分布式训练时,遇到报错 host not found. + + * 现象描述 + + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq11_1120.png) + + * 原因分析 + + 对模型进行分布式训练时,会调用集合通信模块HCCL,需要根据实际情况设置IP和端口信息。根据报错信息,确定是IP地址设置错误。 + + * 处理方法 + + 在运行脚本中设置正确的IP地址,对于单机情况,设置为本机的IP即可;对于多机情况,每个服务器上脚本中的IP需要设置为master节点的IP。 + + ### FAQ2、在模型运行时,遇到eval模式下loss值特别大,过万. + + * 现象描述 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_0201.png) + + + * 原因分析 + + 通过打印输入、查看数据集,降低loss_scale等方式均没有效果,通过重装torch和apex解决,该问题应该是包的版本不匹配引起的 + + * 处理方法 + + 重装环境中的torch和apex,问题得到解决。 + + ### FAQ3、在模型运行时,模型训练的精度和loss值多卡之间不同步. + + + * 现象描述 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_0301.png) + + + * 原因分析 + + 只填加了train_sampler,没有添加set_epoch,导致不同步问题 + + * 处理方法 + + 在train epoch循环过程中,添加set_epoch,问题得到解决。 + + ### FAQ4、在模型运行时,模型训练跑到中途中断. + + + * 现象描述 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_0401.png) + + + * 原因分析 + + 模型在训练时,跑到中途中断报错,经分析是linux环境本身的限制,需要修改默认的打开进程数目值 + + * 处理方法 + + 通过ulimit -SHn 51200命令(可把该命令加入到env.sh文件中,方便跑模型时同步执行)修改打开进程数目值,该问题解决。 + + ### FAQ5、npu跑多P的时候,跑了多个epoch后,报错AllReduce错误 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_0301.png) + + 解决办法: + + 关闭 TASK_QUEUE_ENABLE 的环境变量,虽然这样做跑的会慢点 + ![](https://gitee.com/wangjiangben_hw/ascend-pytorch-crowdintelligence-doc/raw/master/figures/model_faq2_0302.png) \ No newline at end of file